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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
--- a/net/minecraft/world/entity/monster/Guardian.java
+++ b/net/minecraft/world/entity/monster/Guardian.java
@@ -19,12 +19,12 @@
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
+import net.minecraft.world.entity.EntityPose;
import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.EnumMobSpawn;
+import net.minecraft.world.entity.EnumMonsterType;
+import net.minecraft.world.entity.EnumMoveType;
import net.minecraft.world.entity.LivingEntity;
-import net.minecraft.world.entity.MobSpawnType;
-import net.minecraft.world.entity.MobType;
-import net.minecraft.world.entity.MoverType;
-import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.control.LookControl;
@@ -62,10 +62,11 @@
private int clientSideAttackTime;
private boolean clientSideTouchedGround;
@Nullable
- protected RandomStrollGoal randomStrollGoal;
+ public RandomStrollGoal randomStrollGoal;
+ public Guardian.GuardianAttackGoal guardianAttackGoal; // CraftBukkit - add field
- public Guardian(EntityType<? extends Guardian> entitytype, Level level) {
- super(entitytype, level);
+ public Guardian(EntityType<? extends Guardian> entityType, Level level) {
+ super(entityType, level);
this.xpReward = 10;
this.setPathfindingMalus(BlockPathTypes.WATER, 0.0F);
this.moveControl = new Guardian.GuardianMoveControl(this);
@@ -74,19 +75,18 @@
}
@Override
- @Override
protected void registerGoals() {
- MoveTowardsRestrictionGoal movetowardsrestrictiongoal = new MoveTowardsRestrictionGoal(this, 1.0D);
+ MoveTowardsRestrictionGoal pathfindergoalmovetowardsrestriction = new MoveTowardsRestrictionGoal(this, 1.0D);
this.randomStrollGoal = new RandomStrollGoal(this, 1.0D, 80);
- this.goalSelector.addGoal(4, new Guardian.GuardianAttackGoal(this));
- this.goalSelector.addGoal(5, movetowardsrestrictiongoal);
+ this.goalSelector.addGoal(4, guardianAttackGoal = new Guardian.GuardianAttackGoal(this)); // CraftBukkit - assign field
+ this.goalSelector.addGoal(5, pathfindergoalmovetowardsrestriction);
this.goalSelector.addGoal(7, this.randomStrollGoal);
this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F));
this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Guardian.class, 12.0F, 0.01F));
this.goalSelector.addGoal(9, new RandomLookAroundGoal(this));
- this.randomStrollGoal.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
- movetowardsrestrictiongoal.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
+ this.randomStrollGoal.setFlags(EnumSet.of(Goal.Type.MOVE, Goal.Type.LOOK));
+ pathfindergoalmovetowardsrestriction.setFlags(EnumSet.of(Goal.Type.MOVE, Goal.Type.LOOK));
this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, LivingEntity.class, 10, true, false, new Guardian.GuardianAttackSelector(this)));
}
@@ -95,13 +95,11 @@
}
@Override
- @Override
protected PathNavigation createNavigation(Level level) {
return new WaterBoundPathNavigation(this, level);
}
@Override
- @Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(Guardian.DATA_ID_MOVING, false);
@@ -109,25 +107,24 @@
}
@Override
- @Override
- public MobType getMobType() {
- return MobType.WATER;
+ public EnumMonsterType getMobType() {
+ return EnumMonsterType.WATER;
}
public boolean isMoving() {
return (Boolean) this.entityData.get(Guardian.DATA_ID_MOVING);
}
- void setMoving(boolean flag) {
- this.entityData.set(Guardian.DATA_ID_MOVING, flag);
+ void setMoving(boolean moving) {
+ this.entityData.set(Guardian.DATA_ID_MOVING, moving);
}
public int getAttackDuration() {
return 80;
}
- void setActiveAttackTarget(int i) {
- this.entityData.set(Guardian.DATA_ID_ATTACK_TARGET, i);
+ public void setActiveAttackTarget(int activeAttackTargetId) {
+ this.entityData.set(Guardian.DATA_ID_ATTACK_TARGET, activeAttackTargetId);
}
public boolean hasActiveAttackTarget() {
@@ -157,10 +154,9 @@
}
@Override
- @Override
- public void onSyncedDataUpdated(EntityDataAccessor<?> entitydataaccessor) {
- super.onSyncedDataUpdated(entitydataaccessor);
- if (Guardian.DATA_ID_ATTACK_TARGET.equals(entitydataaccessor)) {
+ public void onSyncedDataUpdated(EntityDataAccessor<?> key) {
+ super.onSyncedDataUpdated(key);
+ if (Guardian.DATA_ID_ATTACK_TARGET.equals(key)) {
this.clientSideAttackTime = 0;
this.clientSideCachedAttackTarget = null;
}
@@ -168,63 +164,55 @@
}
@Override
- @Override
public int getAmbientSoundInterval() {
return 160;
}
@Override
- @Override
protected SoundEvent getAmbientSound() {
return this.isInWaterOrBubble() ? SoundEvents.GUARDIAN_AMBIENT : SoundEvents.GUARDIAN_AMBIENT_LAND;
}
@Override
- @Override
- protected SoundEvent getHurtSound(DamageSource damagesource) {
+ protected SoundEvent getHurtSound(DamageSource damageSource) {
return this.isInWaterOrBubble() ? SoundEvents.GUARDIAN_HURT : SoundEvents.GUARDIAN_HURT_LAND;
}
@Override
- @Override
protected SoundEvent getDeathSound() {
return this.isInWaterOrBubble() ? SoundEvents.GUARDIAN_DEATH : SoundEvents.GUARDIAN_DEATH_LAND;
}
@Override
- @Override
protected Entity.MovementEmission getMovementEmission() {
return Entity.MovementEmission.EVENTS;
}
@Override
- @Override
- protected float getStandingEyeHeight(Pose pose, EntityDimensions entitydimensions) {
- return entitydimensions.height * 0.5F;
+ protected float getStandingEyeHeight(EntityPose pose, EntityDimensions size) {
+ return size.height * 0.5F;
}
@Override
- @Override
- public float getWalkTargetValue(BlockPos blockpos, LevelReader levelreader) {
- return levelreader.getFluidState(blockpos).is(FluidTags.WATER) ? 10.0F + levelreader.getPathfindingCostFromLightLevels(blockpos) : super.getWalkTargetValue(blockpos, levelreader);
+ public float getWalkTargetValue(BlockPos pos, LevelReader level) {
+ return level.getFluidState(pos).is(FluidTags.WATER) ? 10.0F + level.getPathfindingCostFromLightLevels(pos) : super.getWalkTargetValue(pos, level);
}
@Override
- @Override
public void aiStep() {
if (this.isAlive()) {
if (this.level().isClientSide) {
this.clientSideTailAnimationO = this.clientSideTailAnimation;
- Vec3 vec3;
+ Vec3 vec3d;
if (!this.isInWater()) {
this.clientSideTailAnimationSpeed = 2.0F;
- vec3 = this.getDeltaMovement();
- if (vec3.y > 0.0D && this.clientSideTouchedGround && !this.isSilent()) {
+ vec3d = this.getDeltaMovement();
+ if (vec3d.y > 0.0D && this.clientSideTouchedGround && !this.isSilent()) {
this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), this.getFlopSound(), this.getSoundSource(), 1.0F, 1.0F, false);
}
- this.clientSideTouchedGround = vec3.y < 0.0D && this.level().loadedAndEntityCanStandOn(this.blockPosition().below(), this);
+ this.clientSideTouchedGround = vec3d.y < 0.0D && this.level().loadedAndEntityCanStandOn(this.blockPosition().below(), this);
} else if (this.isMoving()) {
if (this.clientSideTailAnimationSpeed < 0.5F) {
this.clientSideTailAnimationSpeed = 4.0F;
@@ -246,10 +234,10 @@
}
if (this.isMoving() && this.isInWater()) {
- vec3 = this.getViewVector(0.0F);
+ vec3d = this.getViewVector(0.0F);
for (int i = 0; i < 2; ++i) {
- this.level().addParticle(ParticleTypes.BUBBLE, this.getRandomX(0.5D) - vec3.x * 1.5D, this.getRandomY() - vec3.y * 1.5D, this.getRandomZ(0.5D) - vec3.z * 1.5D, 0.0D, 0.0D, 0.0D);
+ this.level().addParticle(ParticleTypes.BUBBLE, this.getRandomX(0.5D) - vec3d.x * 1.5D, this.getRandomY() - vec3d.y * 1.5D, this.getRandomZ(0.5D) - vec3d.z * 1.5D, 0.0D, 0.0D, 0.0D);
}
}
@@ -258,15 +246,15 @@
++this.clientSideAttackTime;
}
- LivingEntity livingentity = this.getActiveAttackTarget();
+ LivingEntity entityliving = this.getActiveAttackTarget();
- if (livingentity != null) {
- this.getLookControl().setLookAt(livingentity, 90.0F, 90.0F);
+ if (entityliving != null) {
+ this.getLookControl().setLookAt(entityliving, 90.0F, 90.0F);
this.getLookControl().tick();
double d0 = (double) this.getAttackAnimationScale(0.0F);
- double d1 = livingentity.getX() - this.getX();
- double d2 = livingentity.getY(0.5D) - this.getEyeY();
- double d3 = livingentity.getZ() - this.getZ();
+ double d1 = entityliving.getX() - this.getX();
+ double d2 = entityliving.getY(0.5D) - this.getEyeY();
+ double d3 = entityliving.getZ() - this.getZ();
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
d1 /= d4;
@@ -303,16 +291,16 @@
return SoundEvents.GUARDIAN_FLOP;
}
- public float getTailAnimation(float f) {
- return Mth.lerp(f, this.clientSideTailAnimationO, this.clientSideTailAnimation);
+ public float getTailAnimation(float partialTick) {
+ return Mth.lerp(partialTick, this.clientSideTailAnimationO, this.clientSideTailAnimation);
}
- public float getSpikesAnimation(float f) {
- return Mth.lerp(f, this.clientSideSpikesAnimationO, this.clientSideSpikesAnimation);
+ public float getSpikesAnimation(float partialTick) {
+ return Mth.lerp(partialTick, this.clientSideSpikesAnimationO, this.clientSideSpikesAnimation);
}
- public float getAttackAnimationScale(float f) {
- return ((float) this.clientSideAttackTime + f) / (float) this.getAttackDuration();
+ public float getAttackAnimationScale(float partialTick) {
+ return ((float) this.clientSideAttackTime + partialTick) / (float) this.getAttackDuration();
}
public float getClientSideAttackTime() {
@@ -320,28 +308,26 @@
}
@Override
- @Override
- public boolean checkSpawnObstruction(LevelReader levelreader) {
- return levelreader.isUnobstructed(this);
+ public boolean checkSpawnObstruction(LevelReader level) {
+ return level.isUnobstructed(this);
}
- public static boolean checkGuardianSpawnRules(EntityType<? extends Guardian> entitytype, LevelAccessor levelaccessor, MobSpawnType mobspawntype, BlockPos blockpos, RandomSource randomsource) {
- return (randomsource.nextInt(20) == 0 || !levelaccessor.canSeeSkyFromBelowWater(blockpos)) && levelaccessor.getDifficulty() != Difficulty.PEACEFUL && (MobSpawnType.isSpawner(mobspawntype) || levelaccessor.getFluidState(blockpos).is(FluidTags.WATER)) && levelaccessor.getFluidState(blockpos.below()).is(FluidTags.WATER);
+ public static boolean checkGuardianSpawnRules(EntityType<? extends Guardian> guardian, LevelAccessor level, EnumMobSpawn spawnType, BlockPos pos, RandomSource random) {
+ return (random.nextInt(20) == 0 || !level.canSeeSkyFromBelowWater(pos)) && level.getDifficulty() != Difficulty.PEACEFUL && (EnumMobSpawn.isSpawner(spawnType) || level.getFluidState(pos).is(FluidTags.WATER)) && level.getFluidState(pos.below()).is(FluidTags.WATER);
}
@Override
- @Override
- public boolean hurt(DamageSource damagesource, float f) {
+ public boolean hurt(DamageSource source, float amount) {
if (this.level().isClientSide) {
return false;
} else {
- if (!this.isMoving() && !damagesource.is(DamageTypeTags.AVOIDS_GUARDIAN_THORNS) && !damagesource.is(DamageTypes.THORNS)) {
- Entity entity = damagesource.getDirectEntity();
+ if (!this.isMoving() && !source.is(DamageTypeTags.AVOIDS_GUARDIAN_THORNS) && !source.is(DamageTypes.THORNS)) {
+ Entity entity = source.getDirectEntity();
if (entity instanceof LivingEntity) {
- LivingEntity livingentity = (LivingEntity) entity;
+ LivingEntity entityliving = (LivingEntity) entity;
- livingentity.hurt(this.damageSources().thorns(this), 2.0F);
+ entityliving.hurt(this.damageSources().thorns(this), 2.0F);
}
}
@@ -349,36 +335,33 @@
this.randomStrollGoal.trigger();
}
- return super.hurt(damagesource, f);
+ return super.hurt(source, amount);
}
}
@Override
- @Override
public int getMaxHeadXRot() {
return 180;
}
@Override
- @Override
- public void travel(Vec3 vec3) {
+ public void travel(Vec3 travelVector) {
if (this.isControlledByLocalInstance() && this.isInWater()) {
- this.moveRelative(0.1F, vec3);
- this.move(MoverType.SELF, this.getDeltaMovement());
+ this.moveRelative(0.1F, travelVector);
+ this.move(EnumMoveType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
if (!this.isMoving() && this.getTarget() == null) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.005D, 0.0D));
}
} else {
- super.travel(vec3);
+ super.travel(travelVector);
}
}
@Override
- @Override
- protected Vector3f getPassengerAttachmentPoint(Entity entity, EntityDimensions entitydimensions, float f) {
- return new Vector3f(0.0F, entitydimensions.height + 0.125F * f, 0.0F);
+ protected Vector3f getPassengerAttachmentPoint(Entity entity, EntityDimensions entitysize, float f) {
+ return new Vector3f(0.0F, entitysize.height + 0.125F * f, 0.0F);
}
private static class GuardianMoveControl extends MoveControl {
@@ -391,15 +374,14 @@
}
@Override
- @Override
public void tick() {
if (this.operation == MoveControl.Operation.MOVE_TO && !this.guardian.getNavigation().isDone()) {
- Vec3 vec3 = new Vec3(this.wantedX - this.guardian.getX(), this.wantedY - this.guardian.getY(), this.wantedZ - this.guardian.getZ());
- double d0 = vec3.length();
- double d1 = vec3.x / d0;
- double d2 = vec3.y / d0;
- double d3 = vec3.z / d0;
- float f = (float) (Mth.atan2(vec3.z, vec3.x) * 57.2957763671875D) - 90.0F;
+ Vec3 vec3d = new Vec3(this.wantedX - this.guardian.getX(), this.wantedY - this.guardian.getY(), this.wantedZ - this.guardian.getZ());
+ double d0 = vec3d.length();
+ double d1 = vec3d.x / d0;
+ double d2 = vec3d.y / d0;
+ double d3 = vec3d.z / d0;
+ float f = (float) (Mth.atan2(vec3d.z, vec3d.x) * 57.2957763671875D) - 90.0F;
this.guardian.setYRot(this.rotlerp(this.guardian.getYRot(), f, 90.0F));
this.guardian.yBodyRot = this.guardian.getYRot();
@@ -413,15 +395,15 @@
double d7 = Math.sin((double) (this.guardian.tickCount + this.guardian.getId()) * 0.75D) * 0.05D;
this.guardian.setDeltaMovement(this.guardian.getDeltaMovement().add(d4 * d5, d7 * (d6 + d5) * 0.25D + (double) f2 * d2 * 0.1D, d4 * d6));
- LookControl lookcontrol = this.guardian.getLookControl();
+ LookControl controllerlook = this.guardian.getLookControl();
double d8 = this.guardian.getX() + d1 * 2.0D;
double d9 = this.guardian.getEyeY() + d2 / d0;
double d10 = this.guardian.getZ() + d3 * 2.0D;
- double d11 = lookcontrol.getWantedX();
- double d12 = lookcontrol.getWantedY();
- double d13 = lookcontrol.getWantedZ();
+ double d11 = controllerlook.getWantedX();
+ double d12 = controllerlook.getWantedY();
+ double d13 = controllerlook.getWantedZ();
- if (!lookcontrol.isLookingAtTarget()) {
+ if (!controllerlook.isLookingAtTarget()) {
d11 = d8;
d12 = d9;
d13 = d10;
@@ -436,48 +418,44 @@
}
}
- private static class GuardianAttackGoal extends Goal {
+ public static class GuardianAttackGoal extends Goal {
private final Guardian guardian;
- private int attackTime;
+ public int attackTime;
private final boolean elder;
public GuardianAttackGoal(Guardian guardian) {
this.guardian = guardian;
this.elder = guardian instanceof ElderGuardian;
- this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
+ this.setFlags(EnumSet.of(Goal.Type.MOVE, Goal.Type.LOOK));
}
@Override
- @Override
public boolean canUse() {
- LivingEntity livingentity = this.guardian.getTarget();
+ LivingEntity entityliving = this.guardian.getTarget();
- return livingentity != null && livingentity.isAlive();
+ return entityliving != null && entityliving.isAlive();
}
@Override
- @Override
public boolean canContinueToUse() {
return super.canContinueToUse() && (this.elder || this.guardian.getTarget() != null && this.guardian.distanceToSqr((Entity) this.guardian.getTarget()) > 9.0D);
}
@Override
- @Override
public void start() {
this.attackTime = -10;
this.guardian.getNavigation().stop();
- LivingEntity livingentity = this.guardian.getTarget();
+ LivingEntity entityliving = this.guardian.getTarget();
- if (livingentity != null) {
- this.guardian.getLookControl().setLookAt(livingentity, 90.0F, 90.0F);
+ if (entityliving != null) {
+ this.guardian.getLookControl().setLookAt(entityliving, 90.0F, 90.0F);
}
this.guardian.hasImpulse = true;
}
@Override
- @Override
public void stop() {
this.guardian.setActiveAttackTarget(0);
this.guardian.setTarget((LivingEntity) null);
@@ -485,25 +463,23 @@
}
@Override
- @Override
public boolean requiresUpdateEveryTick() {
return true;
}
@Override
- @Override
public void tick() {
- LivingEntity livingentity = this.guardian.getTarget();
+ LivingEntity entityliving = this.guardian.getTarget();
- if (livingentity != null) {
+ if (entityliving != null) {
this.guardian.getNavigation().stop();
- this.guardian.getLookControl().setLookAt(livingentity, 90.0F, 90.0F);
- if (!this.guardian.hasLineOfSight(livingentity)) {
+ this.guardian.getLookControl().setLookAt(entityliving, 90.0F, 90.0F);
+ if (!this.guardian.hasLineOfSight(entityliving)) {
this.guardian.setTarget((LivingEntity) null);
} else {
++this.attackTime;
if (this.attackTime == 0) {
- this.guardian.setActiveAttackTarget(livingentity.getId());
+ this.guardian.setActiveAttackTarget(entityliving.getId());
if (!this.guardian.isSilent()) {
this.guardian.level().broadcastEntityEvent(this.guardian, (byte) 21);
}
@@ -518,8 +494,8 @@
f += 2.0F;
}
- livingentity.hurt(this.guardian.damageSources().indirectMagic(this.guardian, this.guardian), f);
- livingentity.hurt(this.guardian.damageSources().mobAttack(this.guardian), (float) this.guardian.getAttributeValue(Attributes.ATTACK_DAMAGE));
+ entityliving.hurt(this.guardian.damageSources().indirectMagic(this.guardian, this.guardian), f);
+ entityliving.hurt(this.guardian.damageSources().mobAttack(this.guardian), (float) this.guardian.getAttributeValue(Attributes.ATTACK_DAMAGE));
this.guardian.setTarget((LivingEntity) null);
}
@@ -537,9 +513,8 @@
this.guardian = guardian;
}
- @Override
- public boolean test(@Nullable LivingEntity livingentity) {
- return (livingentity instanceof Player || livingentity instanceof Squid || livingentity instanceof Axolotl) && livingentity.distanceToSqr((Entity) this.guardian) > 9.0D;
+ public boolean test(@Nullable LivingEntity entity) {
+ return (entity instanceof Player || entity instanceof Squid || entity instanceof Axolotl) && entity.distanceToSqr((Entity) this.guardian) > 9.0D;
}
}
}
|