Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/CopperGolem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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<String, State> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
})
Comment on lines +147 to +152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part supposed to be exposed or is it only used for the conversion? can just do a.valueOf(b.name()) once it's generated. The javadocs of getId is at least a bit weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for conversion. Referenced other enums that have an identifier on both sides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer this. It allows to do legacy support easily.

.register(ClientOption.class, composite(
holder("ChatVisibility", ClientOption.ChatVisibility.class, new EnumCloneRewriter<>(ChatVisiblity.class) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CopperGolemState>)net.minecraft.world.entity.animal.golem.CopperGolemState.CODEC).byName(state.getId());
this.getHandle().setState(vanilla);
}

@Override
public Oxidizing getOxidizing() {
long value = this.getHandle().nextWeatheringTick;
Expand Down
Loading