Skip to content

Commit f3f99ac

Browse files
committed
fix: mixins issues with the mod YAWP fixes #7
1 parent 709c534 commit f3f99ac

10 files changed

Lines changed: 93 additions & 59 deletions

File tree

patches/net/minecraft/server/level/ServerPlayer.java.patch

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,43 +606,49 @@
606606
this.setShiftKeyDown(p_8984_);
607607
}
608608
}
609-
@@ -1185,19 +_,19 @@
609+
@@ -1185,19 +_,22 @@
610610
int i = Math.round((float)Math.sqrt(p_308996_ * p_308996_ + p_309062_ * p_309062_ + p_309170_ * p_309170_) * 100.0F);
611611
if (i > 0) {
612612
this.awardStat(Stats.SWIM_ONE_CM, i);
613613
- this.causeFoodExhaustion(0.01F * (float)i * 0.01F);
614-
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)i * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.SWIM); // CraftBukkit - EntityExhaustionEvent // Spigot
614+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.SWIM); // Magma
615+
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)i * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
615616
}
616617
} else if (this.isEyeInFluid(FluidTags.WATER)) {
617618
int j = Math.round((float)Math.sqrt(p_308996_ * p_308996_ + p_309062_ * p_309062_ + p_309170_ * p_309170_) * 100.0F);
618619
if (j > 0) {
619620
this.awardStat(Stats.WALK_UNDER_WATER_ONE_CM, j);
620621
- this.causeFoodExhaustion(0.01F * (float)j * 0.01F);
621-
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)j * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // CraftBukkit - EntityExhaustionEvent // Spigot
622+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // Magma
623+
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)j * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
622624
}
623625
} else if (this.isInWater()) {
624626
int k = Math.round((float)Math.sqrt(p_308996_ * p_308996_ + p_309170_ * p_309170_) * 100.0F);
625627
if (k > 0) {
626628
this.awardStat(Stats.WALK_ON_WATER_ONE_CM, k);
627629
- this.causeFoodExhaustion(0.01F * (float)k * 0.01F);
628-
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)k * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // CraftBukkit - EntityExhaustionEvent // Spigot
630+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // Magma
631+
+ this.causeFoodExhaustion(this.level().spigotConfig.swimMultiplier * (float)k * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
629632
}
630633
} else if (this.onClimbable()) {
631634
if (p_309062_ > 0.0) {
632-
@@ -1208,13 +_,13 @@
635+
@@ -1208,13 +_,16 @@
633636
if (l > 0) {
634637
if (this.isSprinting()) {
635638
this.awardStat(Stats.SPRINT_ONE_CM, l);
636639
- this.causeFoodExhaustion(0.1F * (float)l * 0.01F);
637-
+ this.causeFoodExhaustion(this.level().spigotConfig.sprintMultiplier * (float)l * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.SPRINT); // CraftBukkit - EntityExhaustionEvent // Spigot
640+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.SPRINT); // Magma
641+
+ this.causeFoodExhaustion(this.level().spigotConfig.sprintMultiplier * (float)l * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
638642
} else if (this.isCrouching()) {
639643
this.awardStat(Stats.CROUCH_ONE_CM, l);
640644
- this.causeFoodExhaustion(0.0F * (float)l * 0.01F);
641-
+ this.causeFoodExhaustion(this.level().spigotConfig.otherMultiplier * (float)l * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.CROUCH); // CraftBukkit - EntityExhaustionEvent // Spigot
645+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.CROUCH); // Magma
646+
+ this.causeFoodExhaustion(this.level().spigotConfig.otherMultiplier * (float)l * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
642647
} else {
643648
this.awardStat(Stats.WALK_ONE_CM, l);
644649
- this.causeFoodExhaustion(0.0F * (float)l * 0.01F);
645-
+ this.causeFoodExhaustion(this.level().spigotConfig.otherMultiplier * (float)l * 0.01F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK); // CraftBukkit - EntityExhaustionEvent // Spigot
650+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.WALK); // Magma
651+
+ this.causeFoodExhaustion(this.level().spigotConfig.otherMultiplier * (float)l * 0.01F); // CraftBukkit - EntityExhaustionEvent // Spigot
646652
}
647653
}
648654
} else if (this.isFallFlying()) {
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
--- a/net/minecraft/world/effect/HungerMobEffect.java
22
+++ b/net/minecraft/world/effect/HungerMobEffect.java
3-
@@ -11,7 +_,7 @@
3+
@@ -11,6 +_,7 @@
44
@Override
55
public boolean applyEffectTick(LivingEntity p_296407_, int p_296356_) {
66
if (p_296407_ instanceof Player player) {
7-
- player.causeFoodExhaustion(0.005F * (float)(p_296356_ + 1));
8-
+ player.causeFoodExhaustion(0.005F * (float)(p_296356_ + 1), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.HUNGER_EFFECT); // CraftBukkit - EntityExhaustionEvent
7+
+ player.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.HUNGER_EFFECT); // Magma
8+
player.causeFoodExhaustion(0.005F * (float)(p_296356_ + 1));
99
}
1010

11-
return true;

patches/net/minecraft/world/entity/LivingEntity.java.patch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@
954954
}
955955

956956
return p_21194_;
957-
@@ -1677,13 +_,221 @@
957+
@@ -1677,13 +_,222 @@
958958
}
959959
}
960960

@@ -1116,7 +1116,8 @@
11161116
+ if (f > 0 || !human) {
11171117
+ if (human) {
11181118
+ // PAIL: Be sure to drag all this code from the Player subclass each update.
1119-
+ ((Player) this).causeFoodExhaustion(damagesource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
1119+
+ ((Player) this).setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // Magma
1120+
+ ((Player) this).causeFoodExhaustion(damagesource.getFoodExhaustion());
11201121
+ if (f < 3.4028235E37F) {
11211122
+ ((Player) this).awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
11221123
+ }

patches/net/minecraft/world/entity/player/Player.java.patch

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
if (this.useItem.isEmpty()) {
321321
if (interactionhand == InteractionHand.MAIN_HAND) {
322322
this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
323-
@@ -949,20 +_,35 @@
323+
@@ -949,19 +_,35 @@
324324
}
325325
}
326326

@@ -358,11 +358,10 @@
358358
}
359359

360360
if (f1 != 0.0F) {
361-
- this.causeFoodExhaustion(p_36312_.getFoodExhaustion());
362-
+ this.causeFoodExhaustion(p_36312_.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
361+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // Magma
362+
this.causeFoodExhaustion(p_36312_.getFoodExhaustion());
363363
this.getCombatTracker().recordDamage(p_36312_, f1);
364364
this.setHealth(this.getHealth() - f1);
365-
if (f1 < 3.4028235E37F) {
366365
@@ -970,7 +_,9 @@
367366
}
368367

@@ -535,12 +534,13 @@
535534
if (itemstack == this.getMainHandItem()) {
536535
this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
537536
} else {
538-
@@ -1305,12 +_,18 @@
537+
@@ -1305,12 +_,19 @@
539538
}
540539
}
541540

542541
- this.causeFoodExhaustion(0.1F);
543-
+ this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot
542+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.ATTACK); // Magma
543+
+ this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion);
544544
} else {
545545
this.level()
546546
.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
@@ -592,15 +592,17 @@
592592
super.stopSleeping();
593593
if (this.level() instanceof ServerLevel && p_36227_) {
594594
((ServerLevel)this.level()).updateSleepingPlayerList();
595-
@@ -1452,9 +_,9 @@
595+
@@ -1452,9 +_,11 @@
596596
super.jumpFromGround();
597597
this.awardStat(Stats.JUMP);
598598
if (this.isSprinting()) {
599599
- this.causeFoodExhaustion(0.2F);
600-
+ this.causeFoodExhaustion(this.level().spigotConfig.jumpSprintExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent // Spigot
600+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // Magma
601+
+ this.causeFoodExhaustion(this.level().spigotConfig.jumpSprintExhaustion);
601602
} else {
602603
- this.causeFoodExhaustion(0.05F);
603-
+ this.causeFoodExhaustion(this.level().spigotConfig.jumpWalkExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent // Spigot
604+
+ this.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.JUMP); // Magma
605+
+ this.causeFoodExhaustion(this.level().spigotConfig.jumpWalkExhaustion);
604606
}
605607
}
606608

@@ -711,22 +713,23 @@
711713
this.experienceLevel += p_36276_;
712714
if (this.experienceLevel < 0) {
713715
this.experienceLevel = 0;
714-
@@ -1661,10 +_,21 @@
716+
@@ -1661,10 +_,22 @@
715717
}
716718
}
717719

718-
+ // CraftBukkit start
719-
public void causeFoodExhaustion(float p_36400_) {
720-
+ this.causeFoodExhaustion(p_36400_, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.UNKNOWN);
720+
+ // Magma start - mixin support
721+
+ private org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason magma$ExhaustionReason = org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.UNKNOWN;
722+
+ public void setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason reason) {
723+
+ magma$ExhaustionReason = reason;
721724
+ }
722725
+
723-
+ public void causeFoodExhaustion(float p_36400_, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason reason) {
724-
+ // CraftBukkit end
726+
public void causeFoodExhaustion(float p_36400_) {
725727
if (!this.abilities.invulnerable) {
726728
if (!this.level().isClientSide) {
727729
- this.foodData.addExhaustion(p_36400_);
728730
+ // CraftBukkit start
729-
+ org.bukkit.event.entity.EntityExhaustionEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerExhaustionEvent(this, reason, p_36400_);
731+
+ org.bukkit.event.entity.EntityExhaustionEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerExhaustionEvent(this, magma$ExhaustionReason, p_36400_);
732+
+ magma$ExhaustionReason = org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.UNKNOWN;
730733
+ if (!event.isCancelled()) {
731734
+ this.foodData.addExhaustion(event.getExhaustion());
732735
+ }

patches/net/minecraft/world/food/FoodData.java.patch

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
public void tick(Player p_38711_) {
4343
Difficulty difficulty = p_38711_.level().getDifficulty();
4444
this.lastFoodLevel = this.foodLevel;
45-
@@ -38,29 +_,39 @@
45+
@@ -38,29 +_,41 @@
4646
if (this.saturationLevel > 0.0F) {
4747
this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F);
4848
} else if (difficulty != Difficulty.PEACEFUL) {
@@ -69,7 +69,8 @@
6969
- this.addExhaustion(f);
7070
+ entityhuman.setHealRegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // Magma - add regain reason
7171
+ entityhuman.heal(f / 6.0F);
72-
+ entityhuman.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent
72+
+ entityhuman.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // Magma
73+
+ entityhuman.causeFoodExhaustion(f);
7374
this.tickTimer = 0;
7475
}
7576
} else if (flag && this.foodLevel >= 18 && p_38711_.isHurt()) {
@@ -80,7 +81,8 @@
8081
+ if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation
8182
+ entityhuman.setHealRegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // Magma - add regain reason
8283
+ entityhuman.heal(1.0F);
83-
+ entityhuman.causeFoodExhaustion(entityhuman.level().spigotConfig.regenExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent // Spigot
84+
+ entityhuman.setExhaustionReason(org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // Magma
85+
+ entityhuman.causeFoodExhaustion(entityhuman.level().spigotConfig.regenExhaustion);
8486
this.tickTimer = 0;
8587
}
8688
} else if (this.foodLevel <= 0) {

patches/net/minecraft/world/item/BucketItem.java.patch

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,61 @@
2626
if (!p_40703_.isClientSide) {
2727
CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer)p_40704_, itemstack3);
2828
}
29-
@@ -72,8 +_,8 @@
29+
@@ -72,8 +_,9 @@
3030
return InteractionResultHolder.fail(itemstack);
3131
} else {
3232
BlockState blockstate = p_40703_.getBlockState(blockpos);
3333
- BlockPos blockpos2 = blockstate.getBlock() instanceof LiquidBlockContainer && this.content == Fluids.WATER ? blockpos : blockpos1;
3434
- if (this.emptyContents(p_40704_, p_40703_, blockpos2, blockhitresult)) {
3535
+ BlockPos blockpos2 = canBlockContainFluid(p_40704_, p_40703_, blockpos, blockstate) ? blockpos : blockpos1;
36-
+ if (this.emptyContents(p_40704_, p_40703_, blockpos2, blockhitresult, itemstack, blockhitresult.getDirection(), blockpos, itemstack, p_40705_)) { // CraftBukkit
36+
+ this.setCBContents(blockhitresult.getDirection(), blockpos, itemstack, p_40705_); // Magma
37+
+ if (this.emptyContents(p_40704_, p_40703_, blockpos2, blockhitresult, itemstack)) {
3738
this.checkExtraContent(p_40704_, p_40703_, itemstack, blockpos2);
3839
if (p_40704_ instanceof ServerPlayer) {
3940
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)p_40704_, blockpos2, itemstack);
40-
@@ -98,7 +_,17 @@
41+
@@ -98,7 +_,33 @@
4142
}
4243

4344
@Override
4445
+ @Deprecated // Neo: use the ItemStack sensitive version
4546
public boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_) {
4647
+ return this.emptyContents(p_150716_, p_150717_, p_150718_, p_150719_, null);
4748
+ }
48-
+ public boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container) {
49-
+ // CraftBukkit start
50-
+ return emptyContents(p_150716_, p_150717_, p_150718_, p_150719_,container, null, null, null, InteractionHand.MAIN_HAND);
49+
+
50+
+ // Magma start - mixin support
51+
+ private Direction magma$enumdirection = null;
52+
+ private BlockPos magma$clicked = null;
53+
+ private ItemStack magma$itemstack = null;
54+
+ private InteractionHand magma$enumhand = net.minecraft.world.InteractionHand.MAIN_HAND;
55+
+
56+
+ public void setCBContents(Direction enumdirection, BlockPos clicked, ItemStack itemstack, InteractionHand enumhand){
57+
+ magma$enumdirection = enumdirection;
58+
+ magma$clicked = clicked;
59+
+ magma$itemstack = itemstack;
60+
+ magma$enumhand = enumhand;
5161
+ }
5262
+
53-
+ public boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container, Direction enumdirection, BlockPos clicked, ItemStack itemstack, InteractionHand enumhand) {
54-
+ // CraftBukkit end
63+
+ private void resetCB() {
64+
+ magma$enumdirection = null;
65+
+ magma$clicked = null;
66+
+ magma$itemstack = null;
67+
+ magma$enumhand = net.minecraft.world.InteractionHand.MAIN_HAND;
68+
+ }
69+
+ // Magma end
70+
+
71+
+ public boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container) {
5572
if (!(this.content instanceof FlowingFluid flowingfluid)) {
5673
return false;
5774
} else {
58-
@@ -125,8 +_,22 @@
75+
@@ -125,8 +_,24 @@
5976
}
6077

6178
boolean flag1 = flag2;
6279
+ java.util.Optional<net.neoforged.neoforge.fluids.FluidStack> containedFluidStack = java.util.Optional.ofNullable(container).flatMap(net.neoforged.neoforge.fluids.FluidUtil::getFluidContained);
6380
+ // CraftBukkit start
6481
+ if (flag1 && p_150716_ != null) {
65-
+ org.bukkit.event.player.PlayerBucketEmptyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBucketEmptyEvent((net.minecraft.server.level.ServerLevel) p_150717_, p_150716_, p_150718_, clicked, enumdirection, itemstack, enumhand);
82+
+ org.bukkit.event.player.PlayerBucketEmptyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBucketEmptyEvent((net.minecraft.server.level.ServerLevel) p_150717_, p_150716_, p_150718_, magma$clicked, magma$enumdirection, magma$itemstack, magma$enumhand);
83+
+ resetCB();
6684
+ if (event.isCancelled()) {
6785
+ ((ServerPlayer) p_150716_).connection.send(new net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket(p_150717_, p_150718_)); // SPIGOT-4238: needed when looking through entity
6886
+ ((ServerPlayer) p_150716_).getBukkitEntity().updateInventory(); // SPIGOT-4541
@@ -72,7 +90,8 @@
7290
+ // CraftBukkit end
7391
if (!flag1) {
7492
- return p_150719_ != null && this.emptyContents(p_150716_, p_150717_, p_150719_.getBlockPos().relative(p_150719_.getDirection()), null);
75-
+ return p_150719_ != null && this.emptyContents(p_150716_, p_150717_, p_150719_.getBlockPos().relative(p_150719_.getDirection()), null, container, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
93+
+ this.setCBContents(magma$enumdirection, magma$clicked, magma$itemstack, magma$enumhand);
94+
+ return p_150719_ != null && this.emptyContents(p_150716_, p_150717_, p_150719_.getBlockPos().relative(p_150719_.getDirection()), null, container);
7695
+ } else if (containedFluidStack.isPresent() && this.content.getFluidType().isVaporizedOnPlacement(p_150717_, p_150718_, containedFluidStack.get())) {
7796
+ this.content.getFluidType().onVaporize(p_150716_, p_150717_, p_150718_, containedFluidStack.get());
7897
+ return true;

0 commit comments

Comments
 (0)