From 3bd1e295ea830c8811f3f9f901df0d41871e11dd Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 17 May 2022 19:27:01 +1000 Subject: [PATCH] #1047: Support setting individual Wither head targets By: Yannick Lamprecht --- .../craftbukkit/entity/CraftWither.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java index 9330e76e83..592c7a6022 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java @@ -1,10 +1,13 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.boss.wither.EntityWither; import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.boss.CraftBossBar; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Wither; public class CraftWither extends CraftMonster implements Wither { @@ -38,4 +41,24 @@ public class CraftWither extends CraftMonster implements Wither { public BossBar getBossBar() { return bossBar; } + + @Override + public void setTarget(Head head, LivingEntity livingEntity) { + Preconditions.checkArgument(head != null, "head cannot be null"); + + int entityId = (livingEntity != null) ? livingEntity.getEntityId() : 0; + getHandle().setAlternativeTarget(head.ordinal(), entityId); + } + + @Override + public LivingEntity getTarget(Head head) { + Preconditions.checkArgument(head != null, "head cannot be null"); + + int entityId = getHandle().getAlternativeTarget(head.ordinal()); + if (entityId == 0) { + return null; + } + Entity target = getHandle().getLevel().getEntity(entityId); + return (target != null) ? (LivingEntity) target.getBukkitEntity() : null; + } }