From df5cb9bc3a7f758572ebb5673dacbe080afca7a1 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 2 Apr 2023 13:49:05 +1000 Subject: [PATCH] #1144: Add more Guardian API, particularly for its laser By: Parker Hawke --- .../world/entity/monster/EntityGuardian.patch | 19 ++++++++++++ .../craftbukkit/entity/CraftGuardian.java | 29 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch new file mode 100644 index 0000000000..d448ed9dc6 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch @@ -0,0 +1,19 @@ +--- a/net/minecraft/world/entity/monster/EntityGuardian.java ++++ b/net/minecraft/world/entity/monster/EntityGuardian.java +@@ -62,6 +62,7 @@ + private boolean clientSideTouchedGround; + @Nullable + public PathfinderGoalRandomStroll randomStrollGoal; ++ public EntityGuardian.PathfinderGoalGuardianAttack guardianAttackGoal; // CraftBukkit - add field + + public EntityGuardian(EntityTypes entitytypes, World world) { + super(entitytypes, world); +@@ -77,7 +78,7 @@ + PathfinderGoalMoveTowardsRestriction pathfindergoalmovetowardsrestriction = new PathfinderGoalMoveTowardsRestriction(this, 1.0D); + + this.randomStrollGoal = new PathfinderGoalRandomStroll(this, 1.0D, 80); +- this.goalSelector.addGoal(4, new EntityGuardian.PathfinderGoalGuardianAttack(this)); ++ this.goalSelector.addGoal(4, guardianAttackGoal = new EntityGuardian.PathfinderGoalGuardianAttack(this)); // CraftBukkit - assign field + this.goalSelector.addGoal(5, pathfindergoalmovetowardsrestriction); + this.goalSelector.addGoal(7, this.randomStrollGoal); + this.goalSelector.addGoal(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F)); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java index be95190b75..00ee47d7cb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftGuardian.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; import net.minecraft.world.entity.monster.EntityGuardian; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; @@ -8,6 +9,8 @@ import org.bukkit.entity.LivingEntity; public class CraftGuardian extends CraftMonster implements Guardian { + private static final int MINIMUM_ATTACK_TICKS = -10; + public CraftGuardian(CraftServer server, EntityGuardian entity) { super(server, entity); } @@ -58,6 +61,27 @@ public class CraftGuardian extends CraftMonster implements Guardian { return getHandle().hasActiveAttackTarget(); } + @Override + public int getLaserDuration() { + return getHandle().getAttackDuration(); + } + + @Override + public void setLaserTicks(int ticks) { + Preconditions.checkArgument(ticks >= MINIMUM_ATTACK_TICKS, "ticks must be >= %s. Given %s", MINIMUM_ATTACK_TICKS, ticks); + + EntityGuardian.PathfinderGoalGuardianAttack goal = getHandle().guardianAttackGoal; + if (goal != null) { + goal.attackTime = ticks; + } + } + + @Override + public int getLaserTicks() { + EntityGuardian.PathfinderGoalGuardianAttack goal = getHandle().guardianAttackGoal; + return (goal != null) ? goal.attackTime : MINIMUM_ATTACK_TICKS; + } + @Override public boolean isElder() { return false; @@ -67,4 +91,9 @@ public class CraftGuardian extends CraftMonster implements Guardian { public void setElder(boolean shouldBeElder) { throw new UnsupportedOperationException("Not supported."); } + + @Override + public boolean isMoving() { + return getHandle().isMoving(); + } }