/
0006-Ridables.patch
6368 lines (6074 loc) · 285 KB
/
0006-Ridables.patch
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Sun, 5 Jul 2020 22:19:49 -0500
Subject: [PATCH] Ridables
diff --git a/src/main/java/net/minecraft/core/BlockPos.java b/src/main/java/net/minecraft/core/BlockPos.java
index 14610e6144ec144ebbec6fb0945c67bb0ea86795..6833eb5dc7aa64bef1b3b38de5e282bdf1e10ec7 100644
--- a/src/main/java/net/minecraft/core/BlockPos.java
+++ b/src/main/java/net/minecraft/core/BlockPos.java
@@ -41,6 +41,12 @@ public class BlockPos extends Vec3i {
private static final int X_OFFSET = 38;
// Paper end
+ // Purpur start
+ public BlockPos(net.minecraft.world.entity.Entity entity) {
+ super(entity.getX(), entity.getY(), entity.getZ());
+ }
+ // Purpur end
+
public BlockPos(int x, int y, int z) {
super(x, y, z);
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 61d3ed736314d68322585cb6266a47fd17a4a4b4..044b1d5d17fe4554ceefbdd893ef23dba4b999d9 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1589,6 +1589,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
ServerLevel worldserver = (ServerLevel) iterator.next();
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
+ worldserver.hasRidableMoveEvent = org.purpurmc.purpur.event.entity.RidableMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Purpur
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig.disableHopperMoveEvents || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper
this.profiler.push(() -> {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 8cdacd7ed9a26e6757eeff89545fde21ddb80fd2..cd01b2f06b0dd34c3261d84beead96bba76cf825 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -211,6 +211,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
public final UUID uuid;
public boolean hasPhysicsEvent = true; // Paper
public boolean hasEntityMoveEvent = false; // Paper
+ public boolean hasRidableMoveEvent = false; // Purpur
public static Throwable getAddToWorldStackTrace(Entity entity) {
return new Throwable(entity + " Added to world at " + new java.util.Date());
}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index c516ad43cac2419bcf63e11eaa183785b462de5c..618595add09eef5381307ba2fe154adfc97b2a0e 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -662,6 +662,15 @@ public class ServerPlayer extends Player {
this.trackStartFallingPosition();
this.trackEnteredOrExitedLavaOnVehicle();
this.advancements.flushDirty(this);
+
+ // Purpur start
+ if (this.level.purpurConfig.useNightVisionWhenRiding && this.getVehicle() != null && this.getVehicle().getRider() == this && this.level.getGameTime() % 100 == 0) { // 5 seconds
+ MobEffectInstance nightVision = this.getEffect(MobEffects.NIGHT_VISION);
+ if (nightVision == null || nightVision.getDuration() <= 300) { // 15 seconds
+ this.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 400, 0)); // 20 seconds
+ }
+ }
+ // Purpur end
}
public void doTick() {
@@ -2458,4 +2467,6 @@ public class ServerPlayer extends Player {
return (CraftPlayer) super.getBukkitEntity();
}
// CraftBukkit end
+
+
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 38de81f8696ed658d002427d002f22b28e3a6122..39bf75a7ba276f25e39573f084786dd5c046f51c 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2456,6 +2456,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event);
+ player.processClick(enumhand); // Purpur
+
// Entity in bucket - SPIGOT-4048 and SPIGOT-6859
if ((entity instanceof Bucketable && entity instanceof LivingEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null || ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem() != origItem)) {
ServerGamePacketListenerImpl.this.send(new ClientboundAddMobPacket((LivingEntity) entity));
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 452d56e6e0c6682f0d55697b3e9e94d53e186f92..ab905ab075fd6966a95db45fc183d630bbf414ec 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -297,7 +297,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
private final Set<String> tags;
private final double[] pistonDeltas;
private long pistonDeltasGameTime;
- private EntityDimensions dimensions;
+ protected EntityDimensions dimensions; // Purpur - private -> protected
private float eyeHeight;
public boolean isInPowderSnow;
public boolean wasInPowderSnow;
@@ -2664,6 +2664,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
this.passengers = ImmutableList.copyOf(list);
}
+ // Purpur start
+ if (isRidable() && this.passengers.get(0) == entity && entity instanceof Player player) {
+ onMount(player);
+ this.rider = player;
+ }
+ // Purpur end
}
return true; // CraftBukkit
}
@@ -2704,6 +2710,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
return false;
}
// Spigot end
+
+ // Purpur start
+ if (this.rider != null && this.passengers.get(0) == this.rider) {
+ onDismount(this.rider);
+ this.rider = null;
+ }
+ // Purpur end
+
if (this.passengers.size() == 1 && this.passengers.get(0) == entity) {
this.passengers = ImmutableList.of();
} else {
@@ -4389,4 +4403,45 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
return ((ServerChunkCache) level.getChunkSource()).isPositionTicking(this);
}
// Paper end
+
+ // Purpur start
+ @Nullable
+ private Player rider = null;
+
+ @Nullable
+ public Player getRider() {
+ return rider;
+ }
+
+ public boolean isRidable() {
+ return false;
+ }
+
+ public boolean isControllable() {
+ return true;
+ }
+
+ public void onMount(Player rider) {
+ if (this instanceof Mob) {
+ ((Mob) this).setTarget(null, null, false);
+ ((Mob) this).getNavigation().stop();
+ }
+ rider.setJumping(false); // fixes jump on mount
+ }
+
+ public void onDismount(Player player) {
+ }
+
+ public boolean onSpacebar() {
+ return false;
+ }
+
+ public boolean onClick(InteractionHand hand) {
+ return false;
+ }
+
+ public boolean processClick(InteractionHand hand) {
+ return false;
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/world/entity/GlowSquid.java b/src/main/java/net/minecraft/world/entity/GlowSquid.java
index 645c1dc9bd09b135a641759c76ce8d957b9bd488..912767ed261e44c0192c5a07e2c2026110988816 100644
--- a/src/main/java/net/minecraft/world/entity/GlowSquid.java
+++ b/src/main/java/net/minecraft/world/entity/GlowSquid.java
@@ -23,6 +23,23 @@ public class GlowSquid extends Squid {
super(type, world);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.glowSquidRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return true;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.glowSquidControllable;
+ }
+ // Purpur end
+
@Override
protected ParticleOptions getInkParticle() {
return ParticleTypes.GLOW_SQUID_INK;
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a6681690e1e556440320c492bf2a8e617008baa1..67912e15aa060261b1ec2c13abcab309d6af8813 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -216,9 +216,9 @@ public abstract class LivingEntity extends Entity {
protected int deathScore;
public float lastHurt;
public boolean jumping;
- public float xxa;
- public float yya;
- public float zza;
+ public float xxa; public float getStrafeMot() { return xxa; } public void setStrafeMot(float strafe) { xxa = strafe; } // Purpur - OBFHELPER
+ public float yya; public float getVerticalMot() { return yya; } public void setVerticalMot(float vertical) { yya = vertical; } // Purpur - OBFHELPER
+ public float zza; public float getForwardMot() { return zza; } public void setForwardMot(float forward) { zza = forward; } // Purpur - OBFHELPER
protected int lerpSteps;
protected double lerpX;
protected double lerpY;
@@ -282,7 +282,7 @@ public abstract class LivingEntity extends Entity {
this.effectsDirty = true;
this.useItem = ItemStack.EMPTY;
this.lastClimbablePos = Optional.empty();
- this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type));
+ this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type), this); // Purpur
this.craftAttributes = new CraftAttributeMap(this.attributes); // CraftBukkit
// CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
this.entityData.set(LivingEntity.DATA_HEALTH_ID, (float) this.getAttribute(Attributes.MAX_HEALTH).getValue());
@@ -333,6 +333,7 @@ public abstract class LivingEntity extends Entity {
public static AttributeSupplier.Builder createLivingAttributes() {
return AttributeSupplier.builder().add(Attributes.MAX_HEALTH).add(Attributes.KNOCKBACK_RESISTANCE).add(Attributes.MOVEMENT_SPEED).add(Attributes.ARMOR).add(Attributes.ARMOR_TOUGHNESS);
}
+ public boolean shouldSendAttribute(Attribute attribute) { return true; } // Purpur
@Override
protected void checkFallDamage(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
@@ -2604,7 +2605,7 @@ public abstract class LivingEntity extends Entity {
}
protected long lastJumpTime = 0L; // Paper
- protected void jumpFromGround() {
+ public void jumpFromGround() { // Purpur - protected -> public
double d0 = (double) this.getJumpPower() + this.getJumpBoostPower();
Vec3 vec3d = this.getDeltaMovement();
// Paper start
@@ -3346,8 +3347,10 @@ public abstract class LivingEntity extends Entity {
this.pushEntities();
this.level.getProfiler().pop();
// Paper start
- if (((ServerLevel) this.level).hasEntityMoveEvent && !(this instanceof net.minecraft.world.entity.player.Player)) {
- if (this.xo != getX() || this.yo != this.getY() || this.zo != this.getZ() || this.yRotO != this.getYRot() || this.xRotO != this.getXRot()) {
+ // Purpur start
+ if (this.xo != this.getX() || this.yo != this.getY() || this.zo != this.getZ() || this.yRotO != this.getYRot() || this.xRotO != this.getXRot()) {
+ if (((ServerLevel) this.level).hasEntityMoveEvent && !(this instanceof net.minecraft.world.entity.player.Player)) {
+ // Purpur end
Location from = new Location(this.level.getWorld(), this.xo, this.yo, this.zo, this.yRotO, this.xRotO);
Location to = new Location (this.level.getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
io.papermc.paper.event.entity.EntityMoveEvent event = new io.papermc.paper.event.entity.EntityMoveEvent(this.getBukkitLivingEntity(), from, to.clone());
@@ -3357,6 +3360,21 @@ public abstract class LivingEntity extends Entity {
absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
+ // Purpur start
+ if (getRider() != null) {
+ getRider().resetLastActionTime();
+ if (((ServerLevel) level).hasRidableMoveEvent && this instanceof Mob) {
+ Location from = new Location(level.getWorld(), xo, yo, zo, this.yRotO, this.xRotO);
+ Location to = new Location(level.getWorld(), getX(), getY(), getZ(), this.getYRot(), this.getXRot());
+ org.purpurmc.purpur.event.entity.RidableMoveEvent event = new org.purpurmc.purpur.event.entity.RidableMoveEvent((org.bukkit.entity.Mob) getBukkitLivingEntity(), (Player) getRider().getBukkitEntity(), from, to.clone());
+ if (!event.callEvent()) {
+ absMoveTo(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
+ } else if (!to.equals(event.getTo())) {
+ absMoveTo(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch());
+ }
+ }
+ }
+ // Purpur end
}
// Paper end
if (!this.level.isClientSide && this.isSensitiveToWater() && this.isInWaterRainOrBubble()) {
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 35ff7abd8251b0af6c23fbb63804db632ec5b85d..dcf788de63b819abc668cc6deba974af26a41f2e 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -141,8 +141,8 @@ public abstract class Mob extends LivingEntity {
this.restrictRadius = -1.0F;
this.goalSelector = new GoalSelector(world.getProfilerSupplier());
this.targetSelector = new GoalSelector(world.getProfilerSupplier());
- this.lookControl = new LookControl(this);
- this.moveControl = new MoveControl(this);
+ this.lookControl = new org.purpurmc.purpur.controller.LookControllerWASD(this); // Purpur
+ this.moveControl = new org.purpurmc.purpur.controller.MoveControllerWASD(this); // Purpur
this.jumpControl = new JumpControl(this);
this.bodyRotationControl = this.createBodyControl();
this.navigation = this.createNavigation(world);
@@ -1306,7 +1306,7 @@ public abstract class Mob extends LivingEntity {
protected void onOffspringSpawnedFromEgg(Player player, Mob child) {}
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
- return InteractionResult.PASS;
+ return tryRide(player, hand); // Purpur
}
public boolean isWithinRestriction() {
@@ -1667,4 +1667,52 @@ public abstract class Mob extends LivingEntity {
return itemmonsteregg == null ? null : new ItemStack(itemmonsteregg);
}
+
+ // Purpur start
+ public double getMaxY() {
+ return level.getHeight();
+ }
+
+ public InteractionResult tryRide(Player player, InteractionHand hand) {
+ if (!isRidable()) {
+ return InteractionResult.PASS;
+ }
+ if (hand != InteractionHand.MAIN_HAND) {
+ return InteractionResult.PASS;
+ }
+ if (player.isShiftKeyDown()) {
+ return InteractionResult.PASS;
+ }
+ if (!player.getItemInHand(hand).isEmpty()) {
+ return InteractionResult.PASS;
+ }
+ if (!passengers.isEmpty() || player.isPassenger()) {
+ return InteractionResult.PASS;
+ }
+ if (this instanceof TamableAnimal tamable) {
+ if (tamable.isTame() && !tamable.isOwnedBy(player)) {
+ return InteractionResult.PASS;
+ }
+ if (!tamable.isTame() && !level.purpurConfig.untamedTamablesAreRidable) {
+ return InteractionResult.PASS;
+ }
+ }
+ if (this instanceof AgeableMob ageable) {
+ if (ageable.isBaby() && !level.purpurConfig.babiesAreRidable) {
+ return InteractionResult.PASS;
+ }
+ }
+ if (!player.getBukkitEntity().hasPermission("allow.ride." + getType().id)) {
+ player.sendMessage(org.purpurmc.purpur.PurpurConfig.cannotRideMob);
+ return InteractionResult.PASS;
+ }
+ player.setYRot(this.getYRot());
+ player.setXRot(this.getXRot());
+ if (player.startRiding(this)) {
+ return InteractionResult.SUCCESS;
+ } else {
+ return InteractionResult.PASS;
+ }
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
index 52ddf38d5a1894a248e142c6b9ebaff5cc921e5b..4fa1e8dd7ebc839527eed7f7db5af2c56c38f230 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
@@ -23,14 +23,21 @@ public class AttributeMap {
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
private final AttributeSupplier supplier;
private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Pufferfish
+ private final net.minecraft.world.entity.LivingEntity entity; // Purpur
public AttributeMap(AttributeSupplier defaultAttributes) {
+ // Purpur start
+ this(defaultAttributes, null);
+ }
+ public AttributeMap(AttributeSupplier defaultAttributes, net.minecraft.world.entity.LivingEntity entity) {
+ this.entity = entity;
+ // Purpur end
this.supplier = defaultAttributes;
this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute); // Pufferfish
}
private void onAttributeModified(AttributeInstance instance) {
- if (instance.getAttribute().isClientSyncable()) {
+ if (instance.getAttribute().isClientSyncable() && (entity == null || entity.shouldSendAttribute(instance.getAttribute()))) { // Purpur
this.dirtyAttributes.add(instance);
}
@@ -42,7 +49,7 @@ public class AttributeMap {
public Collection<AttributeInstance> getSyncableAttributes() {
return this.attributes.values().stream().filter((attribute) -> {
- return attribute.getAttribute().isClientSyncable();
+ return attribute.getAttribute().isClientSyncable() && (entity == null || entity.shouldSendAttribute(attribute.getAttribute())); // Purpur
}).collect(Collectors.toList());
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java b/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java
index 6a4a0ba0f8f96dd8566b3164bbbceeaa37b548f1..65d0b0e7856eaa61e26b0af750bb7959f5a225f7 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java
@@ -74,7 +74,86 @@ import org.apache.logging.log4j.Logger;
public class DefaultAttributes {
private static final Logger LOGGER = LogManager.getLogger();
- private static final Map<EntityType<? extends LivingEntity>, AttributeSupplier> SUPPLIERS = ImmutableMap.<EntityType<? extends LivingEntity>, AttributeSupplier>builder().put(EntityType.ARMOR_STAND, LivingEntity.createLivingAttributes().build()).put(EntityType.AXOLOTL, Axolotl.createAttributes().build()).put(EntityType.BAT, Bat.createAttributes().build()).put(EntityType.BEE, Bee.createAttributes().build()).put(EntityType.BLAZE, Blaze.createAttributes().build()).put(EntityType.CAT, Cat.createAttributes().build()).put(EntityType.CAVE_SPIDER, CaveSpider.createCaveSpider().build()).put(EntityType.CHICKEN, Chicken.createAttributes().build()).put(EntityType.COD, AbstractFish.createAttributes().build()).put(EntityType.COW, Cow.createAttributes().build()).put(EntityType.CREEPER, Creeper.createAttributes().build()).put(EntityType.DOLPHIN, Dolphin.createAttributes().build()).put(EntityType.DONKEY, AbstractChestedHorse.createBaseChestedHorseAttributes().build()).put(EntityType.DROWNED, Zombie.createAttributes().build()).put(EntityType.ELDER_GUARDIAN, ElderGuardian.createAttributes().build()).put(EntityType.ENDERMAN, EnderMan.createAttributes().build()).put(EntityType.ENDERMITE, Endermite.createAttributes().build()).put(EntityType.ENDER_DRAGON, EnderDragon.createAttributes().build()).put(EntityType.EVOKER, Evoker.createAttributes().build()).put(EntityType.FOX, Fox.createAttributes().build()).put(EntityType.GHAST, Ghast.createAttributes().build()).put(EntityType.GIANT, Giant.createAttributes().build()).put(EntityType.GLOW_SQUID, GlowSquid.createAttributes().build()).put(EntityType.GOAT, Goat.createAttributes().build()).put(EntityType.GUARDIAN, Guardian.createAttributes().build()).put(EntityType.HOGLIN, Hoglin.createAttributes().build()).put(EntityType.HORSE, AbstractHorse.createBaseHorseAttributes().build()).put(EntityType.HUSK, Zombie.createAttributes().build()).put(EntityType.ILLUSIONER, Illusioner.createAttributes().build()).put(EntityType.IRON_GOLEM, IronGolem.createAttributes().build()).put(EntityType.LLAMA, Llama.createAttributes().build()).put(EntityType.MAGMA_CUBE, MagmaCube.createAttributes().build()).put(EntityType.MOOSHROOM, Cow.createAttributes().build()).put(EntityType.MULE, AbstractChestedHorse.createBaseChestedHorseAttributes().build()).put(EntityType.OCELOT, Ocelot.createAttributes().build()).put(EntityType.PANDA, Panda.createAttributes().build()).put(EntityType.PARROT, Parrot.createAttributes().build()).put(EntityType.PHANTOM, Monster.createMonsterAttributes().build()).put(EntityType.PIG, Pig.createAttributes().build()).put(EntityType.PIGLIN, Piglin.createAttributes().build()).put(EntityType.PIGLIN_BRUTE, PiglinBrute.createAttributes().build()).put(EntityType.PILLAGER, Pillager.createAttributes().build()).put(EntityType.PLAYER, Player.createAttributes().build()).put(EntityType.POLAR_BEAR, PolarBear.createAttributes().build()).put(EntityType.PUFFERFISH, AbstractFish.createAttributes().build()).put(EntityType.RABBIT, Rabbit.createAttributes().build()).put(EntityType.RAVAGER, Ravager.createAttributes().build()).put(EntityType.SALMON, AbstractFish.createAttributes().build()).put(EntityType.SHEEP, Sheep.createAttributes().build()).put(EntityType.SHULKER, Shulker.createAttributes().build()).put(EntityType.SILVERFISH, Silverfish.createAttributes().build()).put(EntityType.SKELETON, AbstractSkeleton.createAttributes().build()).put(EntityType.SKELETON_HORSE, SkeletonHorse.createAttributes().build()).put(EntityType.SLIME, Monster.createMonsterAttributes().build()).put(EntityType.SNOW_GOLEM, SnowGolem.createAttributes().build()).put(EntityType.SPIDER, Spider.createAttributes().build()).put(EntityType.SQUID, Squid.createAttributes().build()).put(EntityType.STRAY, AbstractSkeleton.createAttributes().build()).put(EntityType.STRIDER, Strider.createAttributes().build()).put(EntityType.TRADER_LLAMA, Llama.createAttributes().build()).put(EntityType.TROPICAL_FISH, AbstractFish.createAttributes().build()).put(EntityType.TURTLE, Turtle.createAttributes().build()).put(EntityType.VEX, Vex.createAttributes().build()).put(EntityType.VILLAGER, Villager.createAttributes().build()).put(EntityType.VINDICATOR, Vindicator.createAttributes().build()).put(EntityType.WANDERING_TRADER, Mob.createMobAttributes().build()).put(EntityType.WITCH, Witch.createAttributes().build()).put(EntityType.WITHER, WitherBoss.createAttributes().build()).put(EntityType.WITHER_SKELETON, AbstractSkeleton.createAttributes().build()).put(EntityType.WOLF, Wolf.createAttributes().build()).put(EntityType.ZOGLIN, Zoglin.createAttributes().build()).put(EntityType.ZOMBIE, Zombie.createAttributes().build()).put(EntityType.ZOMBIE_HORSE, ZombieHorse.createAttributes().build()).put(EntityType.ZOMBIE_VILLAGER, Zombie.createAttributes().build()).put(EntityType.ZOMBIFIED_PIGLIN, ZombifiedPiglin.createAttributes().build()).build();
+
+ // Purpur start
+ private static final Map<EntityType<? extends LivingEntity>, AttributeSupplier> SUPPLIERS = ImmutableMap.<EntityType<? extends LivingEntity>, AttributeSupplier>builder()
+ .put(EntityType.ARMOR_STAND, LivingEntity.createLivingAttributes().build())
+ .put(EntityType.AXOLOTL, Axolotl.createAttributes().build())
+ .put(EntityType.BAT, Bat.createAttributes().build())
+ .put(EntityType.BEE, Bee.createAttributes().build())
+ .put(EntityType.BLAZE, Blaze.createAttributes().build())
+ .put(EntityType.CAT, Cat.createAttributes().build())
+ .put(EntityType.CAVE_SPIDER, CaveSpider.createCaveSpider().build())
+ .put(EntityType.CHICKEN, Chicken.createAttributes().build())
+ .put(EntityType.COD, AbstractFish.createAttributes().build())
+ .put(EntityType.COW, Cow.createAttributes().build())
+ .put(EntityType.CREEPER, Creeper.createAttributes().build())
+ .put(EntityType.DOLPHIN, Dolphin.createAttributes().build())
+ .put(EntityType.DONKEY, AbstractChestedHorse.createBaseChestedHorseAttributes().build())
+ .put(EntityType.DROWNED, Zombie.createAttributes().build())
+ .put(EntityType.ELDER_GUARDIAN, ElderGuardian.createAttributes().build())
+ .put(EntityType.ENDERMAN, EnderMan.createAttributes().build())
+ .put(EntityType.ENDERMITE, Endermite.createAttributes().build())
+ .put(EntityType.ENDER_DRAGON, EnderDragon.createAttributes().build())
+ .put(EntityType.EVOKER, Evoker.createAttributes().build())
+ .put(EntityType.FOX, Fox.createAttributes().build())
+ .put(EntityType.GHAST, Ghast.createAttributes().build())
+ .put(EntityType.GIANT, Giant.createAttributes().build())
+ .put(EntityType.GLOW_SQUID, GlowSquid.createAttributes().build())
+ .put(EntityType.GOAT, Goat.createAttributes().build())
+ .put(EntityType.GUARDIAN, Guardian.createAttributes().build())
+ .put(EntityType.HOGLIN, Hoglin.createAttributes().build())
+ .put(EntityType.HORSE, AbstractHorse.createBaseHorseAttributes().build())
+ .put(EntityType.HUSK, Zombie.createAttributes().build())
+ .put(EntityType.ILLUSIONER, Illusioner.createAttributes().build())
+ .put(EntityType.IRON_GOLEM, IronGolem.createAttributes().build())
+ .put(EntityType.LLAMA, Llama.createAttributes().build())
+ .put(EntityType.MAGMA_CUBE, MagmaCube.createAttributes().build())
+ .put(EntityType.MOOSHROOM, Cow.createAttributes().build())
+ .put(EntityType.MULE, AbstractChestedHorse.createBaseChestedHorseAttributes().build())
+ .put(EntityType.OCELOT, Ocelot.createAttributes().build())
+ .put(EntityType.PANDA, Panda.createAttributes().build())
+ .put(EntityType.PARROT, Parrot.createAttributes().build())
+ .put(EntityType.PHANTOM, net.minecraft.world.entity.monster.Phantom.createAttributes().build()) // Purpur
+ .put(EntityType.PIG, Pig.createAttributes().build())
+ .put(EntityType.PIGLIN, Piglin.createAttributes().build())
+ .put(EntityType.PIGLIN_BRUTE, PiglinBrute.createAttributes().build())
+ .put(EntityType.PILLAGER, Pillager.createAttributes().build())
+ .put(EntityType.PLAYER, Player.createAttributes().build())
+ .put(EntityType.POLAR_BEAR, PolarBear.createAttributes().build())
+ .put(EntityType.PUFFERFISH, AbstractFish.createAttributes().build())
+ .put(EntityType.RABBIT, Rabbit.createAttributes().build())
+ .put(EntityType.RAVAGER, Ravager.createAttributes().build())
+ .put(EntityType.SALMON, AbstractFish.createAttributes().build())
+ .put(EntityType.SHEEP, Sheep.createAttributes().build())
+ .put(EntityType.SHULKER, Shulker.createAttributes().build())
+ .put(EntityType.SILVERFISH, Silverfish.createAttributes().build())
+ .put(EntityType.SKELETON, AbstractSkeleton.createAttributes().build())
+ .put(EntityType.SKELETON_HORSE, SkeletonHorse.createAttributes().build())
+ .put(EntityType.SLIME, Monster.createMonsterAttributes().build())
+ .put(EntityType.SNOW_GOLEM, SnowGolem.createAttributes().build())
+ .put(EntityType.SPIDER, Spider.createAttributes().build())
+ .put(EntityType.SQUID, Squid.createAttributes().build())
+ .put(EntityType.STRAY, AbstractSkeleton.createAttributes().build())
+ .put(EntityType.STRIDER, Strider.createAttributes().build())
+ .put(EntityType.TRADER_LLAMA, Llama.createAttributes().build())
+ .put(EntityType.TROPICAL_FISH, AbstractFish.createAttributes().build())
+ .put(EntityType.TURTLE, Turtle.createAttributes().build())
+ .put(EntityType.VEX, Vex.createAttributes().build())
+ .put(EntityType.VILLAGER, Villager.createAttributes().build())
+ .put(EntityType.VINDICATOR, Vindicator.createAttributes().build())
+ .put(EntityType.WANDERING_TRADER, Mob.createMobAttributes().build())
+ .put(EntityType.WITCH, Witch.createAttributes().build())
+ .put(EntityType.WITHER, WitherBoss.createAttributes().build())
+ .put(EntityType.WITHER_SKELETON, AbstractSkeleton.createAttributes().build())
+ .put(EntityType.WOLF, Wolf.createAttributes().build())
+ .put(EntityType.ZOGLIN, Zoglin.createAttributes().build())
+ .put(EntityType.ZOMBIE, Zombie.createAttributes().build())
+ .put(EntityType.ZOMBIE_HORSE, ZombieHorse.createAttributes().build())
+ .put(EntityType.ZOMBIE_VILLAGER, Zombie.createAttributes().build())
+ .put(EntityType.ZOMBIFIED_PIGLIN, ZombifiedPiglin.createAttributes().build())
+ .build();
+ // Purpur end
public static AttributeSupplier getSupplier(EntityType<? extends LivingEntity> type) {
return SUPPLIERS.get(type);
diff --git a/src/main/java/net/minecraft/world/entity/ai/control/MoveControl.java b/src/main/java/net/minecraft/world/entity/ai/control/MoveControl.java
index e3028cf5f88da6ab6d6d762e8011d45fd1d8eff8..5af8786692d3e978b3cb939d0a24bf7e24b149b5 100644
--- a/src/main/java/net/minecraft/world/entity/ai/control/MoveControl.java
+++ b/src/main/java/net/minecraft/world/entity/ai/control/MoveControl.java
@@ -29,6 +29,20 @@ public class MoveControl implements Control {
this.mob = entity;
}
+ // Purpur start
+ public void setSpeedModifier(double speed) {
+ this.speedModifier = speed;
+ }
+
+ public void setForward(float forward) {
+ this.strafeForwards = forward;
+ }
+
+ public void setStrafe(float strafe) {
+ this.strafeRight = strafe;
+ }
+ // Purpur end
+
public boolean hasWanted() {
return this.operation == MoveControl.Operation.MOVE_TO;
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/control/SmoothSwimmingLookControl.java b/src/main/java/net/minecraft/world/entity/ai/control/SmoothSwimmingLookControl.java
index 7df56705a4a0de2dc4ff7ab133fc26612c219162..60d21d6171b9af20a4c6fcc0d564a31aaa4ecdba 100644
--- a/src/main/java/net/minecraft/world/entity/ai/control/SmoothSwimmingLookControl.java
+++ b/src/main/java/net/minecraft/world/entity/ai/control/SmoothSwimmingLookControl.java
@@ -3,7 +3,7 @@ package net.minecraft.world.entity.ai.control;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Mob;
-public class SmoothSwimmingLookControl extends LookControl {
+public class SmoothSwimmingLookControl extends org.purpurmc.purpur.controller.LookControllerWASD { // Purpur
private final int maxYRotFromCenter;
private static final int HEAD_TILT_X = 10;
private static final int HEAD_TILT_Y = 20;
@@ -14,7 +14,7 @@ public class SmoothSwimmingLookControl extends LookControl {
}
@Override
- public void tick() {
+ public void vanillaTick() { // Purpur
if (this.lookAtCooldown > 0) {
--this.lookAtCooldown;
this.getYRotD().ifPresent((yaw) -> {
@@ -32,9 +32,9 @@ public class SmoothSwimmingLookControl extends LookControl {
}
float f = Mth.wrapDegrees(this.mob.yHeadRot - this.mob.yBodyRot);
- if (f < (float)(-this.maxYRotFromCenter)) {
+ if (f < (float) (-this.maxYRotFromCenter)) {
this.mob.yBodyRot -= 4.0F;
- } else if (f > (float)this.maxYRotFromCenter) {
+ } else if (f > (float) this.maxYRotFromCenter) {
this.mob.yBodyRot += 4.0F;
}
diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
index a76b754305036bf9c6387e27b86ec1559b290774..7814f9825ef1956c9f327bee8a0c268cda6eef21 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
@@ -19,6 +19,7 @@ import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
+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;
@@ -42,9 +43,56 @@ public class Bat extends AmbientCreature {
public Bat(EntityType<? extends Bat> type, Level world) {
super(type, world);
+ this.moveControl = new org.purpurmc.purpur.controller.FlyingWithSpacebarMoveControllerWASD(this, 0.075F); // Purpur
this.setResting(true);
}
+ // Purpur start
+ @Override
+ public boolean shouldSendAttribute(net.minecraft.world.entity.ai.attributes.Attribute attribute) { return attribute != Attributes.FLYING_SPEED; } // Fixes log spam on clients
+
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.batRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return level.purpurConfig.batRidableInWater;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.batControllable;
+ }
+
+ @Override
+ public double getMaxY() {
+ return level.purpurConfig.batMaxY;
+ }
+
+ @Override
+ public void onMount(Player rider) {
+ super.onMount(rider);
+ if (isResting()) {
+ setResting(false);
+ level.levelEvent(null, 1025, new BlockPos(this).above(), 0);
+ }
+ }
+
+ @Override
+ public void travel(Vec3 vec3) {
+ super.travel(vec3);
+ if (getRider() != null && this.isControllable() && !onGround) {
+ float speed = (float) getAttributeValue(Attributes.FLYING_SPEED) * 2;
+ setSpeed(speed);
+ Vec3 mot = getDeltaMovement();
+ move(MoverType.SELF, mot.multiply(speed, 0.25, speed));
+ setDeltaMovement(mot.scale(0.9D));
+ }
+ }
+ // Purpur end
+
@Override
public boolean isFlapping() {
return !this.isResting() && this.tickCount % Bat.TICKS_PER_FLAP == 0;
@@ -94,7 +142,7 @@ public class Bat extends AmbientCreature {
protected void pushEntities() {}
public static AttributeSupplier.Builder createAttributes() {
- return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 6.0D);
+ return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 6.0D).add(Attributes.FLYING_SPEED, 0.6D); // Purpur
}
public boolean isResting() {
@@ -126,6 +174,14 @@ public class Bat extends AmbientCreature {
@Override
protected void customServerAiStep() {
+ // Purpur start
+ if (getRider() != null && this.isControllable()) {
+ Vec3 mot = getDeltaMovement();
+ setDeltaMovement(mot.x(), mot.y() + (getVerticalMot() > 0 ? 0.07D : 0.0D), mot.z());
+ return;
+ }
+ // Purpur end
+
super.customServerAiStep();
BlockPos blockposition = this.blockPosition();
BlockPos blockposition1 = blockposition.above();
diff --git a/src/main/java/net/minecraft/world/entity/animal/AbstractFish.java b/src/main/java/net/minecraft/world/entity/animal/AbstractFish.java
index 3484defdfd5a487b11917310d7b1d1543291eee1..2ae0296b0a2e9585caf81b819742a0a8c1312545 100644
--- a/src/main/java/net/minecraft/world/entity/animal/AbstractFish.java
+++ b/src/main/java/net/minecraft/world/entity/animal/AbstractFish.java
@@ -99,12 +99,9 @@ public abstract class AbstractFish extends WaterAnimal implements Bucketable {
@Override
protected void registerGoals() {
super.registerGoals();
+ this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.goalSelector.addGoal(0, new PanicGoal(this, 1.25D));
- GoalSelector pathfindergoalselector = this.goalSelector;
- Predicate predicate = EntitySelector.NO_SPECTATORS;
-
- Objects.requireNonNull(predicate);
- pathfindergoalselector.addGoal(2, new AvoidEntityGoal<>(this, Player.class, 8.0F, 1.6D, 1.4D, predicate::test));
+ this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, Player.class, 8.0F, 1.6D, 1.4D, EntitySelector.NO_SPECTATORS::test)); // Purpur - decompile fix
this.goalSelector.addGoal(4, new AbstractFish.FishSwimGoal(this));
}
@@ -116,7 +113,7 @@ public abstract class AbstractFish extends WaterAnimal implements Bucketable {
@Override
public void travel(Vec3 movementInput) {
if (this.isEffectiveAi() && this.isInWater()) {
- this.moveRelative(0.01F, movementInput);
+ this.moveRelative(getRider() != null ? getSpeed() : 0.01F, movementInput); // Purpur
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
if (this.getTarget() == null) {
@@ -174,7 +171,7 @@ public abstract class AbstractFish extends WaterAnimal implements Bucketable {
@Override
protected void playStepSound(BlockPos pos, BlockState state) {}
- private static class FishMoveControl extends MoveControl {
+ private static class FishMoveControl extends org.purpurmc.purpur.controller.WaterMoveControllerWASD { // Purpur
private final AbstractFish fish;
@@ -183,14 +180,22 @@ public abstract class AbstractFish extends WaterAnimal implements Bucketable {
this.fish = owner;
}
+ // Purpur start
+ @Override
+ public void purpurTick(Player rider) {
+ super.purpurTick(rider);
+ fish.setDeltaMovement(fish.getDeltaMovement().add(0.0D, 0.005D, 0.0D));
+ }
+ // Purpur end
+
@Override
- public void tick() {
+ public void vanillaTick() { // Purpur
if (this.fish.isEyeInFluid(FluidTags.WATER)) {
this.fish.setDeltaMovement(this.fish.getDeltaMovement().add(0.0D, 0.005D, 0.0D));
}
if (this.operation == MoveControl.Operation.MOVE_TO && !this.fish.getNavigation().isDone()) {
- float f = (float) (this.speedModifier * this.fish.getAttributeValue(Attributes.MOVEMENT_SPEED));
+ float f = (float) (this.getSpeedModifier() * this.fish.getAttributeValue(Attributes.MOVEMENT_SPEED)); // Purpur
this.fish.setSpeed(Mth.lerp(0.125F, this.fish.getSpeed(), f));
double d0 = this.wantedX - this.fish.getX();
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bee.java b/src/main/java/net/minecraft/world/entity/animal/Bee.java
index 5a9d9926fb6fc356ee250d4e38f3bc303e280d45..fea80e6ed278bff6cd8773abe1a7def96b3a7c97 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Bee.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java
@@ -44,6 +44,7 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobType;
+import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.NeutralMob;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.Pose;
@@ -144,6 +145,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
public Bee(EntityType<? extends Bee> type, Level world) {
super(type, world);
this.remainingCooldownBeforeLocatingNewFlower = Mth.nextInt(this.random, 20, 60);
+ final org.purpurmc.purpur.controller.FlyingMoveControllerWASD flyingController = new org.purpurmc.purpur.controller.FlyingMoveControllerWASD(this, 0.25F, false); // Purpur
// Paper start - apply gravity to bees when they get stuck in the void, fixes MC-167279
class BeeFlyingMoveControl extends FlyingMoveControl {
public BeeFlyingMoveControl(final Mob entity, final int maxPitchChange, final boolean noGravity) {
@@ -152,11 +154,24 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
@Override
public void tick() {
+ // Purpur start
+ if (mob.getRider() != null && mob.isControllable()) {
+ flyingController.purpurTick(mob.getRider());
+ return;
+ }
+ // Purpur end
if (this.mob.getY() <= Bee.this.level.getMinBuildHeight()) {
this.mob.setNoGravity(false);
}
super.tick();
}
+
+ // Purpur start
+ @Override
+ public boolean hasWanted() {
+ return mob.getRider() != null || !mob.isControllable() || super.hasWanted();
+ }
+ // Purpur end
}
this.moveControl = new BeeFlyingMoveControl(this, 20, true);
// Paper end
@@ -168,6 +183,40 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
this.setPathfindingMalus(BlockPathTypes.FENCE, -1.0F);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.beeRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return level.purpurConfig.beeRidableInWater;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.beeControllable;
+ }
+
+ @Override
+ public double getMaxY() {
+ return level.purpurConfig.beeMaxY;
+ }
+
+ @Override
+ public void travel(Vec3 vec3) {
+ super.travel(vec3);
+ if (getRider() != null && this.isControllable() && !onGround) {
+ float speed = (float) getAttributeValue(Attributes.FLYING_SPEED) * 2;
+ setSpeed(speed);
+ Vec3 mot = getDeltaMovement();
+ move(MoverType.SELF, mot.multiply(speed, speed, speed));
+ setDeltaMovement(mot.scale(0.9D));
+ }
+ }
+ // Purpur end
+
@Override
protected void defineSynchedData() {
super.defineSynchedData();
@@ -182,6 +231,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
@Override
protected void registerGoals() {
+ this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.goalSelector.addGoal(0, new Bee.BeeAttackGoal(this, 1.399999976158142D, true));
this.goalSelector.addGoal(1, new Bee.BeeEnterHiveGoal());
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
@@ -197,6 +247,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
this.goalSelector.addGoal(7, new Bee.BeeGrowCropGoal());
this.goalSelector.addGoal(8, new Bee.BeeWanderGoal());
this.goalSelector.addGoal(9, new FloatGoal(this));
+ this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.targetSelector.addGoal(1, (new Bee.BeeHurtByOtherGoal(this)).setAlertOthers(new Class[0]));
this.targetSelector.addGoal(2, new Bee.BeeBecomeAngryTargetGoal(this));
this.targetSelector.addGoal(3, new ResetUniversalAngerTargetGoal<>(this, true));
@@ -879,16 +930,16 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
}
}
- private class BeeLookControl extends LookControl {
+ private class BeeLookControl extends org.purpurmc.purpur.controller.LookControllerWASD { // Purpur
BeeLookControl(Mob entity) {
super(entity);
}
@Override
- public void tick() {
+ public void vanillaTick() { // Purpur
if (!Bee.this.isAngry()) {
- super.tick();
+ super.vanillaTick(); // Purpur
}
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/Cat.java b/src/main/java/net/minecraft/world/entity/animal/Cat.java
index b0d3444c721765e10217474ca57f703531e69260..495e3b17cc1c5b5d502a172a9b6bd8c95a7b2064 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Cat.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Cat.java
@@ -122,6 +122,31 @@ public class Cat extends TamableAnimal {
super(type, world);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.catRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return level.purpurConfig.catRidableInWater;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.catControllable;
+ }
+
+ @Override
+ public void onMount(Player rider) {
+ super.onMount(rider);
+ setInSittingPose(false);
+ setLying(false);
+ setRelaxStateOne(false);
+ }
+ // Purpur end
+
public ResourceLocation getResourceLocation() {
return (ResourceLocation) Cat.TEXTURE_BY_TYPE.getOrDefault(this.getCatType(), (ResourceLocation) Cat.TEXTURE_BY_TYPE.get(0));
}
@@ -130,6 +155,7 @@ public class Cat extends TamableAnimal {
protected void registerGoals() {
this.temptGoal = new Cat.CatTemptGoal(this, 0.6D, Cat.TEMPT_INGREDIENT, true);
this.goalSelector.addGoal(1, new FloatGoal(this));
+ this.goalSelector.addGoal(1, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.goalSelector.addGoal(1, new SitWhenOrderedToGoal(this));
this.goalSelector.addGoal(2, new Cat.CatRelaxOnOwnerGoal(this));
this.goalSelector.addGoal(3, this.temptGoal);
@@ -141,6 +167,7 @@ public class Cat extends TamableAnimal {
this.goalSelector.addGoal(10, new BreedGoal(this, 0.8D));
this.goalSelector.addGoal(11, new WaterAvoidingRandomStrollGoal(this, 0.8D, 1.0000001E-5F));
this.goalSelector.addGoal(12, new LookAtPlayerGoal(this, Player.class, 10.0F));
+ this.targetSelector.addGoal(1, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.targetSelector.addGoal(1, new NonTameRandomTargetGoal<>(this, Rabbit.class, false, (Predicate) null));
this.targetSelector.addGoal(1, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR));
}
@@ -395,6 +422,7 @@ public class Cat extends TamableAnimal {
@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
+ if (getRider() != null) return InteractionResult.PASS; // Purpur
ItemStack itemstack = player.getItemInHand(hand);
Item item = itemstack.getItem();
diff --git a/src/main/java/net/minecraft/world/entity/animal/Chicken.java b/src/main/java/net/minecraft/world/entity/animal/Chicken.java
index aa373560120684a037ac02d8df196b97b791bd85..46ac6d4559be25914ebb24684fbeb33f471e226d 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Chicken.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Chicken.java
@@ -52,9 +52,27 @@ public class Chicken extends Animal {
this.setPathfindingMalus(BlockPathTypes.WATER, 0.0F);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.chickenRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return level.purpurConfig.chickenRidableInWater;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.chickenControllable;
+ }
+ // Purpur end
+
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
+ this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.goalSelector.addGoal(1, new PanicGoal(this, 1.4D));
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, Chicken.FOOD_ITEMS, false));
diff --git a/src/main/java/net/minecraft/world/entity/animal/Cod.java b/src/main/java/net/minecraft/world/entity/animal/Cod.java
index 824e5e4fe7619ae46061c3c978c9a044db8c84ab..545ef4ab037b3173cc7377ad8147a44a2050d56f 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Cod.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Cod.java
@@ -13,6 +13,23 @@ public class Cod extends AbstractSchoolingFish {
super(type, world);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.codRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return true;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.codControllable;
+ }
+ // Purpur end
+
@Override
public ItemStack getBucketItemStack() {
return new ItemStack(Items.COD_BUCKET);
diff --git a/src/main/java/net/minecraft/world/entity/animal/Cow.java b/src/main/java/net/minecraft/world/entity/animal/Cow.java
index 425c6da0de40983b0870c9fd1b53f16b6a11c34c..8f046fb76b6967e72abde523ffb790e0f46b80e0 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Cow.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Cow.java
@@ -40,9 +40,27 @@ public class Cow extends Animal {
super(type, world);
}
+ // Purpur start
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.cowRidable;
+ }
+
+ @Override
+ public boolean rideableUnderWater() {
+ return level.purpurConfig.cowRidableInWater;
+ }
+
+ @Override
+ public boolean isControllable() {
+ return level.purpurConfig.cowControllable;
+ }
+ // Purpur end
+
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
+ this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
this.goalSelector.addGoal(1, new PanicGoal(this, 2.0D));
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.25D, Ingredient.of(Items.WHEAT), false));
@@ -83,6 +101,7 @@ public class Cow extends Animal {
@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
+ if (getRider() != null) return InteractionResult.PASS; // Purpur
ItemStack itemstack = player.getItemInHand(hand);
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
@@ -90,7 +109,7 @@ public class Cow extends Animal {
org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level, player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand); // Paper - add enumHand
if (event.isCancelled()) {
- return InteractionResult.PASS;
+ return tryRide(player, hand); // Purpur
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/entity/animal/Dolphin.java b/src/main/java/net/minecraft/world/entity/animal/Dolphin.java
index 6f759d144c1b0f576a4fd617bf36456b72ff428d..ca8c0651642500a0aeded005a446eebbca7aa399 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Dolphin.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Dolphin.java
@@ -80,14 +80,87 @@ public class Dolphin extends WaterAnimal {
public static final Predicate<ItemEntity> ALLOWED_ITEMS = (entityitem) -> {
return !entityitem.hasPickUpDelay() && entityitem.isAlive() && entityitem.isInWater();
};
+ private int spitCooldown; // Purpur