From ed0354be301cae61dc38c3c1266db36c4a335ce5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 21 Apr 2022 06:45:42 +1000 Subject: [PATCH] SPIGOT-6992: Add LimitedLife/LifeTicks/Bound APIs to Vex By: Doc --- .../world/entity/monster/EntityVex.patch | 11 ++++++ .../bukkit/craftbukkit/entity/CraftVex.java | 37 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch index 573f6745c4..26e7736cd2 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch @@ -1,5 +1,16 @@ --- a/net/minecraft/world/entity/monster/EntityVex.java +++ b/net/minecraft/world/entity/monster/EntityVex.java +@@ -49,8 +49,8 @@ + EntityInsentient owner; + @Nullable + private BlockPosition boundOrigin; +- private boolean hasLimitedLife; +- private int limitedLifeTicks; ++ public boolean hasLimitedLife; // CraftBukkit - PAIL, private -> public ++ public int limitedLifeTicks; // CraftBukkit - PAIL, private -> public + + public EntityVex(EntityTypes entitytypes, World world) { + super(entitytypes, world); @@ -368,7 +368,7 @@ @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVex.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVex.java index d6e8217e2d..2c21b041d5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVex.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVex.java @@ -1,6 +1,9 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; +import net.minecraft.core.BlockPosition; import net.minecraft.world.entity.monster.EntityVex; +import org.bukkit.Location; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; import org.bukkit.entity.Vex; @@ -35,4 +38,38 @@ public class CraftVex extends CraftMonster implements Vex { public void setCharging(boolean charging) { getHandle().setIsCharging(charging); } + + @Override + public Location getBound() { + BlockPosition blockPosition = getHandle().getBoundOrigin(); + return (blockPosition == null) ? null : new Location(getWorld(), blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); + } + + @Override + public void setBound(Location location) { + if (location == null) { + getHandle().setBoundOrigin(null); + } else { + Preconditions.checkArgument(getWorld().equals(location.getWorld()), "The bound world cannot be different to the entity's world."); + getHandle().setBoundOrigin(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + } + } + + @Override + public int getLifeTicks() { + return getHandle().limitedLifeTicks; + } + + @Override + public void setLifeTicks(int lifeTicks) { + getHandle().setLimitedLife(lifeTicks); + if (lifeTicks < 0) { + getHandle().hasLimitedLife = false; + } + } + + @Override + public boolean hasLimitedLife() { + return getHandle().hasLimitedLife; + } }