Skip to content

Commit 8d216ec

Browse files
committed
Add CopperGolemWeatheringEvent
1 parent 9d427a5 commit 8d216ec

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package io.papermc.paper.event.entity;
2+
3+
import io.papermc.paper.world.WeatheringCopperState;
4+
import org.bukkit.entity.CopperGolem;
5+
import org.bukkit.event.Cancellable;
6+
import org.bukkit.event.HandlerList;
7+
import org.bukkit.event.entity.EntityEvent;
8+
import org.jetbrains.annotations.ApiStatus;
9+
import org.jspecify.annotations.NullMarked;
10+
11+
/**
12+
* Called when a {@link CopperGolem} transitions from one {@link WeatheringCopperState} to another.
13+
*/
14+
@NullMarked
15+
public class CopperGolemWeatheringEvent extends EntityEvent implements Cancellable {
16+
17+
private static final HandlerList HANDLER_LIST = new HandlerList();
18+
19+
private final WeatheringCopperState weatherState;
20+
private final WeatheringCopperState nextWeatherState;
21+
22+
private boolean cancelled;
23+
24+
@ApiStatus.Internal
25+
public CopperGolemWeatheringEvent(final CopperGolem golem, final WeatheringCopperState weatherState, final WeatheringCopperState nextWeatherState) {
26+
super(golem);
27+
this.weatherState = weatherState;
28+
this.nextWeatherState = nextWeatherState;
29+
}
30+
31+
/**
32+
* Gets the copper golem entity that is about to weather.
33+
*
34+
* @return The copper golem entity about to weather.
35+
*/
36+
@Override
37+
public CopperGolem getEntity() {
38+
return (CopperGolem) super.getEntity();
39+
}
40+
41+
/**
42+
* Gets the current weathering state of the copper golem.
43+
*
44+
* @return The current weathering state.
45+
*/
46+
public WeatheringCopperState getWeatheringState() {
47+
return weatherState;
48+
}
49+
50+
/**
51+
* Gets the next weathering state the copper golem will transition to.
52+
*
53+
* @return The next weathering state.
54+
*/
55+
public WeatheringCopperState getNextWeatheringState() {
56+
return nextWeatherState;
57+
}
58+
59+
@Override
60+
public boolean isCancelled() {
61+
return cancelled;
62+
}
63+
64+
@Override
65+
public void setCancelled(final boolean cancel) {
66+
this.cancelled = cancel;
67+
}
68+
69+
@Override
70+
public HandlerList getHandlers() {
71+
return HANDLER_LIST;
72+
}
73+
74+
public static HandlerList getHandlerList() {
75+
return HANDLER_LIST;
76+
}
77+
}

paper-server/patches/sources/net/minecraft/world/entity/animal/coppergolem/CopperGolem.java.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@
3737
this.gameEvent(GameEvent.SHEAR, player);
3838
itemInHand.hurtAndBreak(1, player, hand);
3939
}
40+
@@ -267,9 +_,18 @@
41+
boolean flag = weatherState.equals(WeatheringCopper.WeatherState.OXIDIZED);
42+
if (gameTime >= this.nextWeatheringTick && !flag) {
43+
WeatheringCopper.WeatherState weatherState1 = weatherState.next();
44+
+ // Paper start - CopperGolemWeatheringEvent
45+
+ io.papermc.paper.event.entity.CopperGolemWeatheringEvent event = new io.papermc.paper.event.entity.CopperGolemWeatheringEvent(
46+
+ (org.bukkit.entity.CopperGolem) this.getBukkitEntity(),
47+
+ io.papermc.paper.world.WeatheringCopperState.valueOf(weatherState.name()),
48+
+ io.papermc.paper.world.WeatheringCopperState.valueOf(weatherState1.name())
49+
+ );
50+
+ event.callEvent();
51+
+ // Paper end - CopperGolemWeatheringEvent
52+
boolean flag1 = weatherState1.equals(WeatheringCopper.WeatherState.OXIDIZED);
53+
- this.setWeatherState(weatherState1);
54+
+ if (!event.isCancelled()) this.setWeatherState(weatherState1); // Paper - CopperGolemWeatheringEvent
55+
this.nextWeatheringTick = flag1 ? 0L : this.nextWeatheringTick + random.nextIntBetweenInclusive(504000, 552000);
56+
+ if (event.isCancelled()) return; // Paper - CopperGolemWeatheringEvent
57+
}
58+
59+
if (flag && this.canTurnToStatue(level)) {
4060
@@ -285,20 +_,27 @@
4161

4262
private void turnToStatue(ServerLevel level) {

0 commit comments

Comments
 (0)