From 038135733b7ad38895b3fbd69f503974d911e6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Tue, 25 Sep 2018 15:26:10 +0800 Subject: [PATCH] =?UTF-8?q?v4.32=20+=20PathfinderExecutor=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=20controllerLookAt(LivingEntity=20entity,=20Entity=20?= =?UTF-8?q?target)=20=E6=96=B9=E6=B3=95=E6=97=A0=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=E5=B7=B2=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20+=20PathfinderExecutor=20=E5=B7=A5=E5=85=B7=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=9B=9B=E4=B8=AA=E5=85=B3=E4=BA=8E=E5=AF=BB=E8=B7=AF?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=9A=20=20=20+=20setPathEntity(?= =?UTF-8?q?LivingEntity=20entity,=20Object=20pathEntity)=20=20=20+=20navig?= =?UTF-8?q?ationMove(LivingEntity=20entity,=20LivingEntity=20target,=20dou?= =?UTF-8?q?ble=20speed)=20=20=20+=20navigationMove(LivingEntity=20entity,?= =?UTF-8?q?=20LivingEntity=20target)=20=20=20+=20setFollowRange(LivingEnti?= =?UTF-8?q?ty=20entity,=20double=20value)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/pathfinder/PathfinderExecutor.java | 12 ++++- .../internal/InternalPathfinderExecutor.java | 49 ++++++++++++++----- .../taboolib/common/util/SimpleCounter.java | 24 +++++++++ 3 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 src/main/java/me/skymc/taboolib/common/util/SimpleCounter.java diff --git a/src/main/java/me/skymc/taboolib/common/pathfinder/PathfinderExecutor.java b/src/main/java/me/skymc/taboolib/common/pathfinder/PathfinderExecutor.java index 2d5dd50..d726120 100644 --- a/src/main/java/me/skymc/taboolib/common/pathfinder/PathfinderExecutor.java +++ b/src/main/java/me/skymc/taboolib/common/pathfinder/PathfinderExecutor.java @@ -14,8 +14,6 @@ public abstract class PathfinderExecutor { public abstract Object getNavigation(LivingEntity entity); - public abstract Object getPathEntity(LivingEntity entity); - public abstract Object getControllerJump(LivingEntity entity); public abstract Object getControllerMove(LivingEntity entity); @@ -26,6 +24,10 @@ public abstract class PathfinderExecutor { public abstract Object getTargetSelector(LivingEntity entity); + public abstract Object getPathEntity(LivingEntity entity); + + public abstract void setPathEntity(LivingEntity entity, Object pathEntity); + public abstract void setGoalAi(LivingEntity entity, SimpleAi ai, int priority); public abstract void setTargetAi(LivingEntity entity, SimpleAi ai, int priority); @@ -38,6 +40,10 @@ public abstract class PathfinderExecutor { public abstract boolean navigationMove(LivingEntity entity, Location location, double speed); + public abstract boolean navigationMove(LivingEntity entity, LivingEntity target); + + public abstract boolean navigationMove(LivingEntity entity, LivingEntity target, double speed); + public abstract boolean navigationReach(LivingEntity entity); public abstract void controllerLookAt(LivingEntity entity, Location target); @@ -47,4 +53,6 @@ public abstract class PathfinderExecutor { public abstract void controllerJumpReady(LivingEntity entity); public abstract boolean controllerJumpCurrent(LivingEntity entity); + + public abstract void setFollowRange(LivingEntity entity, double value); } diff --git a/src/main/java/me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor.java b/src/main/java/me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor.java index e24df74..68330f9 100644 --- a/src/main/java/me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor.java +++ b/src/main/java/me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor.java @@ -8,6 +8,7 @@ import net.minecraft.server.v1_8_R3.*; import org.bukkit.Location; import org.bukkit.attribute.Attribute; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -59,16 +60,6 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { return ((EntityInsentient) getEntityInsentient(entity)).getNavigation(); } - @Override - public Object getPathEntity(LivingEntity entity) { - try { - return pathEntity.get(getNavigation(entity)); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - @Override public Object getControllerJump(LivingEntity entity) { return ((EntityInsentient) getEntityInsentient(entity)).getControllerJump(); @@ -94,6 +85,25 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { return ((EntityInsentient) getEntityInsentient(entity)).targetSelector; } + @Override + public Object getPathEntity(LivingEntity entity) { + try { + return pathEntity.get(getNavigation(entity)); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void setPathEntity(LivingEntity entity, Object pathEntity) { + try { + this.pathEntity.set(getNavigation(entity), pathEntity); + } catch (Exception e) { + e.printStackTrace(); + } + } + @Override public void setGoalAi(LivingEntity entity, SimpleAi ai, int priority) { ((EntityInsentient) getEntityInsentient(entity)).goalSelector.a(priority, (PathfinderGoal) SimpleAiSelector.getCreator().createPathfinderGoal(ai)); @@ -124,7 +134,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { @Override public boolean navigationMove(LivingEntity entity, Location location) { - return navigationMove(entity, location, entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue()); + return navigationMove(entity, location, 0.6); } @Override @@ -132,6 +142,16 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { return ((Navigation) getNavigation(entity)).a(location.getX(), location.getY(), location.getZ(), speed); } + @Override + public boolean navigationMove(LivingEntity entity, LivingEntity target) { + return navigationMove(entity, target, 0.6); + } + + @Override + public boolean navigationMove(LivingEntity entity, LivingEntity target, double speed) { + return ((Navigation) getNavigation(entity)).a(((CraftEntity) target).getHandle(), speed); + } + @Override public boolean navigationReach(LivingEntity entity) { Object pathEntity = getPathEntity(entity); @@ -145,7 +165,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { @Override public void controllerLookAt(LivingEntity entity, Entity target) { - ((ControllerLook) getControllerLook(entity)).a((net.minecraft.server.v1_8_R3.Entity) target, 10, 40); + ((ControllerLook) getControllerLook(entity)).a(((CraftEntity) target).getHandle(), 10, 40); } @Override @@ -161,4 +181,9 @@ public class InternalPathfinderExecutor extends PathfinderExecutor { return false; } } + + @Override + public void setFollowRange(LivingEntity entity, double value) { + ((EntityInsentient) getEntityInsentient(entity)).getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(value); + } } diff --git a/src/main/java/me/skymc/taboolib/common/util/SimpleCounter.java b/src/main/java/me/skymc/taboolib/common/util/SimpleCounter.java new file mode 100644 index 0000000..96dd083 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/common/util/SimpleCounter.java @@ -0,0 +1,24 @@ +package me.skymc.taboolib.common.util; + +/** + * @Author sky + * @Since 2018-09-25 15:21 + */ +public class SimpleCounter { + + private int timer; + private int limit; + + public SimpleCounter(int limit) { + this.timer = 0; + this.limit = limit; + } + + public boolean next() { + if (--timer <= 0) { + timer = limit; + return true; + } + return false; + } +}