1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
--- a/net/minecraft/world/entity/animal/IronGolem.java
+++ b/net/minecraft/world/entity/animal/IronGolem.java
@@ -2,6 +2,7 @@
import com.google.common.collect.ImmutableList;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;
@@ -16,7 +17,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.TimeUtil;
import net.minecraft.util.valueproviders.UniformInt;
-import net.minecraft.world.InteractionHand;
+import net.minecraft.world.EnumHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
@@ -38,18 +39,19 @@
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal;
import net.minecraft.world.entity.monster.Creeper;
-import net.minecraft.world.entity.monster.Enemy;
+import net.minecraft.world.entity.monster.IMonster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.NaturalSpawner;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.Vec3;
public class IronGolem extends AbstractGolem implements NeutralMob {
+
protected static final EntityDataAccessor<Byte> DATA_FLAGS_ID = SynchedEntityData.defineId(IronGolem.class, EntityDataSerializers.BYTE);
private static final int IRON_INGOT_HEAL_AMOUNT = 25;
private int attackAnimationTick;
@@ -66,33 +68,30 @@
@Override
protected void registerGoals() {
- this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0, true));
- this.goalSelector.addGoal(2, new MoveTowardsTargetGoal(this, 0.9, 32.0F));
- this.goalSelector.addGoal(2, new MoveBackToVillageGoal(this, 0.6, false));
- this.goalSelector.addGoal(4, new GolemRandomStrollInVillageGoal(this, 0.6));
+ this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0D, true));
+ this.goalSelector.addGoal(2, new MoveTowardsTargetGoal(this, 0.9D, 32.0F));
+ this.goalSelector.addGoal(2, new MoveBackToVillageGoal(this, 0.6D, false));
+ this.goalSelector.addGoal(4, new GolemRandomStrollInVillageGoal(this, 0.6D));
this.goalSelector.addGoal(5, new OfferFlowerGoal(this));
this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
this.targetSelector.addGoal(1, new DefendVillageTargetGoal(this));
- this.targetSelector.addGoal(2, new HurtByTargetGoal(this));
+ this.targetSelector.addGoal(2, new HurtByTargetGoal(this, new Class[0]));
this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, this::isAngryAt));
- this.targetSelector
- .addGoal(3, new NearestAttackableTargetGoal<>(this, Mob.class, 5, false, false, entity -> entity instanceof Enemy && !(entity instanceof Creeper)));
+ this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Mob.class, 5, false, false, (entityliving) -> {
+ return entityliving instanceof IMonster && !(entityliving instanceof Creeper);
+ }));
this.targetSelector.addGoal(4, new ResetUniversalAngerTargetGoal<>(this, false));
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
- this.entityData.define(DATA_FLAGS_ID, (byte)0);
+ this.entityData.define(IronGolem.DATA_FLAGS_ID, (byte) 0);
}
public static AttributeSupplier.Builder createAttributes() {
- return Mob.createMobAttributes()
- .add(Attributes.MAX_HEALTH, 100.0)
- .add(Attributes.MOVEMENT_SPEED, 0.25)
- .add(Attributes.KNOCKBACK_RESISTANCE, 1.0)
- .add(Attributes.ATTACK_DAMAGE, 15.0);
+ return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 100.0D).add(Attributes.MOVEMENT_SPEED, 0.25D).add(Attributes.KNOCKBACK_RESISTANCE, 1.0D).add(Attributes.ATTACK_DAMAGE, 15.0D);
}
@Override
@@ -102,8 +101,8 @@
@Override
protected void doPush(Entity entity) {
- if (entity instanceof Enemy && !(entity instanceof Creeper) && this.getRandom().nextInt(20) == 0) {
- this.setTarget((LivingEntity)entity);
+ if (entity instanceof IMonster && !(entity instanceof Creeper) && this.getRandom().nextInt(20) == 0) {
+ this.setTarget((LivingEntity) entity, org.bukkit.event.entity.EntityTargetLivingEntityEvent.TargetReason.COLLISION, true); // CraftBukkit - set reason
}
super.doPush(entity);
@@ -113,26 +112,27 @@
public void aiStep() {
super.aiStep();
if (this.attackAnimationTick > 0) {
- this.attackAnimationTick--;
+ --this.attackAnimationTick;
}
if (this.offerFlowerTick > 0) {
- this.offerFlowerTick--;
+ --this.offerFlowerTick;
}
if (!this.level().isClientSide) {
- this.updatePersistentAnger((ServerLevel)this.level(), true);
+ this.updatePersistentAnger((ServerLevel) this.level(), true);
}
+
}
@Override
public boolean canSpawnSprintParticle() {
- return this.getDeltaMovement().horizontalDistanceSqr() > 2.5000003E-7F && this.random.nextInt(5) == 0;
+ return this.getDeltaMovement().horizontalDistanceSqr() > 2.500000277905201E-7D && this.random.nextInt(5) == 0;
}
@Override
public boolean canAttackType(EntityType<?> type) {
- return (!this.isPlayerCreated() || type != EntityType.PLAYER) && type != EntityType.CREEPER && super.canAttackType(type);
+ return this.isPlayerCreated() && type == EntityType.PLAYER ? false : (type == EntityType.CREEPER ? false : super.canAttackType(type));
}
@Override
@@ -151,7 +151,7 @@
@Override
public void startPersistentAngerTimer() {
- this.setRemainingPersistentAngerTime(PERSISTENT_ANGER_TIME.sample(this.random));
+ this.setRemainingPersistentAngerTime(IronGolem.PERSISTENT_ANGER_TIME.sample(this.random));
}
@Override
@@ -176,20 +176,32 @@
}
private float getAttackDamage() {
- return (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
+ return (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE);
}
@Override
public boolean doHurtTarget(Entity entity) {
this.attackAnimationTick = 10;
- this.level().broadcastEntityEvent(this, (byte)4);
- float attackDamage = this.getAttackDamage();
- float f = (int)attackDamage > 0 ? attackDamage / 2.0F + (float)this.random.nextInt((int)attackDamage) : attackDamage;
- boolean flag = entity.hurt(this.damageSources().mobAttack(this), f);
+ this.level().broadcastEntityEvent(this, (byte) 4);
+ float f = this.getAttackDamage();
+ float f1 = (int) f > 0 ? f / 2.0F + (float) this.random.nextInt((int) f) : f;
+ boolean flag = entity.hurt(this.damageSources().mobAttack(this), f1);
+
if (flag) {
- double d = entity instanceof LivingEntity livingEntity ? livingEntity.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE) : 0.0;
- double max = Math.max(0.0, 1.0 - d);
- entity.setDeltaMovement(entity.getDeltaMovement().add(0.0, 0.4F * max, 0.0));
+ double d0;
+
+ if (entity instanceof LivingEntity) {
+ LivingEntity entityliving = (LivingEntity) entity;
+
+ d0 = entityliving.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
+ } else {
+ d0 = 0.0D;
+ }
+
+ double d1 = d0;
+ double d2 = Math.max(0.0D, 1.0D - d1);
+
+ entity.setDeltaMovement(entity.getDeltaMovement().add(0.0D, 0.4000000059604645D * d2, 0.0D));
this.doEnchantDamageEffects(this, entity);
}
@@ -199,9 +211,10 @@
@Override
public boolean hurt(DamageSource source, float amount) {
- IronGolem.Crackiness crackiness = this.getCrackiness();
+ IronGolem.Crackiness entityirongolem_cracklevel = this.getCrackiness();
boolean flag = super.hurt(source, amount);
- if (flag && this.getCrackiness() != crackiness) {
+
+ if (flag && this.getCrackiness() != entityirongolem_cracklevel) {
this.playSound(SoundEvents.IRON_GOLEM_DAMAGE, 1.0F, 1.0F);
}
@@ -224,6 +237,7 @@
} else {
super.handleEntityEvent(id);
}
+
}
public int getAttackAnimationTick() {
@@ -233,11 +247,12 @@
public void offerFlower(boolean offeringFlower) {
if (offeringFlower) {
this.offerFlowerTick = 400;
- this.level().broadcastEntityEvent(this, (byte)11);
+ this.level().broadcastEntityEvent(this, (byte) 11);
} else {
this.offerFlowerTick = 0;
- this.level().broadcastEntityEvent(this, (byte)34);
+ this.level().broadcastEntityEvent(this, (byte) 34);
}
+
}
@Override
@@ -251,20 +266,23 @@
}
@Override
- protected InteractionResult mobInteract(Player player, InteractionHand hand) {
- ItemStack itemInHand = player.getItemInHand(hand);
- if (!itemInHand.is(Items.IRON_INGOT)) {
+ protected InteractionResult mobInteract(Player player, EnumHand hand) {
+ ItemStack itemstack = player.getItemInHand(hand);
+
+ if (!itemstack.is(Items.IRON_INGOT)) {
return InteractionResult.PASS;
} else {
- float health = this.getHealth();
+ float f = this.getHealth();
+
this.heal(25.0F);
- if (this.getHealth() == health) {
+ if (this.getHealth() == f) {
return InteractionResult.PASS;
} else {
- float f = 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.2F;
- this.playSound(SoundEvents.IRON_GOLEM_REPAIR, 1.0F, f);
+ float f1 = 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.2F;
+
+ this.playSound(SoundEvents.IRON_GOLEM_REPAIR, 1.0F, f1);
if (!player.getAbilities().instabuild) {
- itemInHand.shrink(1);
+ itemstack.shrink(1);
}
return InteractionResult.sidedSuccess(this.level().isClientSide);
@@ -273,7 +291,7 @@
}
@Override
- protected void playStepSound(BlockPos pos, BlockState block) {
+ protected void playStepSound(BlockPos pos, IBlockData block) {
this.playSound(SoundEvents.IRON_GOLEM_STEP, 1.0F, 1.0F);
}
@@ -282,16 +300,18 @@
}
public boolean isPlayerCreated() {
- return (this.entityData.get(DATA_FLAGS_ID) & 1) != 0;
+ return ((Byte) this.entityData.get(IronGolem.DATA_FLAGS_ID) & 1) != 0;
}
public void setPlayerCreated(boolean playerCreated) {
- byte b = this.entityData.get(DATA_FLAGS_ID);
+ byte b0 = (Byte) this.entityData.get(IronGolem.DATA_FLAGS_ID);
+
if (playerCreated) {
- this.entityData.set(DATA_FLAGS_ID, (byte)(b | 1));
+ this.entityData.set(IronGolem.DATA_FLAGS_ID, (byte) (b0 | 1));
} else {
- this.entityData.set(DATA_FLAGS_ID, (byte)(b & -2));
+ this.entityData.set(IronGolem.DATA_FLAGS_ID, (byte) (b0 & -2));
}
+
}
@Override
@@ -301,55 +321,58 @@
@Override
public boolean checkSpawnObstruction(LevelReader level) {
- BlockPos blockPos = this.blockPosition();
- BlockPos blockPos1 = blockPos.below();
- BlockState blockState = level.getBlockState(blockPos1);
- if (!blockState.entityCanStandOn(level, blockPos1, this)) {
+ BlockPos blockposition = this.blockPosition();
+ BlockPos blockposition1 = blockposition.below();
+ IBlockData iblockdata = level.getBlockState(blockposition1);
+
+ if (!iblockdata.entityCanStandOn(level, blockposition1, this)) {
return false;
} else {
- for (int i = 1; i < 3; i++) {
- BlockPos blockPos2 = blockPos.above(i);
- BlockState blockState1 = level.getBlockState(blockPos2);
- if (!NaturalSpawner.isValidEmptySpawnBlock(level, blockPos2, blockState1, blockState1.getFluidState(), EntityType.IRON_GOLEM)) {
+ for (int i = 1; i < 3; ++i) {
+ BlockPos blockposition2 = blockposition.above(i);
+ IBlockData iblockdata1 = level.getBlockState(blockposition2);
+
+ if (!NaturalSpawner.isValidEmptySpawnBlock(level, blockposition2, iblockdata1, iblockdata1.getFluidState(), EntityType.IRON_GOLEM)) {
return false;
}
}
- return NaturalSpawner.isValidEmptySpawnBlock(
- level, blockPos, level.getBlockState(blockPos), Fluids.EMPTY.defaultFluidState(), EntityType.IRON_GOLEM
- )
- && level.isUnobstructed(this);
+ return NaturalSpawner.isValidEmptySpawnBlock(level, blockposition, level.getBlockState(blockposition), Fluids.EMPTY.defaultFluidState(), EntityType.IRON_GOLEM) && level.isUnobstructed(this);
}
}
@Override
public Vec3 getLeashOffset() {
- return new Vec3(0.0, (double)(0.875F * this.getEyeHeight()), (double)(this.getBbWidth() * 0.4F));
+ return new Vec3(0.0D, (double) (0.875F * this.getEyeHeight()), (double) (this.getBbWidth() * 0.4F));
}
public static enum Crackiness {
- NONE(1.0F),
- LOW(0.75F),
- MEDIUM(0.5F),
- HIGH(0.25F);
- private static final List<IronGolem.Crackiness> BY_DAMAGE = Stream.of(values())
- .sorted(Comparator.comparingDouble(crack -> (double)crack.fraction))
- .collect(ImmutableList.toImmutableList());
+ NONE(1.0F), LOW(0.75F), MEDIUM(0.5F), HIGH(0.25F);
+
+ private static final List<IronGolem.Crackiness> BY_DAMAGE = (List) Stream.of(values()).sorted(Comparator.comparingDouble((entityirongolem_cracklevel) -> {
+ return (double) entityirongolem_cracklevel.fraction;
+ })).collect(ImmutableList.toImmutableList());
private final float fraction;
- private Crackiness(float fraction) {
- this.fraction = fraction;
+ private Crackiness(float f) {
+ this.fraction = f;
}
public static IronGolem.Crackiness byFraction(float fraction) {
- for (IronGolem.Crackiness crackiness : BY_DAMAGE) {
- if (fraction < crackiness.fraction) {
- return crackiness;
+ Iterator iterator = IronGolem.Crackiness.BY_DAMAGE.iterator();
+
+ IronGolem.Crackiness entityirongolem_cracklevel;
+
+ do {
+ if (!iterator.hasNext()) {
+ return IronGolem.Crackiness.NONE;
}
- }
- return NONE;
+ entityirongolem_cracklevel = (IronGolem.Crackiness) iterator.next();
+ } while (fraction >= entityirongolem_cracklevel.fraction);
+
+ return entityirongolem_cracklevel;
}
}
}
|