PlayerMoveData.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package me.km.events;
  2. import java.util.function.BiConsumer;
  3. import me.hammerle.snuviscript.code.Script;
  4. import me.km.KajetansMod;
  5. import me.km.api.Location;
  6. import me.km.snuviscript.ScriptEvents;
  7. import net.minecraft.entity.player.EntityPlayerMP;
  8. import net.minecraft.world.World;
  9. public class PlayerMoveData
  10. {
  11. private final Script sc;
  12. private final BiConsumer<EntityPlayerMP, Object> c;
  13. private final int coolDown;
  14. private int ticks;
  15. private int livingTime;
  16. private Object data;
  17. private final World w;
  18. private final double minX;
  19. private final double minY;
  20. private final double minZ;
  21. private final double maxX;
  22. private final double maxY;
  23. private final double maxZ;
  24. private PlayerMoveData(Script sc, BiConsumer<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
  25. {
  26. this.sc = sc;
  27. this.c = c;
  28. this.coolDown = cooldown;
  29. this.ticks = cooldown;
  30. this.livingTime = livingTime;
  31. this.w = l1.getWorld();
  32. this.minX = Math.min(l1.getX(), l2.getX());
  33. this.minY = Math.min(l1.getY(), l2.getY());
  34. this.minZ = Math.min(l1.getZ(), l2.getZ());
  35. this.maxX = Math.max(l1.getX(), l2.getX());
  36. this.maxY = Math.max(l1.getY(), l2.getY());
  37. this.maxZ = Math.max(l1.getZ(), l2.getZ());
  38. this.data = data;
  39. System.out.println("X DATA FROM " + minX +" TO " + maxX);
  40. System.out.println("Y DATA FROM " + minY +" TO " + maxY);
  41. System.out.println("Z DATA FROM " + minZ +" TO " + maxZ);
  42. }
  43. public PlayerMoveData(Script sc, Location l1, Location l2, int cooldown, int livingTime)
  44. {
  45. this(sc, null, l1, l2, cooldown, livingTime, null);
  46. }
  47. public PlayerMoveData(BiConsumer<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
  48. {
  49. this(null, c, l1, l2, cooldown, livingTime, data);
  50. }
  51. public Object getData()
  52. {
  53. return data;
  54. }
  55. public boolean tickLiving()
  56. {
  57. if(livingTime == -1)
  58. {
  59. return false;
  60. }
  61. livingTime--;
  62. return livingTime < 0;
  63. }
  64. public boolean tick()
  65. {
  66. ticks--;
  67. if(ticks > 0)
  68. {
  69. return true;
  70. }
  71. ticks = coolDown;
  72. return false;
  73. }
  74. public boolean check(EntityPlayerMP p)
  75. {
  76. if(p.world != w || p.posX < minX || p.posX > maxX || p.posZ < minZ || p.posZ > maxZ || p.posY < minY || p.posY > maxY)
  77. {
  78. return false;
  79. }
  80. if(sc != null)
  81. {
  82. KajetansMod.scripts.getEvent(ScriptEvents.class).onPlayerMove(p);
  83. }
  84. if(c != null)
  85. {
  86. c.accept(p, data);
  87. }
  88. return coolDown == -1;
  89. }
  90. }