123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package me.km.events;
- import java.util.function.BiConsumer;
- import me.hammerle.snuviscript.code.Script;
- import me.km.KajetansMod;
- import me.km.api.Location;
- import me.km.snuviscript.ScriptEvents;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.world.World;
- public class PlayerMoveData
- {
- private final Script sc;
- private final BiConsumer<EntityPlayerMP, Object> c;
- private final int coolDown;
- private int ticks;
- private int livingTime;
-
- private Object data;
-
- private final World w;
- private final double minX;
- private final double minY;
- private final double minZ;
- private final double maxX;
- private final double maxY;
- private final double maxZ;
-
- private PlayerMoveData(Script sc, BiConsumer<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
- {
- this.sc = sc;
- this.c = c;
- this.coolDown = cooldown;
- this.ticks = cooldown;
- this.livingTime = livingTime;
- this.w = l1.getWorld();
- this.minX = Math.min(l1.getX(), l2.getX());
- this.minY = Math.min(l1.getY(), l2.getY());
- this.minZ = Math.min(l1.getZ(), l2.getZ());
- this.maxX = Math.max(l1.getX(), l2.getX());
- this.maxY = Math.max(l1.getY(), l2.getY());
- this.maxZ = Math.max(l1.getZ(), l2.getZ());
- this.data = data;
-
- System.out.println("X DATA FROM " + minX +" TO " + maxX);
- System.out.println("Y DATA FROM " + minY +" TO " + maxY);
- System.out.println("Z DATA FROM " + minZ +" TO " + maxZ);
- }
-
- public PlayerMoveData(Script sc, Location l1, Location l2, int cooldown, int livingTime)
- {
- this(sc, null, l1, l2, cooldown, livingTime, null);
- }
-
- public PlayerMoveData(BiConsumer<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
- {
- this(null, c, l1, l2, cooldown, livingTime, data);
- }
-
- public Object getData()
- {
- return data;
- }
-
- public boolean tickLiving()
- {
- if(livingTime == -1)
- {
- return false;
- }
- livingTime--;
- return livingTime < 0;
- }
-
- public boolean tick()
- {
- ticks--;
- if(ticks > 0)
- {
- return true;
- }
- ticks = coolDown;
- return false;
- }
-
- public boolean check(EntityPlayerMP p)
- {
- if(p.world != w || p.posX < minX || p.posX > maxX || p.posZ < minZ || p.posZ > maxZ || p.posY < minY || p.posY > maxY)
- {
- return false;
- }
- if(sc != null)
- {
- KajetansMod.scripts.getEvent(ScriptEvents.class).onPlayerMove(p);
- }
- if(c != null)
- {
- c.accept(p, data);
- }
- return coolDown == -1;
- }
- }
|