From aba54bccdbc5edc3824446035883959532666ac6 Mon Sep 17 00:00:00 2001 From: Yannick Lamprecht Date: Sun, 18 Jan 2026 01:10:59 +0100 Subject: [PATCH] feature(#13558): add copper golem state api --- .../java/org/bukkit/entity/CopperGolem.java | 47 +++++++++++++++++++ .../java/io/papermc/generator/Rewriters.java | 8 ++++ .../craftbukkit/entity/CraftCopperGolem.java | 14 ++++++ 3 files changed, 69 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/entity/CopperGolem.java b/paper-api/src/main/java/org/bukkit/entity/CopperGolem.java index 659733c3d116..b19d3c3d066c 100644 --- a/paper-api/src/main/java/org/bukkit/entity/CopperGolem.java +++ b/paper-api/src/main/java/org/bukkit/entity/CopperGolem.java @@ -25,6 +25,20 @@ public interface CopperGolem extends Golem, Shearable { */ void setWeatheringState(WeatheringCopperState state); + /** + * Get the current copper golem state of the copper golem. + * + * @return the copper golem state + */ + CopperGolem.State getState(); + + /** + * Set the copper golem state of the copper golem. + * + * @param state the new copper golem state + */ + void setState(CopperGolem.State state); + /** * Get the current oxidizing state of the copper golem. * @@ -125,4 +139,37 @@ sealed interface AtTime extends Oxidizing permits AtTimeImpl { @ApiStatus.Internal record AtTimeImpl(long time) implements AtTime {} } + + @NullMarked + enum State { + // Start generate - CopperGolemState + IDLE("idle"), + GETTING_ITEM("getting_item"), + GETTING_NO_ITEM("getting_no_item"), + DROPPING_ITEM("dropping_item"), + DROPPING_NO_ITEM("dropping_no_item"); + // End generate - CopperGolemState + + public static final net.kyori.adventure.util.Index NAMES = net.kyori.adventure.util.Index.create(State.class, State::getId); + + private final String id; + + State(String id) { + this.id = id; + } + + /** + * Get the string id of this display slot. + * + * @return the string id + */ + public String getId() { + return this.id; + } + + @Override + public String toString() { + return this.id; + } + } } diff --git a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java index 6a337d533bff..05f78bb3cff8 100644 --- a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java +++ b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java @@ -66,6 +66,7 @@ import org.bukkit.entity.Boat; import org.bukkit.entity.Cat; import org.bukkit.entity.Chicken; +import org.bukkit.entity.CopperGolem; import org.bukkit.entity.Cow; import org.bukkit.entity.EntityType; import org.bukkit.entity.Fox; @@ -142,6 +143,13 @@ protected EnumValue.Builder rewriteEnumValue(net.minecraft.world.entity.animal.p .register("SoundCategory", SoundCategory.class, new EnumCloneRewriter<>(SoundSource.class)) .register("AttributeSentiment", Attribute.Sentiment.class, new EnumCloneRewriter<>(net.minecraft.world.entity.ai.attributes.Attribute.Sentiment.class)) .register("WeatheringCopperState", WeatheringCopperState.class, new EnumCloneRewriter<>(WeatheringCopper.WeatherState.class)) + .register("CopperGolemState", CopperGolem.State.class, new EnumCloneRewriter<>(net.minecraft.world.entity.animal.golem.CopperGolemState.class) { + @Override + protected EnumValue.Builder rewriteEnumValue(net.minecraft.world.entity.animal.golem.CopperGolemState state) { + final String name = Formatting.formatKeyAsField(state.getSerializedName()); + return EnumValue.builder(name).argument(quoted(state.getSerializedName())); + } + }) .register(ClientOption.class, composite( holder("ChatVisibility", ClientOption.ChatVisibility.class, new EnumCloneRewriter<>(ChatVisiblity.class) { @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCopperGolem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCopperGolem.java index 36d838fe5abc..73752b78efcd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCopperGolem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCopperGolem.java @@ -3,6 +3,8 @@ import com.google.common.base.Preconditions; import io.papermc.paper.entity.PaperShearable; import io.papermc.paper.world.WeatheringCopperState; +import net.minecraft.util.StringRepresentable; +import net.minecraft.world.entity.animal.golem.CopperGolemState; import net.minecraft.world.level.block.WeatheringCopper; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.CopperGolem; @@ -30,6 +32,18 @@ public void setWeatheringState(final WeatheringCopperState state) { this.getHandle().setWeatherState(WeatheringCopper.WeatherState.valueOf(state.name())); } + @Override + public CopperGolem.State getState() { + return State.NAMES.valueOrThrow(this.getHandle().getState().getSerializedName()); + } + + @Override + public void setState(final CopperGolem.State state) { + Preconditions.checkArgument(state != null, "state cannot be null"); + net.minecraft.world.entity.animal.golem.CopperGolemState vanilla = ((StringRepresentable.EnumCodec)net.minecraft.world.entity.animal.golem.CopperGolemState.CODEC).byName(state.getId()); + this.getHandle().setState(vanilla); + } + @Override public Oxidizing getOxidizing() { long value = this.getHandle().nextWeatheringTick;