CopperGolem .java

net.minecraft.world.entity.animal.golem.CopperGolem (class, 470 lines): members: getInteractionDropNoItemAnimationState, interactionDropItemAnimationState.

net.minecraft.world.entity.animal.golemclass470 linescommonextends AbstractGolem17.7 KB

Implements

API Surface (33)

AttributeSupplier.Builder createAttributes()
CopperGolemState getState()
void setState(final CopperGolemState state)
WeatheringCopper.WeatherState getWeatherState()
void setWeatherState(final WeatheringCopper.WeatherState state)
void setOpenedChestPos(final BlockPos openedChestPos)
void clearOpenedChestPos()
AnimationState getIdleAnimationState()
AnimationState getInteractionGetItemAnimationState()
AnimationState getInteractionGetNoItemAnimationState()
AnimationState getInteractionDropItemAnimationState()
AnimationState getInteractionDropNoItemAnimationState()
Brain<CopperGolem> makeBrain(final Brain.Packed packedBrain)
Brain<CopperGolem> getBrain()
void defineSynchedData(final SynchedEntityData.Builder entityData)
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
void customServerAiStep(final ServerLevel level)
void tick()
InteractionResult mobInteract(final Player player, final InteractionHand hand)
void spawn(final WeatheringCopper.WeatherState weatherState)
void playSpawnSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
void playStepSound(final BlockPos pos, final BlockState blockState)
Vec3 getLeashOffset()
boolean hasContainerOpen(final ContainerOpenersCounter container, final BlockPos blockPos)
double getContainerInteractionRange()
void shear(final ServerLevel level, final SoundSource soundSource, final ItemStack tool)
boolean readyForShearing()
void dropEquipment(final ServerLevel level)
void actuallyHurt(final ServerLevel level, final DamageSource source, final float dmg)
void thunderHit(final ServerLevel level, final LightningBolt lightningBolt)

Fields & Constants (24)

IGNORE_WEATHERING_TICK
UNSET_WEATHERING_TICK
WEATHERING_TICK_FROM
WEATHERING_TICK_TO
SPIN_ANIMATION_MIN_COOLDOWN
SPIN_ANIMATION_MAX_COOLDOWN
SPIN_SOUND_TIME_INTERVAL_OFFSET
TURN_TO_STATUE_CHANCE
SPAWN_COOLDOWN_MIN
SPAWN_COOLDOWN_MAX
BRAIN_PROVIDER
DATA_WEATHER_STATE
COPPER_GOLEM_STATE
EQUIPMENT_SLOT_ANTENNA
openedChestPos
lastLightningBoltUUID
nextWeatheringTick
idleAnimationStartTick
idleAnimationState
interactionGetItemAnimationState
interactionGetNoItemAnimationState
interactionDropItemAnimationState
interactionDropNoItemAnimationState
spawnReason

String literals (4)

"next_weather_age"
"weather_state"
"copperGolemBrain"
"copperGolemActivityUpdate"

Code Graph: Dependencies (55)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CopperGolem.java470 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.golem;
2
3
import java.util.List;
4
import java.util.UUID;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.core.Direction;
7
import net.minecraft.network.syncher.EntityDataAccessor;
8
import net.minecraft.network.syncher.EntityDataSerializers;
9
import net.minecraft.network.syncher.SynchedEntityData;
10
import net.minecraft.server.level.ServerLevel;
11
import net.minecraft.sounds.SoundEvent;
12
import net.minecraft.sounds.SoundEvents;
13
import net.minecraft.sounds.SoundSource;
14
import net.minecraft.tags.ItemTags;
15
import net.minecraft.util.RandomSource;
16
import net.minecraft.util.profiling.Profiler;
17
import net.minecraft.util.profiling.ProfilerFiller;
18
import net.minecraft.world.DifficultyInstance;
19
import net.minecraft.world.InteractionHand;
20
import net.minecraft.world.InteractionResult;
21
import net.minecraft.world.damagesource.DamageSource;
22
import net.minecraft.world.entity.AnimationState;
23
import net.minecraft.world.entity.ContainerUser;
24
import net.minecraft.world.entity.EntitySpawnReason;
25
import net.minecraft.world.entity.EntityType;
26
import net.minecraft.world.entity.EquipmentSlot;
27
import net.minecraft.world.entity.LightningBolt;
28
import net.minecraft.world.entity.Mob;
29
import net.minecraft.world.entity.Shearable;
30
import net.minecraft.world.entity.SpawnGroupData;
31
import net.minecraft.world.entity.ai.Brain;
32
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
33
import net.minecraft.world.entity.ai.attributes.Attributes;
34
import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
35
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
36
import net.minecraft.world.entity.ai.sensing.SensorType;
37
import net.minecraft.world.entity.player.Player;
38
import net.minecraft.world.item.ItemStack;
39
import net.minecraft.world.item.Items;
40
import net.minecraft.world.level.Level;
41
import net.minecraft.world.level.ServerLevelAccessor;
42
import net.minecraft.world.level.block.Blocks;
43
import net.minecraft.world.level.block.ChestBlock;
44
import net.minecraft.world.level.block.CopperGolemStatueBlock;
45
import net.minecraft.world.level.block.WeatheringCopper;
46
import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
47
import net.minecraft.world.level.block.entity.CopperGolemStatueBlockEntity;
48
import net.minecraft.world.level.block.state.BlockState;
49
import net.minecraft.world.level.block.state.properties.ChestType;
50
import net.minecraft.world.level.gameevent.GameEvent;
51
import net.minecraft.world.level.gamerules.GameRules;
52
import net.minecraft.world.level.pathfinder.PathType;
53
import net.minecraft.world.level.storage.ValueInput;
54
import net.minecraft.world.level.storage.ValueOutput;
55
import net.minecraft.world.phys.Vec3;
56
import org.jspecify.annotations.Nullable;
57
58
public class CopperGolem extends AbstractGolem implements ContainerUser, Shearable {
59
	private static final long IGNORE_WEATHERING_TICK = -2L;
60
	private static final long UNSET_WEATHERING_TICK = -1L;
61
	private static final int WEATHERING_TICK_FROM = 504000;
62
	private static final int WEATHERING_TICK_TO = 552000;
63
	private static final int SPIN_ANIMATION_MIN_COOLDOWN = 200;
64
	private static final int SPIN_ANIMATION_MAX_COOLDOWN = 240;
65
	private static final float SPIN_SOUND_TIME_INTERVAL_OFFSET = 10.0F;
66
	private static final float TURN_TO_STATUE_CHANCE = 0.0058F;
67
	private static final int SPAWN_COOLDOWN_MIN = 60;
68
	private static final int SPAWN_COOLDOWN_MAX = 100;
69
	private static final Brain.Provider<CopperGolem> BRAIN_PROVIDER = Brain.provider(
70
		List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.HURT_BY), var0 -> CopperGolemAi.getActivities()
71
	);
72
	private static final EntityDataAccessor<WeatheringCopper.WeatherState> DATA_WEATHER_STATE = SynchedEntityData.defineId(
73
		CopperGolem.class, EntityDataSerializers.WEATHERING_COPPER_STATE
74
	);
75
	private static final EntityDataAccessor<CopperGolemState> COPPER_GOLEM_STATE = SynchedEntityData.defineId(
76
		CopperGolem.class, EntityDataSerializers.COPPER_GOLEM_STATE
77
	);
78
	private @Nullable BlockPos openedChestPos;
79
	private @Nullable UUID lastLightningBoltUUID;
80
	private long nextWeatheringTick = -1L;
81
	private int idleAnimationStartTick = 0;
82
	private final AnimationState idleAnimationState = new AnimationState();
83
	private final AnimationState interactionGetItemAnimationState = new AnimationState();
84
	private final AnimationState interactionGetNoItemAnimationState = new AnimationState();
85
	private final AnimationState interactionDropItemAnimationState = new AnimationState();
86
	private final AnimationState interactionDropNoItemAnimationState = new AnimationState();
87
	public static final EquipmentSlot EQUIPMENT_SLOT_ANTENNA = EquipmentSlot.SADDLE;
88
89
	public CopperGolem(final EntityType<? extends AbstractGolem> type, final Level level) {
90
		super(type, level);
91
		this.getNavigation().setRequiredPathLength(48.0F);
92
		this.getNavigation().setCanOpenDoors(true);
93
		this.setPersistenceRequired();
94
		this.setState(CopperGolemState.IDLE);
95
		this.setPathfindingMalus(PathType.FIRE_IN_NEIGHBOR, 16.0F);
96
		this.setPathfindingMalus(PathType.DAMAGING_IN_NEIGHBOR, 16.0F);
97
		this.setPathfindingMalus(PathType.FIRE, -1.0F);
98
		this.getBrain().setMemory(MemoryModuleType.TRANSPORT_ITEMS_COOLDOWN_TICKS, this.getRandom().nextInt(60, 100));
99
	}
100
101
	public static AttributeSupplier.Builder createAttributes() {
102
		return Mob.createMobAttributes().add(Attributes.MOVEMENT_SPEED, 0.2F).add(Attributes.STEP_HEIGHT, 1.0).add(Attributes.MAX_HEALTH, 12.0);
103
	}
104
105
	public CopperGolemState getState() {
106
		return this.entityData.get(COPPER_GOLEM_STATE);
107
	}
108
109
	public void setState(final CopperGolemState state) {
110
		this.entityData.set(COPPER_GOLEM_STATE, state);
111
	}
112
113
	public WeatheringCopper.WeatherState getWeatherState() {
114
		return this.entityData.get(DATA_WEATHER_STATE);
115
	}
116
117
	public void setWeatherState(final WeatheringCopper.WeatherState state) {
118
		this.entityData.set(DATA_WEATHER_STATE, state);
119
	}
120
121
	public void setOpenedChestPos(final BlockPos openedChestPos) {
122
		this.openedChestPos = openedChestPos;
123
	}
124
125
	public void clearOpenedChestPos() {
126
		this.openedChestPos = null;
127
	}
128
129
	public AnimationState getIdleAnimationState() {
130
		return this.idleAnimationState;
131
	}
132
133
	public AnimationState getInteractionGetItemAnimationState() {
134
		return this.interactionGetItemAnimationState;
135
	}
136
137
	public AnimationState getInteractionGetNoItemAnimationState() {
138
		return this.interactionGetNoItemAnimationState;
139
	}
140
141
	public AnimationState getInteractionDropItemAnimationState() {
142
		return this.interactionDropItemAnimationState;
143
	}
144
145
	public AnimationState getInteractionDropNoItemAnimationState() {
146
		return this.interactionDropNoItemAnimationState;
147
	}
148
149
	@Override
150
	protected Brain<CopperGolem> makeBrain(final Brain.Packed packedBrain) {
151
		return BRAIN_PROVIDER.makeBrain(this, packedBrain);
152
	}
153
154
	@Override
155
	public Brain<CopperGolem> getBrain() {
156
		return super.getBrain();
157
	}
158
159
	@Override
160
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
161
		super.defineSynchedData(entityData);
162
		entityData.define(DATA_WEATHER_STATE, WeatheringCopper.WeatherState.UNAFFECTED);
163
		entityData.define(COPPER_GOLEM_STATE, CopperGolemState.IDLE);
164
	}
165
166
	@Override
167
	public void addAdditionalSaveData(final ValueOutput output) {
168
		super.addAdditionalSaveData(output);
169
		output.putLong("next_weather_age", this.nextWeatheringTick);
170
		output.store("weather_state", WeatheringCopper.WeatherState.CODEC, this.getWeatherState());
171
	}
172
173
	@Override
174
	public void readAdditionalSaveData(final ValueInput input) {
175
		super.readAdditionalSaveData(input);
176
		this.nextWeatheringTick = input.getLongOr("next_weather_age", -1L);
177
		this.setWeatherState(input.read("weather_state", WeatheringCopper.WeatherState.CODEC).orElse(WeatheringCopper.WeatherState.UNAFFECTED));
178
	}
179
180
	@Override
181
	protected void customServerAiStep(final ServerLevel level) {
182
		ProfilerFiller profiler = Profiler.get();
183
		profiler.push("copperGolemBrain");
184
		this.getBrain().tick(level, this);
185
		profiler.pop();
186
		profiler.push("copperGolemActivityUpdate");
187
		CopperGolemAi.updateActivity(this);
188
		profiler.pop();
189
		super.customServerAiStep(level);
190
	}
191
192
	@Override
193
	public void tick() {
194
		super.tick();
195
		if (this.level().isClientSide()) {
196
			if (!this.isNoAi()) {
197
				this.setupAnimationStates();
198
			}
199
		} else {
200
			this.updateWeathering((ServerLevel)this.level(), this.level().getRandom(), this.level().getGameTime());
201
		}
202
	}
203
204
	@Override
205
	public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
206
		ItemStack itemStack = player.getItemInHand(hand);
207
		if (itemStack.isEmpty()) {
208
			ItemStack equippedItem = this.getMainHandItem();
209
			if (!equippedItem.isEmpty()) {
210
				BehaviorUtils.throwItem(this, equippedItem, player.position());
211
				this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
212
				return InteractionResult.SUCCESS;
213
			}
214
		}
215
216
		Level level = this.level();
217
		if (itemStack.is(Items.SHEARS) && this.readyForShearing()) {
218
			if (level instanceof ServerLevel serverLevel) {
219
				this.shear(serverLevel, SoundSource.PLAYERS, itemStack);
220
				this.gameEvent(GameEvent.SHEAR, player);
221
				itemStack.hurtAndBreak(1, player, hand);
222
			}
223
224
			return InteractionResult.SUCCESS;
225
		} else {
226
			if (level.isClientSide()) {
227
				return InteractionResult.PASS;
228
			}
229
230
			if (itemStack.is(Items.HONEYCOMB) && this.nextWeatheringTick != -2L) {
231
				BlockPos pos = this.blockPosition();
232
				level.levelEvent(this, 3003, pos, 0);
233
				level.playSound(null, pos, SoundEvents.HONEYCOMB_WAX_ON, SoundSource.BLOCKS, 1.0F, 1.0F);
234
				this.nextWeatheringTick = -2L;
235
				this.usePlayerItem(player, hand, itemStack);
236
				return InteractionResult.SUCCESS_SERVER;
237
			}
238
239
			if (itemStack.is(ItemTags.AXES) && this.nextWeatheringTick == -2L) {
240
				level.playSound(null, this, SoundEvents.AXE_SCRAPE, this.getSoundSource(), 1.0F, 1.0F);
241
				level.levelEvent(this, 3004, this.blockPosition(), 0);
242
				this.nextWeatheringTick = -1L;
243
				itemStack.hurtAndBreak(1, player, hand.asEquipmentSlot());
244
				return InteractionResult.SUCCESS_SERVER;
245
			}
246
247
			if (itemStack.is(ItemTags.AXES)) {
248
				WeatheringCopper.WeatherState weatherState = this.getWeatherState();
249
				if (weatherState != WeatheringCopper.WeatherState.UNAFFECTED) {
250
					level.playSound(null, this, SoundEvents.AXE_SCRAPE, this.getSoundSource(), 1.0F, 1.0F);
251
					level.levelEvent(this, 3005, this.blockPosition(), 0);
252
					this.nextWeatheringTick = -1L;
253
					this.entityData.set(DATA_WEATHER_STATE, weatherState.previous(), true);
254
					itemStack.hurtAndBreak(1, player, hand.asEquipmentSlot());
255
					return InteractionResult.SUCCESS_SERVER;
256
				}
257
			}
258
259
			return super.mobInteract(player, hand);
260
		}
261
	}
262
263
	private void updateWeathering(final ServerLevel level, final RandomSource random, final long gameTime) {
264
		if (this.nextWeatheringTick != -2L) {
265
			if (this.nextWeatheringTick == -1L) {
266
				this.nextWeatheringTick = gameTime + random.nextIntBetweenInclusive(504000, 552000);
267
			} else {
268
				WeatheringCopper.WeatherState weatherState = this.entityData.get(DATA_WEATHER_STATE);
269
				boolean isFullyOxidized = weatherState.equals(WeatheringCopper.WeatherState.OXIDIZED);
270
				if (gameTime >= this.nextWeatheringTick && !isFullyOxidized) {
271
					WeatheringCopper.WeatherState newState = weatherState.next();
272
					boolean isNewStateFullyOxidized = newState.equals(WeatheringCopper.WeatherState.OXIDIZED);
273
					this.setWeatherState(newState);
274
					this.nextWeatheringTick = isNewStateFullyOxidized ? 0L : this.nextWeatheringTick + random.nextIntBetweenInclusive(504000, 552000);
275
				}
276
277
				if (isFullyOxidized && this.canTurnToStatue(level)) {
278
					this.turnToStatue(level);
279
				}
280
			}
281
		}
282
	}
283
284
	private boolean canTurnToStatue(final Level level) {
285
		return level.getBlockState(this.blockPosition()).isAir() && level.getRandom().nextFloat() <= 0.0058F;
286
	}
287
288
	private void turnToStatue(final ServerLevel level) {
289
		BlockPos pos = this.blockPosition();
290
		level.setBlockAndUpdate(
291
			pos,
292
			Blocks.COPPER_GOLEM_STATUE
293
				.weathering()
294
				.oxidized()
295
				.defaultBlockState()
296
				.setValue(CopperGolemStatueBlock.POSE, CopperGolemStatueBlock.Pose.values()[this.random.nextInt(0, CopperGolemStatueBlock.Pose.values().length)])
297
				.setValue(CopperGolemStatueBlock.FACING, Direction.fromYRot(this.getYRot()))
298
		);
299
		if (level.getBlockEntity(pos) instanceof CopperGolemStatueBlockEntity copperGolemStatueBlockEntity) {
300
			copperGolemStatueBlockEntity.createStatue(this);
301
			this.dropPreservedEquipment(level);
302
			this.discard();
303
			this.playSound(SoundEvents.COPPER_GOLEM_BECOME_STATUE);
304
			if (this.isLeashed()) {
305
				if (level.getGameRules().get(GameRules.ENTITY_DROPS)) {
306
					this.dropLeash();
307
				} else {
308
					this.removeLeash();
309
				}
310
			}
311
		}
312
	}
313
314
	private void setupAnimationStates() {
315
		switch (this.getState()) {
316
			case IDLE:
317
				this.interactionGetNoItemAnimationState.stop();
318
				this.interactionGetItemAnimationState.stop();
319
				this.interactionDropItemAnimationState.stop();
320
				this.interactionDropNoItemAnimationState.stop();
321
				if (this.idleAnimationStartTick == this.tickCount) {
322
					this.idleAnimationState.start(this.tickCount);
323
				} else if (this.idleAnimationStartTick == 0) {
324
					this.idleAnimationStartTick = this.tickCount + this.random.nextInt(200, 240);
325
				}
326
327
				if (this.tickCount == this.idleAnimationStartTick + 10.0F) {
328
					this.playHeadSpinSound();
329
					this.idleAnimationStartTick = 0;
330
				}
331
				break;
332
			case GETTING_ITEM:
333
				this.idleAnimationState.stop();
334
				this.idleAnimationStartTick = 0;
335
				this.interactionGetNoItemAnimationState.stop();
336
				this.interactionDropItemAnimationState.stop();
337
				this.interactionDropNoItemAnimationState.stop();
338
				this.interactionGetItemAnimationState.startIfStopped(this.tickCount);
339
				break;
340
			case GETTING_NO_ITEM:
341
				this.idleAnimationState.stop();
342
				this.idleAnimationStartTick = 0;
343
				this.interactionGetItemAnimationState.stop();
344
				this.interactionDropNoItemAnimationState.stop();
345
				this.interactionDropItemAnimationState.stop();
346
				this.interactionGetNoItemAnimationState.startIfStopped(this.tickCount);
347
				break;
348
			case DROPPING_ITEM:
349
				this.idleAnimationState.stop();
350
				this.idleAnimationStartTick = 0;
351
				this.interactionGetItemAnimationState.stop();
352
				this.interactionGetNoItemAnimationState.stop();
353
				this.interactionDropNoItemAnimationState.stop();
354
				this.interactionDropItemAnimationState.startIfStopped(this.tickCount);
355
				break;
356
			case DROPPING_NO_ITEM:
357
				this.idleAnimationState.stop();
358
				this.idleAnimationStartTick = 0;
359
				this.interactionGetItemAnimationState.stop();
360
				this.interactionGetNoItemAnimationState.stop();
361
				this.interactionDropItemAnimationState.stop();
362
				this.interactionDropNoItemAnimationState.startIfStopped(this.tickCount);
363
		}
364
	}
365
366
	public void spawn(final WeatheringCopper.WeatherState weatherState) {
367
		this.setWeatherState(weatherState);
368
		this.playSpawnSound();
369
	}
370
371
	@Override
372
	public @Nullable SpawnGroupData finalizeSpawn(
373
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
374
	) {
375
		this.playSpawnSound();
376
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
377
	}
378
379
	public void playSpawnSound() {
380
		this.playSound(SoundEvents.COPPER_GOLEM_SPAWN);
381
	}
382
383
	private void playHeadSpinSound() {
384
		if (!this.isSilent()) {
385
			this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), this.getSpinHeadSound(), this.getSoundSource(), 1.0F, 1.0F, false);
386
		}
387
	}
388
389
	@Override
390
	protected SoundEvent getHurtSound(final DamageSource source) {
391
		return CopperGolemOxidationLevels.getOxidationLevel(this.getWeatherState()).hurtSound();
392
	}
393
394
	@Override
395
	protected SoundEvent getDeathSound() {
396
		return CopperGolemOxidationLevels.getOxidationLevel(this.getWeatherState()).deathSound();
397
	}
398
399
	@Override
400
	protected void playStepSound(final BlockPos pos, final BlockState blockState) {
401
		this.playSound(CopperGolemOxidationLevels.getOxidationLevel(this.getWeatherState()).stepSound(), 1.0F, 1.0F);
402
	}
403
404
	private SoundEvent getSpinHeadSound() {
405
		return CopperGolemOxidationLevels.getOxidationLevel(this.getWeatherState()).spinHeadSound();
406
	}
407
408
	@Override
409
	public Vec3 getLeashOffset() {
410
		return new Vec3(0.0, 0.75F * this.getEyeHeight(), 0.0);
411
	}
412
413
	@Override
414
	public boolean hasContainerOpen(final ContainerOpenersCounter container, final BlockPos blockPos) {
415
		if (this.openedChestPos == null) {
416
			return false;
417
		}
418
419
		BlockState blockState = this.level().getBlockState(this.openedChestPos);
420
		return this.openedChestPos.equals(blockPos)
421
			|| blockState.getBlock() instanceof ChestBlock
422
				&& blockState.getValue(ChestBlock.TYPE) != ChestType.SINGLE
423
				&& ChestBlock.getConnectedBlockPos(this.openedChestPos, blockState).equals(blockPos);
424
	}
425
426
	@Override
427
	public double getContainerInteractionRange() {
428
		return 3.0;
429
	}
430
431
	@Override
432
	public void shear(final ServerLevel level, final SoundSource soundSource, final ItemStack tool) {
433
		level.playSound(null, this, SoundEvents.COPPER_GOLEM_SHEAR, soundSource, 1.0F, 1.0F);
434
		ItemStack itemStack = this.getItemBySlot(EQUIPMENT_SLOT_ANTENNA);
435
		this.setItemSlot(EQUIPMENT_SLOT_ANTENNA, ItemStack.EMPTY);
436
		this.spawnAtLocation(level, itemStack, 1.5F);
437
	}
438
439
	@Override
440
	public boolean readyForShearing() {
441
		return this.getItemBySlot(EQUIPMENT_SLOT_ANTENNA).is(ItemTags.SHEARABLE_FROM_COPPER_GOLEM);
442
	}
443
444
	@Override
445
	protected void dropEquipment(final ServerLevel level) {
446
		super.dropEquipment(level);
447
		this.dropPreservedEquipment(level);
448
	}
449
450
	@Override
451
	protected void actuallyHurt(final ServerLevel level, final DamageSource source, final float dmg) {
452
		super.actuallyHurt(level, source, dmg);
453
		this.setState(CopperGolemState.IDLE);
454
	}
455
456
	@Override
457
	public void thunderHit(final ServerLevel level, final LightningBolt lightningBolt) {
458
		super.thunderHit(level, lightningBolt);
459
		UUID lightningBoltUUID = lightningBolt.getUUID();
460
		if (!lightningBoltUUID.equals(this.lastLightningBoltUUID)) {
461
			this.lastLightningBoltUUID = lightningBoltUUID;
462
			WeatheringCopper.WeatherState weatherState = this.getWeatherState();
463
			if (weatherState != WeatheringCopper.WeatherState.UNAFFECTED) {
464
				this.nextWeatheringTick = -1L;
465
				this.entityData.set(DATA_WEATHER_STATE, weatherState.previous(), true);
466
			}
467
		}
468
	}
469
}
470

Decompiled Minecraft 26.3 source of CopperGolem (net/minecraft/world/entity/animal/golem/CopperGolem.java) with Mojang official mappings, stored verbatim on the site.