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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
--- a/net/minecraft/world/entity/raid/Raider.java
+++ b/net/minecraft/world/entity/raid/Raider.java
@@ -2,13 +2,13 @@
import com.google.common.collect.Lists;
import java.util.EnumSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
-import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
@@ -22,10 +22,10 @@
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.EnumMobSpawn;
import net.minecraft.world.entity.EquipmentSlot;
+import net.minecraft.world.entity.GroupDataEntity;
import net.minecraft.world.entity.LivingEntity;
-import net.minecraft.world.entity.MobSpawnType;
-import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.PathfindToRaidGoal;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
@@ -44,10 +44,11 @@
import net.minecraft.world.phys.Vec3;
public abstract class Raider extends PatrollingMonster {
+
protected static final EntityDataAccessor<Boolean> IS_CELEBRATING = SynchedEntityData.defineId(Raider.class, EntityDataSerializers.BOOLEAN);
- static final Predicate<ItemEntity> ALLOWED_ITEMS = itemEntity -> !itemEntity.hasPickUpDelay()
- && itemEntity.isAlive()
- && ItemStack.matches(itemEntity.getItem(), Raid.getLeaderBannerInstance());
+ static final Predicate<ItemEntity> ALLOWED_ITEMS = (entityitem) -> {
+ return !entityitem.hasPickUpDelay() && entityitem.isAlive() && ItemStack.matches(entityitem.getItem(), Raid.getLeaderBannerInstance());
+ };
@Nullable
protected Raid raid;
private int wave;
@@ -63,14 +64,14 @@
super.registerGoals();
this.goalSelector.addGoal(1, new Raider.ObtainRaidLeaderBannerGoal<>(this));
this.goalSelector.addGoal(3, new PathfindToRaidGoal<>(this));
- this.goalSelector.addGoal(4, new Raider.RaiderMoveThroughVillageGoal(this, 1.05F, 1));
+ this.goalSelector.addGoal(4, new Raider.RaiderMoveThroughVillageGoal(this, 1.0499999523162842D, 1));
this.goalSelector.addGoal(5, new Raider.RaiderCelebration(this));
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
- this.entityData.define(IS_CELEBRATING, false);
+ this.entityData.define(Raider.IS_CELEBRATING, false);
}
public abstract void applyRaidBuffs(int wave, boolean unusedFalse);
@@ -86,18 +87,21 @@
@Override
public void aiStep() {
if (this.level() instanceof ServerLevel && this.isAlive()) {
- Raid currentRaid = this.getCurrentRaid();
+ Raid raid = this.getCurrentRaid();
+
if (this.canJoinRaid()) {
- if (currentRaid == null) {
+ if (raid == null) {
if (this.level().getGameTime() % 20L == 0L) {
- Raid raidAt = ((ServerLevel)this.level()).getRaidAt(this.blockPosition());
- if (raidAt != null && Raids.canJoinRaid(this, raidAt)) {
- raidAt.joinRaid(raidAt.getGroupsSpawned(), this, null, true);
+ Raid raid1 = ((ServerLevel) this.level()).getRaidAt(this.blockPosition());
+
+ if (raid1 != null && Raids.canJoinRaid(this, raid1)) {
+ raid1.joinRaid(raid1.getGroupsSpawned(), this, (BlockPos) null, true);
}
}
} else {
- LivingEntity target = this.getTarget();
- if (target != null && (target.getType() == EntityType.PLAYER || target.getType() == EntityType.IRON_GOLEM)) {
+ LivingEntity entityliving = this.getTarget();
+
+ if (entityliving != null && (entityliving.getType() == EntityType.PLAYER || entityliving.getType() == EntityType.IRON_GOLEM)) {
this.noActionTime = 0;
}
}
@@ -116,45 +120,52 @@
public void die(DamageSource cause) {
if (this.level() instanceof ServerLevel) {
Entity entity = cause.getEntity();
- Raid currentRaid = this.getCurrentRaid();
- if (currentRaid != null) {
+ Raid raid = this.getCurrentRaid();
+
+ if (raid != null) {
if (this.isPatrolLeader()) {
- currentRaid.removeLeader(this.getWave());
+ raid.removeLeader(this.getWave());
}
if (entity != null && entity.getType() == EntityType.PLAYER) {
- currentRaid.addHeroOfTheVillage(entity);
+ raid.addHeroOfTheVillage(entity);
}
- currentRaid.removeFromRaid(this, false);
+ raid.removeFromRaid(this, false);
}
- if (this.isPatrolLeader() && currentRaid == null && ((ServerLevel)this.level()).getRaidAt(this.blockPosition()) == null) {
- ItemStack itemBySlot = this.getItemBySlot(EquipmentSlot.HEAD);
- Player player = null;
+ if (this.isPatrolLeader() && raid == null && ((ServerLevel) this.level()).getRaidAt(this.blockPosition()) == null) {
+ ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
+ Player entityhuman = null;
+
if (entity instanceof Player) {
- player = (Player)entity;
- } else if (entity instanceof Wolf wolf) {
- LivingEntity owner = wolf.getOwner();
- if (wolf.isTame() && owner instanceof Player) {
- player = (Player)owner;
+ entityhuman = (Player) entity;
+ } else if (entity instanceof Wolf) {
+ Wolf entitywolf = (Wolf) entity;
+ LivingEntity entityliving = entitywolf.getOwner();
+
+ if (entitywolf.isTame() && entityliving instanceof Player) {
+ entityhuman = (Player) entityliving;
}
}
- if (!itemBySlot.isEmpty() && ItemStack.matches(itemBySlot, Raid.getLeaderBannerInstance()) && player != null) {
- MobEffectInstance effect = player.getEffect(MobEffects.BAD_OMEN);
- int i = 1;
- if (effect != null) {
- i += effect.getAmplifier();
- player.removeEffectNoUpdate(MobEffects.BAD_OMEN);
+ if (!itemstack.isEmpty() && ItemStack.matches(itemstack, Raid.getLeaderBannerInstance()) && entityhuman != null) {
+ MobEffectInstance mobeffect = entityhuman.getEffect(MobEffects.BAD_OMEN);
+ byte b0 = 1;
+ int i;
+
+ if (mobeffect != null) {
+ i = b0 + mobeffect.getAmplifier();
+ entityhuman.removeEffectNoUpdate(MobEffects.BAD_OMEN);
} else {
- i--;
+ i = b0 - 1;
}
i = Mth.clamp(i, 0, 4);
- MobEffectInstance mobEffectInstance = new MobEffectInstance(MobEffects.BAD_OMEN, 120000, i, false, false, true);
+ MobEffectInstance mobeffect1 = new MobEffectInstance(MobEffects.BAD_OMEN, 120000, i, false, false, true);
+
if (!this.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_RAIDS)) {
- player.addEffect(mobEffectInstance);
+ entityhuman.addEffect(mobeffect1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); // CraftBukkit
}
}
}
@@ -190,11 +201,11 @@
}
public boolean isCelebrating() {
- return this.entityData.get(IS_CELEBRATING);
+ return (Boolean) this.entityData.get(Raider.IS_CELEBRATING);
}
public void setCelebrating(boolean celebrating) {
- this.entityData.set(IS_CELEBRATING, celebrating);
+ this.entityData.set(Raider.IS_CELEBRATING, celebrating);
}
@Override
@@ -205,6 +216,7 @@
if (this.raid != null) {
compound.putInt("RaidId", this.raid.getId());
}
+
}
@Override
@@ -214,7 +226,7 @@
this.canJoinRaid = compound.getBoolean("CanJoinRaid");
if (compound.contains("RaidId", 3)) {
if (this.level() instanceof ServerLevel) {
- this.raid = ((ServerLevel)this.level()).getRaids().get(compound.getInt("RaidId"));
+ this.raid = ((ServerLevel) this.level()).getRaids().get(compound.getInt("RaidId"));
}
if (this.raid != null) {
@@ -224,34 +236,38 @@
}
}
}
+
}
@Override
protected void pickUpItem(ItemEntity itemEntity) {
- ItemStack item = itemEntity.getItem();
+ ItemStack itemstack = itemEntity.getItem();
boolean flag = this.hasActiveRaid() && this.getCurrentRaid().getLeader(this.getWave()) != null;
- if (this.hasActiveRaid() && !flag && ItemStack.matches(item, Raid.getLeaderBannerInstance())) {
- EquipmentSlot equipmentSlot = EquipmentSlot.HEAD;
- ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
- double d = (double)this.getEquipmentDropChance(equipmentSlot);
- if (!itemBySlot.isEmpty() && (double)Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d) {
- this.spawnAtLocation(itemBySlot);
+
+ if (this.hasActiveRaid() && !flag && ItemStack.matches(itemstack, Raid.getLeaderBannerInstance())) {
+ EquipmentSlot enumitemslot = EquipmentSlot.HEAD;
+ ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
+ double d0 = (double) this.getEquipmentDropChance(enumitemslot);
+
+ if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.spawnAtLocation(itemstack1);
}
this.onItemPickup(itemEntity);
- this.setItemSlot(equipmentSlot, item);
- this.take(itemEntity, item.getCount());
+ this.setItemSlot(enumitemslot, itemstack);
+ this.take(itemEntity, itemstack.getCount());
itemEntity.discard();
this.getCurrentRaid().setLeader(this.getWave(), this);
this.setPatrolLeader(true);
} else {
super.pickUpItem(itemEntity);
}
+
}
@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
- return this.getCurrentRaid() == null && super.removeWhenFarAway(distanceToClosestPlayer);
+ return this.getCurrentRaid() == null ? super.removeWhenFarAway(distanceToClosestPlayer) : false;
}
@Override
@@ -278,143 +294,176 @@
@Nullable
@Override
- public SpawnGroupData finalizeSpawn(
- ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType reason, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag dataTag
- ) {
- this.setCanJoinRaid(this.getType() != EntityType.WITCH || reason != MobSpawnType.NATURAL);
+ public GroupDataEntity finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EnumMobSpawn reason, @Nullable GroupDataEntity spawnData, @Nullable CompoundTag dataTag) {
+ this.setCanJoinRaid(this.getType() != EntityType.WITCH || reason != EnumMobSpawn.NATURAL);
return super.finalizeSpawn(level, difficulty, reason, spawnData, dataTag);
}
public abstract SoundEvent getCelebrateSound();
- protected class HoldGroundAttackGoal extends Goal {
- private final Raider mob;
- private final float hostileRadiusSqr;
- public final TargetingConditions shoutTargeting = TargetingConditions.forNonCombat().range(8.0).ignoreLineOfSight().ignoreInvisibilityTesting();
+ public class ObtainRaidLeaderBannerGoal<T extends Raider> extends Goal {
- public HoldGroundAttackGoal(AbstractIllager mob, float hostileRadiusSquare) {
- this.mob = mob;
- this.hostileRadiusSqr = hostileRadiusSquare * hostileRadiusSquare;
- this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
+ private final T mob;
+
+ public ObtainRaidLeaderBannerGoal(T entityraider) { // CraftBukkit - decompile error
+ this.mob = entityraider;
+ this.setFlags(EnumSet.of(Goal.Type.MOVE));
}
@Override
public boolean canUse() {
- LivingEntity lastHurtByMob = this.mob.getLastHurtByMob();
- return this.mob.getCurrentRaid() == null
- && this.mob.isPatrolling()
- && this.mob.getTarget() != null
- && !this.mob.isAggressive()
- && (lastHurtByMob == null || lastHurtByMob.getType() != EntityType.PLAYER);
- }
+ Raid raid = this.mob.getCurrentRaid();
- @Override
- public void start() {
- super.start();
- this.mob.getNavigation().stop();
+ if (this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && this.mob.canBeLeader() && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), Raid.getLeaderBannerInstance())) {
+ Raider entityraider = raid.getLeader(this.mob.getWave());
- for (Raider raider : this.mob
- .level()
- .getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0, 8.0, 8.0))) {
- raider.setTarget(this.mob.getTarget());
- }
- }
+ if (entityraider == null || !entityraider.isAlive()) {
+ List<ItemEntity> list = this.mob.level().getEntitiesOfClass(ItemEntity.class, this.mob.getBoundingBox().inflate(16.0D, 8.0D, 16.0D), Raider.ALLOWED_ITEMS);
- @Override
- public void stop() {
- super.stop();
- LivingEntity target = this.mob.getTarget();
- if (target != null) {
- for (Raider raider : this.mob
- .level()
- .getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0, 8.0, 8.0))) {
- raider.setTarget(target);
- raider.setAggressive(true);
+ if (!list.isEmpty()) {
+ return this.mob.getNavigation().moveTo((Entity) list.get(0), 1.149999976158142D);
+ }
}
- this.mob.setAggressive(true);
+ return false;
+ } else {
+ return false;
}
}
@Override
- public boolean requiresUpdateEveryTick() {
- return true;
- }
-
- @Override
public void tick() {
- LivingEntity target = this.mob.getTarget();
- if (target != null) {
- if (this.mob.distanceToSqr(target) > (double)this.hostileRadiusSqr) {
- this.mob.getLookControl().setLookAt(target, 30.0F, 30.0F);
- if (this.mob.random.nextInt(50) == 0) {
- this.mob.playAmbientSound();
- }
- } else {
- this.mob.setAggressive(true);
- }
+ if (this.mob.getNavigation().getTargetPos().closerToCenterThan(this.mob.position(), 1.414D)) {
+ List<ItemEntity> list = this.mob.level().getEntitiesOfClass(ItemEntity.class, this.mob.getBoundingBox().inflate(4.0D, 4.0D, 4.0D), Raider.ALLOWED_ITEMS);
- super.tick();
+ if (!list.isEmpty()) {
+ this.mob.pickUpItem((ItemEntity) list.get(0));
+ }
}
+
}
}
- public class ObtainRaidLeaderBannerGoal<T extends Raider> extends Goal {
- private final T mob;
+ private static class RaiderMoveThroughVillageGoal extends Goal {
- public ObtainRaidLeaderBannerGoal(T mob) {
- this.mob = mob;
- this.setFlags(EnumSet.of(Goal.Flag.MOVE));
+ private final Raider raider;
+ private final double speedModifier;
+ private BlockPos poiPos;
+ private final List<BlockPos> visited = Lists.newArrayList();
+ private final int distanceToPoi;
+ private boolean stuck;
+
+ public RaiderMoveThroughVillageGoal(Raider raider, double speedModifier, int i) {
+ this.raider = raider;
+ this.speedModifier = speedModifier;
+ this.distanceToPoi = i;
+ this.setFlags(EnumSet.of(Goal.Type.MOVE));
}
@Override
public boolean canUse() {
- Raid currentRaid = this.mob.getCurrentRaid();
- if (this.mob.hasActiveRaid()
- && !this.mob.getCurrentRaid().isOver()
- && this.mob.canBeLeader()
- && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), Raid.getLeaderBannerInstance())) {
- Raider leader = currentRaid.getLeader(this.mob.getWave());
- if (leader == null || !leader.isAlive()) {
- List<ItemEntity> entitiesOfClass = this.mob
- .level()
- .getEntitiesOfClass(ItemEntity.class, this.mob.getBoundingBox().inflate(16.0, 8.0, 16.0), Raider.ALLOWED_ITEMS);
- if (!entitiesOfClass.isEmpty()) {
- return this.mob.getNavigation().moveTo(entitiesOfClass.get(0), 1.15F);
- }
- }
+ this.updateVisited();
+ return this.isValidRaid() && this.hasSuitablePoi() && this.raider.getTarget() == null;
+ }
+ private boolean isValidRaid() {
+ return this.raider.hasActiveRaid() && !this.raider.getCurrentRaid().isOver();
+ }
+
+ private boolean hasSuitablePoi() {
+ ServerLevel worldserver = (ServerLevel) this.raider.level();
+ BlockPos blockposition = this.raider.blockPosition();
+ Optional<BlockPos> optional = worldserver.getPoiManager().getRandom((holder) -> {
+ return holder.is(PoiTypes.HOME);
+ }, this::hasNotVisited, PoiManager.Occupancy.ANY, blockposition, 48, this.raider.random);
+
+ if (optional.isEmpty()) {
return false;
} else {
- return false;
+ this.poiPos = ((BlockPos) optional.get()).immutable();
+ return true;
}
}
@Override
+ public boolean canContinueToUse() {
+ return this.raider.getNavigation().isDone() ? false : this.raider.getTarget() == null && !this.poiPos.closerToCenterThan(this.raider.position(), (double) (this.raider.getBbWidth() + (float) this.distanceToPoi)) && !this.stuck;
+ }
+
+ @Override
+ public void stop() {
+ if (this.poiPos.closerToCenterThan(this.raider.position(), (double) this.distanceToPoi)) {
+ this.visited.add(this.poiPos);
+ }
+
+ }
+
+ @Override
+ public void start() {
+ super.start();
+ this.raider.setNoActionTime(0);
+ this.raider.getNavigation().moveTo((double) this.poiPos.getX(), (double) this.poiPos.getY(), (double) this.poiPos.getZ(), this.speedModifier);
+ this.stuck = false;
+ }
+
+ @Override
public void tick() {
- if (this.mob.getNavigation().getTargetPos().closerToCenterThan(this.mob.position(), 1.414)) {
- List<ItemEntity> entitiesOfClass = this.mob
- .level()
- .getEntitiesOfClass(ItemEntity.class, this.mob.getBoundingBox().inflate(4.0, 4.0, 4.0), Raider.ALLOWED_ITEMS);
- if (!entitiesOfClass.isEmpty()) {
- this.mob.pickUpItem(entitiesOfClass.get(0));
+ if (this.raider.getNavigation().isDone()) {
+ Vec3 vec3d = Vec3.atBottomCenterOf(this.poiPos);
+ Vec3 vec3d1 = DefaultRandomPos.getPosTowards(this.raider, 16, 7, vec3d, 0.3141592741012573D);
+
+ if (vec3d1 == null) {
+ vec3d1 = DefaultRandomPos.getPosTowards(this.raider, 8, 7, vec3d, 1.5707963705062866D);
}
+
+ if (vec3d1 == null) {
+ this.stuck = true;
+ return;
+ }
+
+ this.raider.getNavigation().moveTo(vec3d1.x, vec3d1.y, vec3d1.z, this.speedModifier);
}
+
}
+
+ private boolean hasNotVisited(BlockPos pos) {
+ Iterator iterator = this.visited.iterator();
+
+ BlockPos blockposition1;
+
+ do {
+ if (!iterator.hasNext()) {
+ return true;
+ }
+
+ blockposition1 = (BlockPos) iterator.next();
+ } while (!Objects.equals(pos, blockposition1));
+
+ return false;
+ }
+
+ private void updateVisited() {
+ if (this.visited.size() > 2) {
+ this.visited.remove(0);
+ }
+
+ }
}
public class RaiderCelebration extends Goal {
+
private final Raider mob;
- RaiderCelebration(Raider mob) {
- this.mob = mob;
- this.setFlags(EnumSet.of(Goal.Flag.MOVE));
+ RaiderCelebration(Raider entityraider) {
+ this.mob = entityraider;
+ this.setFlags(EnumSet.of(Goal.Type.MOVE));
}
@Override
public boolean canUse() {
- Raid currentRaid = this.mob.getCurrentRaid();
- return this.mob.isAlive() && this.mob.getTarget() == null && currentRaid != null && currentRaid.isLoss();
+ Raid raid = this.mob.getCurrentRaid();
+
+ return this.mob.isAlive() && this.mob.getTarget() == null && raid != null && raid.isLoss();
}
@Override
@@ -443,99 +492,82 @@
}
}
- static class RaiderMoveThroughVillageGoal extends Goal {
- private final Raider raider;
- private final double speedModifier;
- private BlockPos poiPos;
- private final List<BlockPos> visited = Lists.newArrayList();
- private final int distanceToPoi;
- private boolean stuck;
+ protected class HoldGroundAttackGoal extends Goal {
- public RaiderMoveThroughVillageGoal(Raider raider, double speedModifier, int distanceToPoi) {
- this.raider = raider;
- this.speedModifier = speedModifier;
- this.distanceToPoi = distanceToPoi;
- this.setFlags(EnumSet.of(Goal.Flag.MOVE));
+ private final Raider mob;
+ private final float hostileRadiusSqr;
+ public final TargetingConditions shoutTargeting = TargetingConditions.forNonCombat().range(8.0D).ignoreLineOfSight().ignoreInvisibilityTesting();
+
+ public HoldGroundAttackGoal(AbstractIllager entityillagerabstract, float f) {
+ this.mob = entityillagerabstract;
+ this.hostileRadiusSqr = f * f;
+ this.setFlags(EnumSet.of(Goal.Type.MOVE, Goal.Type.LOOK));
}
@Override
public boolean canUse() {
- this.updateVisited();
- return this.isValidRaid() && this.hasSuitablePoi() && this.raider.getTarget() == null;
- }
+ LivingEntity entityliving = this.mob.getLastHurtByMob();
- private boolean isValidRaid() {
- return this.raider.hasActiveRaid() && !this.raider.getCurrentRaid().isOver();
+ return this.mob.getCurrentRaid() == null && this.mob.isPatrolling() && this.mob.getTarget() != null && !this.mob.isAggressive() && (entityliving == null || entityliving.getType() != EntityType.PLAYER);
}
- private boolean hasSuitablePoi() {
- ServerLevel serverLevel = (ServerLevel)this.raider.level();
- BlockPos blockPos = this.raider.blockPosition();
- Optional<BlockPos> random = serverLevel.getPoiManager()
- .getRandom(holder -> holder.is(PoiTypes.HOME), this::hasNotVisited, PoiManager.Occupancy.ANY, blockPos, 48, this.raider.random);
- if (random.isEmpty()) {
- return false;
- } else {
- this.poiPos = random.get().immutable();
- return true;
+ @Override
+ public void start() {
+ super.start();
+ this.mob.getNavigation().stop();
+ List<Raider> list = this.mob.level().getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0D, 8.0D, 8.0D));
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ Raider entityraider = (Raider) iterator.next();
+
+ entityraider.setTarget(this.mob.getTarget(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
}
- }
- @Override
- public boolean canContinueToUse() {
- return !this.raider.getNavigation().isDone()
- && this.raider.getTarget() == null
- && !this.poiPos.closerToCenterThan(this.raider.position(), (double)(this.raider.getBbWidth() + (float)this.distanceToPoi))
- && !this.stuck;
}
@Override
public void stop() {
- if (this.poiPos.closerToCenterThan(this.raider.position(), (double)this.distanceToPoi)) {
- this.visited.add(this.poiPos);
+ super.stop();
+ LivingEntity entityliving = this.mob.getTarget();
+
+ if (entityliving != null) {
+ List<Raider> list = this.mob.level().getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0D, 8.0D, 8.0D));
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ Raider entityraider = (Raider) iterator.next();
+
+ entityraider.setTarget(this.mob.getTarget(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
+ entityraider.setAggressive(true);
+ }
+
+ this.mob.setAggressive(true);
}
+
}
@Override
- public void start() {
- super.start();
- this.raider.setNoActionTime(0);
- this.raider.getNavigation().moveTo((double)this.poiPos.getX(), (double)this.poiPos.getY(), (double)this.poiPos.getZ(), this.speedModifier);
- this.stuck = false;
+ public boolean requiresUpdateEveryTick() {
+ return true;
}
@Override
public void tick() {
- if (this.raider.getNavigation().isDone()) {
- Vec3 vec3 = Vec3.atBottomCenterOf(this.poiPos);
- Vec3 posTowards = DefaultRandomPos.getPosTowards(this.raider, 16, 7, vec3, (float) (Math.PI / 10));
- if (posTowards == null) {
- posTowards = DefaultRandomPos.getPosTowards(this.raider, 8, 7, vec3, (float) (Math.PI / 2));
- }
+ LivingEntity entityliving = this.mob.getTarget();
- if (posTowards == null) {
- this.stuck = true;
- return;
+ if (entityliving != null) {
+ if (this.mob.distanceToSqr((Entity) entityliving) > (double) this.hostileRadiusSqr) {
+ this.mob.getLookControl().setLookAt(entityliving, 30.0F, 30.0F);
+ if (this.mob.random.nextInt(50) == 0) {
+ this.mob.playAmbientSound();
+ }
+ } else {
+ this.mob.setAggressive(true);
}
- this.raider.getNavigation().moveTo(posTowards.x, posTowards.y, posTowards.z, this.speedModifier);
+ super.tick();
}
}
-
- private boolean hasNotVisited(BlockPos pos) {
- for (BlockPos blockPos : this.visited) {
- if (Objects.equals(pos, blockPos)) {
- return false;
- }
- }
-
- return true;
- }
-
- private void updateVisited() {
- if (this.visited.size() > 2) {
- this.visited.remove(0);
- }
- }
}
}
|