Skip to content

Commit 695a7c2

Browse files
feature(#13558): add copper golem state api
1 parent 81b9122 commit 695a7c2

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

paper-api/src/main/java/org/bukkit/entity/CopperGolem.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ public interface CopperGolem extends Golem, Shearable {
2525
*/
2626
void setWeatheringState(WeatheringCopperState state);
2727

28+
/**
29+
* Get the current copper golem state of the copper golem.
30+
*
31+
* @return the copper golem state
32+
*/
33+
CopperGolem.State getState();
34+
35+
/**
36+
* Set the copper golem state of the copper golem.
37+
*
38+
* @param state the new copper golem state
39+
*/
40+
void setState(CopperGolem.State state);
41+
2842
/**
2943
* Get the current oxidizing state of the copper golem.
3044
*
@@ -125,4 +139,37 @@ sealed interface AtTime extends Oxidizing permits AtTimeImpl {
125139
@ApiStatus.Internal
126140
record AtTimeImpl(long time) implements AtTime {}
127141
}
142+
143+
@NullMarked
144+
enum State {
145+
// Start generate - CopperGolemState
146+
IDLE("idle"),
147+
GETTING_ITEM("getting_item"),
148+
GETTING_NO_ITEM("getting_no_item"),
149+
DROPPING_ITEM("dropping_item"),
150+
DROPPING_NO_ITEM("dropping_no_item");
151+
// End generate - CopperGolemState
152+
153+
public static final net.kyori.adventure.util.Index<String, State> NAMES = net.kyori.adventure.util.Index.create(State.class, State::getId);
154+
155+
private final String id;
156+
157+
State(String id) {
158+
this.id = id;
159+
}
160+
161+
/**
162+
* Get the string id of this display slot.
163+
*
164+
* @return the string id
165+
*/
166+
public String getId() {
167+
return this.id;
168+
}
169+
170+
@Override
171+
public String toString() {
172+
return this.id;
173+
}
174+
}
128175
}

paper-generator/src/main/java/io/papermc/generator/Rewriters.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.bukkit.entity.Boat;
6767
import org.bukkit.entity.Cat;
6868
import org.bukkit.entity.Chicken;
69+
import org.bukkit.entity.CopperGolem;
6970
import org.bukkit.entity.Cow;
7071
import org.bukkit.entity.EntityType;
7172
import org.bukkit.entity.Fox;
@@ -142,6 +143,13 @@ protected EnumValue.Builder rewriteEnumValue(net.minecraft.world.entity.animal.p
142143
.register("SoundCategory", SoundCategory.class, new EnumCloneRewriter<>(SoundSource.class))
143144
.register("AttributeSentiment", Attribute.Sentiment.class, new EnumCloneRewriter<>(net.minecraft.world.entity.ai.attributes.Attribute.Sentiment.class))
144145
.register("WeatheringCopperState", WeatheringCopperState.class, new EnumCloneRewriter<>(WeatheringCopper.WeatherState.class))
146+
.register("CopperGolemState", CopperGolem.State.class, new EnumCloneRewriter<>(net.minecraft.world.entity.animal.golem.CopperGolemState.class) {
147+
@Override
148+
protected EnumValue.Builder rewriteEnumValue(net.minecraft.world.entity.animal.golem.CopperGolemState state) {
149+
final String name = Formatting.formatKeyAsField(state.getSerializedName());
150+
return EnumValue.builder(name).argument(quoted(state.getSerializedName()));
151+
}
152+
})
145153
.register(ClientOption.class, composite(
146154
holder("ChatVisibility", ClientOption.ChatVisibility.class, new EnumCloneRewriter<>(ChatVisiblity.class) {
147155
@Override
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/net/minecraft/world/entity/animal/golem/CopperGolemState.java
2+
+++ b/net/minecraft/world/entity/animal/golem/CopperGolemState.java
3+
@@ -15,7 +_,7 @@
4+
DROPPING_ITEM("dropping_item", 3),
5+
DROPPING_NO_ITEM("dropping_no_item", 4);
6+
7+
- public static final Codec<CopperGolemState> CODEC = StringRepresentable.fromEnum(CopperGolemState::values);
8+
+ public static final StringRepresentable.EnumCodec<CopperGolemState> CODEC = StringRepresentable.fromEnum(CopperGolemState::values); // Paper - support copper golem state api mapping byName
9+
private static final IntFunction<CopperGolemState> BY_ID = ByIdMap.continuous(CopperGolemState::id, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
10+
public static final StreamCodec<ByteBuf, CopperGolemState> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, CopperGolemState::id);
11+
private final String name;

paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCopperGolem.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.base.Preconditions;
44
import io.papermc.paper.entity.PaperShearable;
55
import io.papermc.paper.world.WeatheringCopperState;
6+
import net.minecraft.util.StringRepresentable;
7+
import net.minecraft.world.entity.animal.golem.CopperGolemState;
68
import net.minecraft.world.level.block.WeatheringCopper;
79
import org.bukkit.craftbukkit.CraftServer;
810
import org.bukkit.entity.CopperGolem;
@@ -30,6 +32,18 @@ public void setWeatheringState(final WeatheringCopperState state) {
3032
this.getHandle().setWeatherState(WeatheringCopper.WeatherState.valueOf(state.name()));
3133
}
3234

35+
@Override
36+
public CopperGolem.State getState() {
37+
return State.NAMES.valueOrThrow(this.getHandle().getState().getSerializedName());
38+
}
39+
40+
@Override
41+
public void setState(final CopperGolem.State state) {
42+
Preconditions.checkArgument(state != null, "state cannot be null");
43+
net.minecraft.world.entity.animal.golem.CopperGolemState vanilla = ((StringRepresentable.EnumCodec<CopperGolemState>)net.minecraft.world.entity.animal.golem.CopperGolemState.CODEC).byName(state.getId());
44+
this.getHandle().setState(vanilla);
45+
}
46+
3347
@Override
3448
public Oxidizing getOxidizing() {
3549
long value = this.getHandle().nextWeatheringTick;

0 commit comments

Comments
 (0)