CrumblingStoneTile.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package me.hammerle.supersnuvi.tiles;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.entity.EntityBuilder;
  4. import me.hammerle.supersnuvi.util.BlockDataStorage;
  5. import me.hammerle.supersnuvi.util.Face;
  6. import me.hammerle.supersnuvi.util.SoundUtils;
  7. import me.hammerle.supersnuvi.util.Utils;
  8. import me.hammerle.supersnuvi.gamelogic.Level;
  9. public class CrumblingStoneTile extends BaseMoveCollisionTile
  10. {
  11. private final BlockDataStorage states = new BlockDataStorage();
  12. public CrumblingStoneTile()
  13. {
  14. super(0.1875f, 0.125f, 0.25f, 0.1875f, 0.0f, 0.0f, Tile.SIZE, Tile.SIZE * 0.6f);
  15. }
  16. @Override
  17. public boolean isColliding(float minX, float minY, float maxX, float maxY, int x, int y, Level l)
  18. {
  19. return !states.contains(x, y, l) && super.isColliding(minX, minY, maxX, maxY, x, y, l);
  20. }
  21. @Override
  22. public boolean isMoveColliding(float minX, float minY, float maxX, float maxY, int x, int y, Level l)
  23. {
  24. return !states.contains(x, y, l) && super.isMoveColliding(minX, minY, maxX, maxY, x, y, l);
  25. }
  26. @Override
  27. public void onEntityCollide(Entity ent, int x, int y, Face face, Level l)
  28. {
  29. if(face == Face.UP && !ent.getMovement().canMoveOnTiles() && states.add(x, y, l))
  30. {
  31. l.getTileUpdater().add(l.getData().getBackgroundIndex(), x, y);
  32. l.spawnEntity(EntityBuilder.buildCrumblingStone(l, Utils.toCoord(x), Utils.toCoord(y)));
  33. SoundUtils.playSound(SoundUtils.Sound.STONE_CRUMBLING);
  34. }
  35. }
  36. @Override
  37. public boolean shouldRender(int x, int y, Level l)
  38. {
  39. return !states.contains(x, y, l);
  40. }
  41. @Override
  42. public void reset(Level l)
  43. {
  44. states.clear(l);
  45. }
  46. @Override
  47. public void reset(int x, int y, Level l)
  48. {
  49. states.clear(x, y, l);
  50. }
  51. }