-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathLivingEntity.java.patch
767 lines (700 loc) · 39.1 KB
/
LivingEntity.java.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
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -132,7 +_,7 @@
import net.minecraft.world.scores.Scoreboard;
import org.slf4j.Logger;
-public abstract class LivingEntity extends Entity implements Attackable {
+public abstract class LivingEntity extends Entity implements Attackable, net.neoforged.neoforge.common.extensions.ILivingEntityExtension {
private static final Logger LOGGER = LogUtils.getLogger();
private static final String TAG_ACTIVE_EFFECTS = "active_effects";
private static final ResourceLocation SPEED_MODIFIER_POWDER_SNOW_ID = ResourceLocation.withDefaultNamespace("powder_snow");
@@ -254,6 +_,14 @@
private boolean skipDropExperience;
private final Reference2ObjectMap<Enchantment, Set<EnchantmentLocationBasedEffect>> activeLocationDependentEnchantments = new Reference2ObjectArrayMap<>();
protected float appliedScale = 1.0F;
+ /**
+ * This field stores information about damage dealt to this entity.
+ * a new {@link net.neoforged.neoforge.common.damagesource.DamageContainer} is instantiated
+ * via {@link #hurt(DamageSource, float)} after invulnerability checks, and is removed from
+ * the stack before the method's return.
+ **/
+ @Nullable
+ protected java.util.Stack<net.neoforged.neoforge.common.damagesource.DamageContainer> damageContainers = new java.util.Stack<>();
protected LivingEntity(EntityType<? extends LivingEntity> p_20966_, Level p_20967_) {
super(p_20966_, p_20967_);
@@ -320,7 +_,9 @@
.add(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE)
.add(Attributes.WATER_MOVEMENT_EFFICIENCY)
.add(Attributes.MOVEMENT_EFFICIENCY)
- .add(Attributes.ATTACK_KNOCKBACK);
+ .add(Attributes.ATTACK_KNOCKBACK)
+ .add(net.neoforged.neoforge.common.NeoForgeMod.SWIM_SPEED)
+ .add(net.neoforged.neoforge.common.NeoForgeMod.NAMETAG_DISTANCE);
}
@Override
@@ -348,7 +_,8 @@
float f = (float)Mth.ceil((double)this.fallDistance - d7);
double d4 = Math.min((double)(0.2F + f / 15.0F), 2.5);
int i = (int)(150.0 * d4);
- ((ServerLevel)this.level()).sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, p_20992_), d0, d1, d2, i, 0.0, 0.0, 0.0, 0.15F);
+ if (!p_20992_.addLandingEffects((ServerLevel) this.level(), p_20993_, p_20992_, this, i))
+ ((ServerLevel)this.level()).sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, p_20992_).setPos(p_20993_), d0, d1, d2, i, 0.0, 0.0, 0.0, 0.15F);
}
}
@@ -358,6 +_,7 @@
}
}
+ @Deprecated //FORGE: Use canDrownInFluidType instead
public final boolean canBreatheUnderwater() {
return this.getType().is(EntityTypeTags.CAN_BREATHE_UNDER_WATER);
}
@@ -403,6 +_,9 @@
}
}
+ int airSupply = this.getAirSupply();
+ net.neoforged.neoforge.common.CommonHooks.onLivingBreathe(this, airSupply - decreaseAirSupply(airSupply), increaseAirSupply(airSupply) - airSupply);
+ if (false) // Forge: Handled in ForgeHooks#onLivingBreathe(LivingEntity, int, int)
if (this.isEyeInFluid(FluidTags.WATER)
&& !this.level().getBlockState(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN)) {
boolean flag1 = !this.canBreatheUnderwater()
@@ -441,7 +_,7 @@
}
}
- if (this.isAlive() && (this.isInWaterRainOrBubble() || this.isInPowderSnow)) {
+ if (this.isAlive() && (this.isInWaterRainOrBubble() || this.isInPowderSnow || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType)))) {
this.extinguishFire();
}
@@ -772,7 +_,7 @@
Holder<MobEffect> holder = iterator.next();
MobEffectInstance mobeffectinstance = this.activeEffects.get(holder);
if (!mobeffectinstance.tick(this, () -> this.onEffectUpdated(mobeffectinstance, true, null))) {
- if (!this.level().isClientSide) {
+ if (!this.level().isClientSide && !net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.entity.living.MobEffectEvent.Expired(this, mobeffectinstance)).isCanceled()) {
iterator.remove();
this.onEffectRemoved(mobeffectinstance);
}
@@ -817,8 +_,9 @@
List<ParticleOptions> list = this.activeEffects
.values()
.stream()
- .filter(MobEffectInstance::isVisible)
- .map(MobEffectInstance::getParticleOptions)
+ .map(effect -> net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.entity.living.EffectParticleModificationEvent(this, effect)))
+ .filter(net.neoforged.neoforge.event.entity.living.EffectParticleModificationEvent::isVisible)
+ .map(net.neoforged.neoforge.event.entity.living.EffectParticleModificationEvent::getParticleOptions)
.toList();
this.entityData.set(DATA_EFFECT_PARTICLES, list);
this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(this.activeEffects.values()));
@@ -858,6 +_,7 @@
}
}
+ d0 = net.neoforged.neoforge.common.CommonHooks.getEntityVisibilityMultiplier(this, p_20969_, d0);
return d0;
}
@@ -899,7 +_,9 @@
boolean flag;
for (flag = false; iterator.hasNext(); flag = true) {
- this.onEffectRemoved(iterator.next());
+ MobEffectInstance effect = iterator.next();
+ if(net.neoforged.neoforge.event.EventHooks.onEffectRemoved(this, effect, null)) continue;
+ this.onEffectRemoved(effect);
iterator.remove();
}
@@ -929,11 +_,12 @@
}
public boolean addEffect(MobEffectInstance p_147208_, @Nullable Entity p_147209_) {
- if (!this.canBeAffected(p_147208_)) {
+ if (!net.neoforged.neoforge.common.CommonHooks.canMobEffectBeApplied(this, p_147208_)) {
return false;
} else {
MobEffectInstance mobeffectinstance = this.activeEffects.get(p_147208_.getEffect());
boolean flag = false;
+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.entity.living.MobEffectEvent.Added(this, mobeffectinstance, p_147208_, p_147209_));
if (mobeffectinstance == null) {
this.activeEffects.put(p_147208_.getEffect(), p_147208_);
this.onEffectAdded(p_147208_, p_147209_);
@@ -949,6 +_,14 @@
}
}
+ /**
+ * Neo: Override-Only. Call via {@link net.neoforged.neoforge.common.CommonHooks#canMobEffectBeApplied(LivingEntity, MobEffectInstance)}
+ *
+ * @param p_21197_ A mob effect instance
+ * @return If the mob effect instance can be applied to this entity
+ */
+ @Deprecated
+ @org.jetbrains.annotations.ApiStatus.OverrideOnly
public boolean canBeAffected(MobEffectInstance p_21197_) {
if (this.getType().is(EntityTypeTags.IMMUNE_TO_INFESTED)) {
return !p_21197_.is(MobEffects.INFESTED);
@@ -962,7 +_,7 @@
}
public void forceAddEffect(MobEffectInstance p_147216_, @Nullable Entity p_147217_) {
- if (this.canBeAffected(p_147216_)) {
+ if (net.neoforged.neoforge.common.CommonHooks.canMobEffectBeApplied(this, p_147216_)) {
MobEffectInstance mobeffectinstance = this.activeEffects.put(p_147216_.getEffect(), p_147216_);
if (mobeffectinstance == null) {
this.onEffectAdded(p_147216_, p_147217_);
@@ -983,6 +_,7 @@
}
public boolean removeEffect(Holder<MobEffect> p_316570_) {
+ if (net.neoforged.neoforge.event.EventHooks.onEffectRemoved(this, p_316570_, null)) return false;
MobEffectInstance mobeffectinstance = this.removeEffectNoUpdate(p_316570_);
if (mobeffectinstance != null) {
this.onEffectRemoved(mobeffectinstance);
@@ -1061,6 +_,8 @@
}
public void heal(float p_21116_) {
+ p_21116_ = net.neoforged.neoforge.event.EventHooks.onLivingHeal(this, p_21116_);
+ if (p_21116_ <= 0) return;
float f = this.getHealth();
if (f > 0.0F) {
this.setHealth(f + p_21116_);
@@ -1090,23 +_,30 @@
} else if (p_21016_.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
} else {
+ this.damageContainers.push(new net.neoforged.neoforge.common.damagesource.DamageContainer(p_21016_, p_21017_));
+ if (net.neoforged.neoforge.common.CommonHooks.onEntityIncomingDamage(this, this.damageContainers.peek())) return false;
if (this.isSleeping() && !this.level().isClientSide) {
this.stopSleeping();
}
this.noActionTime = 0;
+ p_21017_ = this.damageContainers.peek().getNewDamage(); //Neo: enforce damage container as source of truth for damage amount
float f = p_21017_;
boolean flag = false;
float f1 = 0.0F;
- if (p_21017_ > 0.0F && this.isDamageSourceBlocked(p_21016_)) {
- this.hurtCurrentlyUsedShield(p_21017_);
- f1 = p_21017_;
- p_21017_ = 0.0F;
+ net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent ev;
+ if (p_21017_ > 0.0F && (ev = net.neoforged.neoforge.common.CommonHooks.onDamageBlock(this, this.damageContainers.peek(), this.isDamageSourceBlocked(p_21016_))).getBlocked()) {
+ this.damageContainers.peek().setBlockedDamage(ev);
+ if(ev.shieldDamage() > 0) {
+ this.hurtCurrentlyUsedShield(ev.shieldDamage());
+ }
+ f1 = ev.getBlockedDamage();
+ p_21017_ = ev.getDamageContainer().getNewDamage();
if (!p_21016_.is(DamageTypeTags.IS_PROJECTILE) && p_21016_.getDirectEntity() instanceof LivingEntity livingentity) {
this.blockUsingShield(livingentity);
}
- flag = true;
+ flag = p_21017_ <= 0;
}
if (p_21016_.is(DamageTypeTags.IS_FREEZING) && this.getType().is(EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES)) {
@@ -1118,10 +_,12 @@
p_21017_ *= 0.75F;
}
+ this.damageContainers.peek().setNewDamage(p_21017_); //update container with vanilla changes
this.walkAnimation.setSpeed(1.5F);
boolean flag1 = true;
if ((float)this.invulnerableTime > 10.0F && !p_21016_.is(DamageTypeTags.BYPASSES_COOLDOWN)) {
if (p_21017_ <= this.lastHurt) {
+ this.damageContainers.pop();
return false;
}
@@ -1130,12 +_,13 @@
flag1 = false;
} else {
this.lastHurt = p_21017_;
- this.invulnerableTime = 20;
+ this.invulnerableTime = this.damageContainers.peek().getPostAttackInvulnerabilityTicks();
this.actuallyHurt(p_21016_, p_21017_);
this.hurtDuration = 10;
this.hurtTime = this.hurtDuration;
}
+ p_21017_ = this.damageContainers.peek().getNewDamage(); //update local with container value
Entity entity = p_21016_.getEntity();
if (entity != null) {
if (entity instanceof LivingEntity livingentity1
@@ -1147,9 +_,9 @@
if (entity instanceof Player player1) {
this.lastHurtByPlayerTime = 100;
this.lastHurtByPlayer = player1;
- } else if (entity instanceof Wolf wolf && wolf.isTame()) {
+ } else if (entity instanceof TamableAnimal tamableAnimal && tamableAnimal.isTame()) {
this.lastHurtByPlayerTime = 100;
- if (wolf.getOwner() instanceof Player player) {
+ if (tamableAnimal.getOwner() instanceof Player player) {
this.lastHurtByPlayer = player;
} else {
this.lastHurtByPlayer = null;
@@ -1220,6 +_,7 @@
CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayer)entity, this, p_21016_, f, p_21017_, flag);
}
+ this.damageContainers.pop();
return flag2;
}
}
@@ -1240,7 +_,7 @@
for (InteractionHand interactionhand : InteractionHand.values()) {
ItemStack itemstack1 = this.getItemInHand(interactionhand);
- if (itemstack1.is(Items.TOTEM_OF_UNDYING)) {
+ if (itemstack1.is(Items.TOTEM_OF_UNDYING) && net.neoforged.neoforge.common.CommonHooks.onLivingUseTotem(this, p_21263_, itemstack1, interactionhand)) {
itemstack = itemstack1.copy();
itemstack1.shrink(1);
break;
@@ -1249,13 +_,13 @@
if (itemstack != null) {
if (this instanceof ServerPlayer serverplayer) {
- serverplayer.awardStat(Stats.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
+ serverplayer.awardStat(Stats.ITEM_USED.get(Items.TOTEM_OF_UNDYING), 1);
CriteriaTriggers.USED_TOTEM.trigger(serverplayer, itemstack);
this.gameEvent(GameEvent.ITEM_INTERACT_FINISH);
}
this.setHealth(1.0F);
- this.removeAllEffects();
+ this.removeEffectsCuredBy(net.neoforged.neoforge.common.EffectCures.PROTECTED_BY_TOTEM);
this.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 900, 1));
this.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 100, 1));
this.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 800, 0));
@@ -1326,6 +_,7 @@
}
public void die(DamageSource p_21014_) {
+ if (net.neoforged.neoforge.common.CommonHooks.onLivingDeath(this, p_21014_)) return;
if (!this.isRemoved() && !this.dead) {
Entity entity = p_21014_.getEntity();
LivingEntity livingentity = this.getKillCredit();
@@ -1361,7 +_,7 @@
if (!this.level().isClientSide) {
boolean flag = false;
if (p_21269_ instanceof WitherBoss) {
- if (this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+ if (net.neoforged.neoforge.event.EventHooks.canEntityGrief(this.level(), p_21269_)) {
BlockPos blockpos = this.blockPosition();
BlockState blockstate = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level().getBlockState(blockpos).isAir() && blockstate.canSurvive(this.level(), blockpos)) {
@@ -1379,6 +_,7 @@
}
protected void dropAllDeathLoot(ServerLevel p_348524_, DamageSource p_21192_) {
+ this.captureDrops(new java.util.ArrayList<>());
boolean flag = this.lastHurtByPlayerTime > 0;
if (this.shouldDropLoot() && p_348524_.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
this.dropFromLootTable(p_21192_, flag);
@@ -1387,6 +_,10 @@
this.dropEquipment();
this.dropExperience(p_21192_.getEntity());
+
+ Collection<ItemEntity> drops = captureDrops(null);
+ if (!net.neoforged.neoforge.common.CommonHooks.onLivingDrops(this, p_21192_, drops, lastHurtByPlayerTime > 0))
+ drops.forEach(e -> level().addFreshEntity(e));
}
protected void dropEquipment() {
@@ -1399,7 +_,8 @@
this.isAlwaysExperienceDropper()
|| this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)
)) {
- ExperienceOrb.award(serverlevel, this.position(), this.getExperienceReward(serverlevel, p_345346_));
+ int reward = net.neoforged.neoforge.event.EventHooks.getExperienceDrop(this, this.lastHurtByPlayer, this.getExperienceReward(serverlevel, p_345346_));
+ ExperienceOrb.award((ServerLevel) this.level(), this.position(), reward);
}
}
@@ -1440,6 +_,11 @@
}
public void knockback(double p_147241_, double p_147242_, double p_147243_) {
+ net.neoforged.neoforge.event.entity.living.LivingKnockBackEvent event = net.neoforged.neoforge.common.CommonHooks.onLivingKnockBack(this, (float) p_147241_, p_147242_, p_147243_);
+ if(event.isCanceled()) return;
+ p_147241_ = event.getStrength();
+ p_147242_ = event.getRatioX();
+ p_147243_ = event.getRatioZ();
p_147241_ *= 1.0 - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
if (!(p_147241_ <= 0.0)) {
this.hasImpulse = true;
@@ -1521,15 +_,9 @@
} else {
BlockPos blockpos = this.blockPosition();
BlockState blockstate = this.getInBlockState();
- if (blockstate.is(BlockTags.CLIMBABLE)) {
- this.lastClimbablePos = Optional.of(blockpos);
- return true;
- } else if (blockstate.getBlock() instanceof TrapDoorBlock && this.trapdoorUsableAsLadder(blockpos, blockstate)) {
- this.lastClimbablePos = Optional.of(blockpos);
- return true;
- } else {
- return false;
- }
+ Optional<BlockPos> ladderPos = net.neoforged.neoforge.common.CommonHooks.isLivingOnLadder(blockstate, level(), blockpos, this);
+ if (ladderPos.isPresent()) this.lastClimbablePos = ladderPos;
+ return ladderPos.isPresent();
}
}
@@ -1558,6 +_,11 @@
@Override
public boolean causeFallDamage(float p_147187_, float p_147188_, DamageSource p_147189_) {
+ float[] ret = net.neoforged.neoforge.common.CommonHooks.onLivingFall(this, p_147187_, p_147188_);
+ if (ret == null) return false;
+ p_147187_ = ret[0];
+ p_147188_ = ret[1];
+
boolean flag = super.causeFallDamage(p_147187_, p_147188_, p_147189_);
int i = this.calculateFallDamage(p_147187_, p_147188_);
if (i > 0) {
@@ -1585,9 +_,10 @@
int i = Mth.floor(this.getX());
int j = Mth.floor(this.getY() - 0.2F);
int k = Mth.floor(this.getZ());
- BlockState blockstate = this.level().getBlockState(new BlockPos(i, j, k));
+ BlockPos pos = new BlockPos(i, j, k);
+ BlockState blockstate = this.level().getBlockState(pos);
if (!blockstate.isAir()) {
- SoundType soundtype = blockstate.getSoundType();
+ SoundType soundtype = blockstate.getSoundType(level(), pos, this);
this.playSound(soundtype.getFallSound(), soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
}
}
@@ -1616,6 +_,8 @@
if (!(p_330394_ <= 0.0F)) {
int i = (int)Math.max(1.0F, p_330394_ / 4.0F);
+ net.neoforged.neoforge.common.CommonHooks.onArmorHurt(p_330843_, p_331314_, i, this);
+ if (true) return; //Neo: Invalidates the loop. Armor damage happens in common hook.
for (EquipmentSlot equipmentslot : p_331314_) {
ItemStack itemstack = this.getItemBySlot(equipmentslot);
if (itemstack.getItem() instanceof ArmorItem && itemstack.canBeHurtBy(p_330843_)) {
@@ -1648,6 +_,7 @@
p_21194_ = Math.max(f / 25.0F, 0.0F);
float f2 = f1 - p_21194_;
if (f2 > 0.0F && f2 < 3.4028235E37F) {
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.MOB_EFFECTS, f2);
if (this instanceof ServerPlayer) {
((ServerPlayer)this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f2 * 10.0F));
} else if (p_21193_.getEntity() instanceof ServerPlayer) {
@@ -1670,6 +_,7 @@
if (f3 > 0.0F) {
p_21194_ = CombatRules.getDamageAfterMagicAbsorb(p_21194_, f3);
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ENCHANTMENTS,this.damageContainers.peek().getNewDamage() - p_21194_);
}
return p_21194_;
@@ -1679,11 +_,14 @@
protected void actuallyHurt(DamageSource p_21240_, float p_21241_) {
if (!this.isInvulnerableTo(p_21240_)) {
- p_21241_ = this.getDamageAfterArmorAbsorb(p_21240_, p_21241_);
- p_21241_ = this.getDamageAfterMagicAbsorb(p_21240_, p_21241_);
- float f1 = Math.max(p_21241_ - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (p_21241_ - f1));
- float f = p_21241_ - f1;
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ARMOR, this.damageContainers.peek().getNewDamage() - this.getDamageAfterArmorAbsorb(p_21240_, this.damageContainers.peek().getNewDamage()));
+ this.getDamageAfterMagicAbsorb(p_21240_, this.damageContainers.peek().getNewDamage());
+ float damage = net.neoforged.neoforge.common.CommonHooks.onLivingDamagePre(this, this.damageContainers.peek());
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION, Math.min(this.getAbsorptionAmount(), damage));
+ float absorbed = Math.min(damage, this.damageContainers.peek().getReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION));
+ this.setAbsorptionAmount(Math.max(0, this.getAbsorptionAmount() - absorbed));
+ float f1 = this.damageContainers.peek().getNewDamage();
+ float f = absorbed;
if (f > 0.0F && f < 3.4028235E37F && p_21240_.getEntity() instanceof ServerPlayer serverplayer) {
serverplayer.awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f * 10.0F));
}
@@ -1691,9 +_,10 @@
if (f1 != 0.0F) {
this.getCombatTracker().recordDamage(p_21240_, f1);
this.setHealth(this.getHealth() - f1);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - f1);
this.gameEvent(GameEvent.ENTITY_DAMAGE);
+ this.onDamageTaken(this.damageContainers.peek());
}
+ net.neoforged.neoforge.common.CommonHooks.onLivingDamagePost(this, this.damageContainers.peek());
}
}
@@ -1747,6 +_,8 @@
}
public void swing(InteractionHand p_21012_, boolean p_21013_) {
+ ItemStack stack = this.getItemInHand(p_21012_);
+ if (!stack.isEmpty() && stack.onEntitySwing(this, p_21012_)) return;
if (!this.swinging || this.swingTime >= this.getCurrentSwingDuration() / 2 || this.swingTime < 0) {
this.swingTime = -1;
this.swinging = true;
@@ -1859,8 +_,10 @@
private void swapHandItems() {
ItemStack itemstack = this.getItemBySlot(EquipmentSlot.OFFHAND);
- this.setItemSlot(EquipmentSlot.OFFHAND, this.getItemBySlot(EquipmentSlot.MAINHAND));
- this.setItemSlot(EquipmentSlot.MAINHAND, itemstack);
+ var event = net.neoforged.neoforge.common.CommonHooks.onLivingSwapHandItems(this);
+ if (event.isCanceled()) return;
+ this.setItemSlot(EquipmentSlot.OFFHAND, event.getItemSwappedToOffHand());
+ this.setItemSlot(EquipmentSlot.MAINHAND, event.getItemSwappedToMainHand());
}
@Override
@@ -2064,15 +_,18 @@
}
this.hasImpulse = true;
+ net.neoforged.neoforge.common.CommonHooks.onLivingJump(this);
}
}
+ @Deprecated // FORGE: use sinkInFluid instead
protected void goDownInWater() {
- this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04F, 0.0));
+ this.sinkInFluid(net.neoforged.neoforge.common.NeoForgeMod.WATER_TYPE.value());
}
+ @Deprecated // FORGE: use jumpInFluid instead
protected void jumpInLiquid(TagKey<Fluid> p_204043_) {
- this.setDeltaMovement(this.getDeltaMovement().add(0.0, 0.04F, 0.0));
+ this.setDeltaMovement(this.getDeltaMovement().add(0.0D, (double)0.04F * this.getAttributeValue(net.neoforged.neoforge.common.NeoForgeMod.SWIM_SPEED), 0.0D));
}
protected float getWaterSlowDown() {
@@ -2097,7 +_,8 @@
}
FluidState fluidstate = this.level().getFluidState(this.blockPosition());
- if (this.isInWater() && this.isAffectedByFluids() && !this.canStandOnFluid(fluidstate)) {
+ if ((this.isInWater() || (this.isInFluidType(fluidstate) && fluidstate.getFluidType() != net.neoforged.neoforge.common.NeoForgeMod.LAVA_TYPE.value())) && this.isAffectedByFluids() && !this.canStandOnFluid(fluidstate)) {
+ if (this.isInWater() || (this.isInFluidType(fluidstate) && !this.moveInFluid(fluidstate, p_21280_, d0))) {
double d9 = this.getY();
float f4 = this.isSprinting() ? 0.9F : this.getWaterSlowDown();
float f5 = 0.02F;
@@ -2115,6 +_,7 @@
f4 = 0.96F;
}
+ f5 *= (float)this.getAttributeValue(net.neoforged.neoforge.common.NeoForgeMod.SWIM_SPEED);
this.moveRelative(f5, p_21280_);
this.move(MoverType.SELF, this.getDeltaMovement());
Vec3 vec36 = this.getDeltaMovement();
@@ -2128,6 +_,7 @@
if (this.horizontalCollision && this.isFree(vec32.x, vec32.y + 0.6F - this.getY() + d9, vec32.z)) {
this.setDeltaMovement(vec32.x, 0.3F, vec32.z);
}
+ }
} else if (this.isInLava() && this.isAffectedByFluids() && !this.canStandOnFluid(fluidstate)) {
double d8 = this.getY();
this.moveRelative(0.02F, p_21280_);
@@ -2190,7 +_,7 @@
}
} else {
BlockPos blockpos = this.getBlockPosBelowThatAffectsMyMovement();
- float f2 = this.level().getBlockState(blockpos).getBlock().getFriction();
+ float f2 = this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getFriction(level(), this.getBlockPosBelowThatAffectsMyMovement(), this);
float f3 = this.onGround() ? f2 * 0.91F : 0.91F;
Vec3 vec35 = this.handleRelativeFrictionAndCalculateMovement(p_21280_, f2);
double d2 = vec35.y;
@@ -2284,7 +_,7 @@
double d0 = Mth.clamp(p_21298_.x, -0.15F, 0.15F);
double d1 = Mth.clamp(p_21298_.z, -0.15F, 0.15F);
double d2 = Math.max(p_21298_.y, -0.15F);
- if (d2 < 0.0 && !this.getInBlockState().is(Blocks.SCAFFOLDING) && this.isSuppressingSlidingDownLadder() && this instanceof Player) {
+ if (d2 < 0.0D && !this.getInBlockState().isScaffolding(this) && this.isSuppressingSlidingDownLadder() && this instanceof Player) {
d2 = 0.0;
}
@@ -2466,6 +_,7 @@
};
ItemStack itemstack1 = this.getItemBySlot(equipmentslot);
if (this.equipmentHasChanged(itemstack, itemstack1)) {
+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.entity.living.LivingEquipmentChangeEvent(this, equipmentslot, itemstack, itemstack1));
if (map == null) {
map = Maps.newEnumMap(EquipmentSlot.class);
}
@@ -2637,6 +_,9 @@
this.level().getProfiler().push("jump");
if (this.jumping && this.isAffectedByFluids()) {
double d3;
+ net.neoforged.neoforge.fluids.FluidType fluidType = this.getMaxHeightFluidType();
+ if (!fluidType.isAir()) d3 = this.getFluidTypeHeight(fluidType);
+ else
if (this.isInLava()) {
d3 = this.getFluidHeight(FluidTags.LAVA);
} else {
@@ -2647,15 +_,17 @@
double d4 = this.getFluidJumpThreshold();
if (!flag || this.onGround() && !(d3 > d4)) {
if (!this.isInLava() || this.onGround() && !(d3 > d4)) {
+ if (fluidType.isAir() || this.onGround() && !(d3 > d4)) {
if ((this.onGround() || flag && d3 <= d4) && this.noJumpDelay == 0) {
this.jumpFromGround();
this.noJumpDelay = 10;
}
+ } else this.jumpInFluid(fluidType);
} else {
- this.jumpInLiquid(FluidTags.LAVA);
+ this.jumpInFluid(net.neoforged.neoforge.common.NeoForgeMod.LAVA_TYPE.value());
}
} else {
- this.jumpInLiquid(FluidTags.WATER);
+ this.jumpInFluid(net.neoforged.neoforge.common.NeoForgeMod.WATER_TYPE.value());
}
} else {
this.noJumpDelay = 0;
@@ -2720,6 +_,8 @@
boolean flag = this.getSharedFlag(7);
if (flag && !this.onGround() && !this.isPassenger() && !this.hasEffect(MobEffects.LEVITATION)) {
ItemStack itemstack = this.getItemBySlot(EquipmentSlot.CHEST);
+ flag = itemstack.canElytraFly(this) && itemstack.elytraFlightTick(this, this.fallFlyTicks);
+ if (false) //Neo: Moved to ElytraItem
if (itemstack.is(Items.ELYTRA) && ElytraItem.isFlyEnabled(itemstack)) {
flag = true;
int i = this.fallFlyTicks + 1;
@@ -2979,8 +_,11 @@
private void updatingUsingItem() {
if (this.isUsingItem()) {
- if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
- this.useItem = this.getItemInHand(this.getUsedItemHand());
+ ItemStack itemStack = this.getItemInHand(this.getUsedItemHand());
+ if (net.neoforged.neoforge.common.CommonHooks.canContinueUsing(this.useItem, itemStack)) {
+ this.useItem = itemStack;
+ }
+ if (itemStack == this.useItem) {
this.updateUsingItem(this.useItem);
} else {
this.stopUsingItem();
@@ -2989,12 +_,15 @@
}
protected void updateUsingItem(ItemStack p_147201_) {
+ if (!p_147201_.isEmpty())
+ this.useItemRemaining = net.neoforged.neoforge.event.EventHooks.onItemUseTick(this, p_147201_, this.getUseItemRemainingTicks());
+ if (this.getUseItemRemainingTicks() > 0)
p_147201_.onUseTick(this.level(), this, this.getUseItemRemainingTicks());
if (this.shouldTriggerItemUseEffects()) {
this.triggerItemUseEffects(p_147201_, 5);
}
- if (--this.useItemRemaining == 0 && !this.level().isClientSide && !p_147201_.useOnRelease()) {
+ if (--this.useItemRemaining <= 0 && !this.level().isClientSide && !p_147201_.useOnRelease()) {
this.completeUsingItem();
}
}
@@ -3029,8 +_,10 @@
public void startUsingItem(InteractionHand p_21159_) {
ItemStack itemstack = this.getItemInHand(p_21159_);
if (!itemstack.isEmpty() && !this.isUsingItem()) {
+ int duration = net.neoforged.neoforge.event.EventHooks.onItemUseStart(this, itemstack, itemstack.getUseDuration(this));
+ if (duration < 0) return; // Neo: Early return for negative values, as that indicates event cancellation.
this.useItem = itemstack;
- this.useItemRemaining = itemstack.getUseDuration(this);
+ this.useItemRemaining = duration;
if (!this.level().isClientSide) {
this.setLivingEntityFlag(1, true);
this.setLivingEntityFlag(2, p_21159_ == InteractionHand.OFF_HAND);
@@ -3111,7 +_,8 @@
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
this.triggerItemUseEffects(this.useItem, 16);
- ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this);
+ ItemStack copy = this.useItem.copy();
+ ItemStack itemstack = net.neoforged.neoforge.event.EventHooks.onItemUseFinish(this, copy, getUseItemRemainingTicks(), this.useItem.finishUsingItem(this.level(), this));
if (itemstack != this.useItem) {
this.setItemInHand(interactionhand, itemstack);
}
@@ -3136,7 +_,11 @@
public void releaseUsingItem() {
if (!this.useItem.isEmpty()) {
+ if (!net.neoforged.neoforge.event.EventHooks.onUseItemStop(this, useItem, this.getUseItemRemainingTicks())) {
+ ItemStack copy = this instanceof Player ? useItem.copy() : null;
this.useItem.releaseUsing(this.level(), this, this.getUseItemRemainingTicks());
+ if (copy != null && useItem.isEmpty()) net.neoforged.neoforge.event.EventHooks.onPlayerDestroyItem((Player)this, copy, getUsedItemHand());
+ }
if (this.useItem.useOnRelease()) {
this.updatingUsingItem();
}
@@ -3146,6 +_,7 @@
}
public void stopUsingItem() {
+ if (this.isUsingItem() && !this.useItem.isEmpty()) this.useItem.onStopUsing(this, useItemRemaining);
if (!this.level().isClientSide) {
boolean flag = this.isUsingItem();
this.setLivingEntityFlag(1, false);
@@ -3161,7 +_,7 @@
public boolean isBlocking() {
if (this.isUsingItem() && !this.useItem.isEmpty()) {
Item item = this.useItem.getItem();
- return item.getUseAnimation(this.useItem) != UseAnim.BLOCK ? false : item.getUseDuration(this.useItem, this) - this.useItemRemaining >= 5;
+ return !this.useItem.canPerformAction(net.neoforged.neoforge.common.ItemAbilities.SHIELD_BLOCK) ? false : item.getUseDuration(this.useItem, this) - this.useItemRemaining >= 5;
} else {
return false;
}
@@ -3302,8 +_,8 @@
}
BlockState blockstate = this.level().getBlockState(p_21141_);
- if (blockstate.getBlock() instanceof BedBlock) {
- this.level().setBlock(p_21141_, blockstate.setValue(BedBlock.OCCUPIED, Boolean.valueOf(true)), 3);
+ if (blockstate.isBed(level(), p_21141_, this)) {
+ blockstate.setBedOccupied(level(), p_21141_, this, true);
}
this.setPose(Pose.SLEEPING);
@@ -3318,15 +_,17 @@
}
private boolean checkBedExists() {
- return this.getSleepingPos().map(p_352707_ -> this.level().getBlockState(p_352707_).getBlock() instanceof BedBlock).orElse(false);
+ // Neo: Overwrite the vanilla instanceof BedBlock check with isBed and fire the CanContinueSleepingEvent.
+ boolean hasBed = this.getSleepingPos().map(pos -> this.level().getBlockState(pos).isBed(this.level(), pos, this)).orElse(false);
+ return net.neoforged.neoforge.event.EventHooks.canEntityContinueSleeping(this, hasBed ? null : Player.BedSleepingProblem.NOT_POSSIBLE_HERE);
}
public void stopSleeping() {
this.getSleepingPos().filter(this.level()::hasChunkAt).ifPresent(p_261435_ -> {
BlockState blockstate = this.level().getBlockState(p_261435_);
- if (blockstate.getBlock() instanceof BedBlock) {
+ if (blockstate.isBed(level(), p_261435_, this)) {
Direction direction = blockstate.getValue(BedBlock.FACING);
- this.level().setBlock(p_261435_, blockstate.setValue(BedBlock.OCCUPIED, Boolean.valueOf(false)), 3);
+ blockstate.setBedOccupied(level(), p_261435_, this, false);
Vec3 vec31 = BedBlock.findStandUpPosition(this.getType(), this.level(), p_261435_, direction, this.getYRot()).orElseGet(() -> {
BlockPos blockpos = p_261435_.above();
return new Vec3((double)blockpos.getX() + 0.5, (double)blockpos.getY() + 0.1, (double)blockpos.getZ() + 0.5);
@@ -3347,7 +_,9 @@
@Nullable
public Direction getBedOrientation() {
BlockPos blockpos = this.getSleepingPos().orElse(null);
- return blockpos != null ? BedBlock.getBedOrientation(this.level(), blockpos) : null;
+ if (blockpos == null) return Direction.UP;
+ BlockState state = this.level().getBlockState(blockpos);
+ return !state.isBed(level(), blockpos, this) ? Direction.UP : state.getBedDirection(level(), blockpos);
}
@Override
@@ -3356,11 +_,11 @@
}
public ItemStack getProjectile(ItemStack p_21272_) {
- return ItemStack.EMPTY;
+ return net.neoforged.neoforge.common.CommonHooks.getProjectile(this, p_21272_, ItemStack.EMPTY);
}
public final ItemStack eat(Level p_21067_, ItemStack p_21068_) {
- FoodProperties foodproperties = p_21068_.get(DataComponents.FOOD);
+ FoodProperties foodproperties = p_21068_.getFoodProperties(this);
return foodproperties != null ? this.eat(p_21067_, p_21068_, foodproperties) : p_21068_;
}
@@ -3411,6 +_,38 @@
return p_320526_ == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND;
}
+ /**
+ * Neo: Removes all potion effects that have the given {@link net.neoforged.neoforge.common.EffectCure} in their set of cures
+ * @param cure the EffectCure being used
+ */
+ public boolean removeEffectsCuredBy(net.neoforged.neoforge.common.EffectCure cure) {
+ if (this.level().isClientSide)
+ return false;
+ boolean ret = false;
+ Iterator<MobEffectInstance> itr = this.activeEffects.values().iterator();
+ while (itr.hasNext()) {
+ MobEffectInstance effect = itr.next();
+ if (effect.getCures().contains(cure) && !net.neoforged.neoforge.event.EventHooks.onEffectRemoved(this, effect, cure)) {
+ this.onEffectRemoved(effect);
+ itr.remove();
+ ret = true;
+ this.effectsDirty = true;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Neo: Returns true if the entity's rider (EntityPlayer) should face forward when mounted.
+ * currently only used in vanilla code by pigs.
+ *
+ * @param player The player who is riding the entity.
+ * @return If the player should orient the same direction as this entity.
+ */
+ public boolean shouldRiderFaceForward(Player player) {
+ return this instanceof net.minecraft.world.entity.animal.Pig;
+ }
+
@Override
public AABB getBoundingBoxForCulling() {
if (this.getItemBySlot(EquipmentSlot.HEAD).is(Items.DRAGON_HEAD)) {
@@ -3422,6 +_,8 @@
}
public EquipmentSlot getEquipmentSlotForItem(ItemStack p_147234_) {
+ final EquipmentSlot slot = p_147234_.getEquipmentSlot();
+ if (slot != null) return slot; // FORGE: Allow modders to set a non-default equipment slot for a stack; e.g. a non-armor chestplate-slot item
Equipable equipable = Equipable.get(p_147234_);
if (equipable != null) {
EquipmentSlot equipmentslot = equipable.getEquipmentSlot();
@@ -3507,7 +_,7 @@
}
public boolean canDisableShield() {
- return this.getWeaponItem().getItem() instanceof AxeItem;
+ return this.getMainHandItem().canDisableShield(this.useItem, this, this); // Neo: Switch to using the item to determine if disables shield instead of hardcoded Axe check
}
@Override