Skip to content

Commit

Permalink
Fix SpongeForge attack and furnace mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Dec 21, 2024
1 parent a35bb81 commit 061dfd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.crafting.SingleRecipeInput;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -69,7 +70,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Forge implements AbstractF
// @formatter:off
@Shadow protected NonNullList<ItemStack> items;
@Shadow int cookingProgress;
@Shadow private boolean shadow$canBurn(RegistryAccess registryAccess, @Nullable RecipeHolder<?> recipe, NonNullList<ItemStack> slots, int maxStackSize) {
@Shadow private boolean shadow$canBurn(RegistryAccess registryAccess, @Nullable RecipeHolder<?> recipe, SingleRecipeInput input, NonNullList<ItemStack> slots, int maxStackSize) {
throw new UnsupportedOperationException("Shadowed canBurn");
}
// @formatter:on
Expand All @@ -79,15 +80,16 @@ public abstract class AbstractFurnaceBlockEntityMixin_Forge implements AbstractF
// Tick up and Start
@Redirect(method = "serverTick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;canBurn(Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/world/item/crafting/RecipeHolder;Lnet/minecraft/core/NonNullList;I)Z",
target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;canBurn(Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/world/item/crafting/RecipeHolder;Lnet/minecraft/world/item/crafting/SingleRecipeInput;Lnet/minecraft/core/NonNullList;I)Z",
ordinal = 1))
private static boolean forge$checkIfCanSmelt(final AbstractFurnaceBlockEntity entityIn,
final RegistryAccess registryAccess,
final RecipeHolder<?> recipe,
final NonNullList<ItemStack> slots,
final int maxStackSize) {
final RegistryAccess registryAccess,
final RecipeHolder<?> recipe,
final SingleRecipeInput input,
final NonNullList<ItemStack> slots,
final int maxStackSize) {
final var entity = (AbstractFurnaceBlockEntityMixin_Forge) (Object) (entityIn);
if (!entity.shadow$canBurn(registryAccess, recipe, slots, maxStackSize)) {
if (!entity.shadow$canBurn(registryAccess, recipe, input, slots, maxStackSize)) {
return false;
}

Expand All @@ -111,7 +113,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Forge implements AbstractF
// Tick down
@Redirect(method = "serverTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(III)I"))
private static int forge$resetCookTimeIfCancelled(final int newCookTime, final int zero, final int totalCookTime,
final Level level, final BlockPos entityPos, final BlockState state, final AbstractFurnaceBlockEntity entityIn) {
final ServerLevel level, final BlockPos entityPos, final BlockState state, final AbstractFurnaceBlockEntity entityIn) {
final int clampedCookTime = Mth.clamp(newCookTime, zero, totalCookTime);
final var entity = (AbstractFurnaceBlockEntityMixin_Forge) (Object) entityIn;
final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(entity.items.get(1));
Expand All @@ -133,7 +135,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Forge implements AbstractF
slice = @Slice(
from = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/Blocks;WET_SPONGE:Lnet/minecraft/world/level/block/Block;", opcode = Opcodes.GETSTATIC)
))
private void forge$captureBucketFill(final RegistryAccess registryAccess, final RecipeHolder<?> recipe, final NonNullList<ItemStack> slots, final int maxStackSize, final CallbackInfoReturnable<Boolean> cir) {
private void forge$captureBucketFill(final RegistryAccess registryAccess, final RecipeHolder<?> recipe, final SingleRecipeInput input, final NonNullList<ItemStack> slots, final int maxStackSize, final CallbackInfoReturnable<Boolean> cir) {
this.forge$filledWaterBucket = true;
}

Expand All @@ -142,7 +144,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Forge implements AbstractF
locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"))
private void forge$afterSmeltItem(
final RegistryAccess registryAccess, final RecipeHolder<?> recipe,
final RegistryAccess registryAccess, final RecipeHolder<?> recipe, final SingleRecipeInput input,
final NonNullList<ItemStack> slots, final int maxStackSize,
final CallbackInfoReturnable<Boolean> cir,
final ItemStack itemIn, final ItemStack recipeResult, final ItemStack itemOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.bridge.world.entity.LivingEntityBridge;
import org.spongepowered.common.event.tracking.PhaseTracker;
Expand Down Expand Up @@ -170,14 +169,10 @@ public abstract class LivingEntityMixin_Attack_Impl extends EntityMixin implemen
* After calling #actuallyHurt (even when invulnerable), if cancelled return early or is still invulnerable
* and reset {@link #lastHurt} and {@link #invulnerableTime}
*/
@Inject(method = "hurtServer", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true,
@Inject(method = "hurtServer", cancellable = true,
at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 0,
target = "Lnet/minecraft/world/entity/LivingEntity;actuallyHurt(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;F)V"))
private void attackImpl$afterActuallyHurt1(
final ServerLevel level, final DamageSource source, final float damageTaken,
final CallbackInfoReturnable<Boolean> cir, final float dealtDamage, final boolean isBlocked,
float $$5, boolean wasHurt
) {
private void attackImpl$afterActuallyHurt1(final ServerLevel level, final DamageSource source, final float damageTaken, final CallbackInfoReturnable<Boolean> cir) {
if (this.attackImpl$actuallyHurtCancelled || damageTaken <= this.lastHurt) {
this.invulnerableTime = this.attackImpl$InvulnerableTime;
this.lastHurt = this.attackImpl$lastHurt;
Expand All @@ -189,7 +184,7 @@ public abstract class LivingEntityMixin_Attack_Impl extends EntityMixin implemen
* After calling #actuallyHurt, if cancelled return early
* Also reset values
*/
@Inject(method = "hurtServer",cancellable = true,
@Inject(method = "hurtServer", cancellable = true,
at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1,
target = "Lnet/minecraft/world/entity/LivingEntity;actuallyHurt(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;F)V"))
private void attackImpl$afterActuallyHurt2(ServerLevel $$0, DamageSource $$1, float $$2, CallbackInfoReturnable<Boolean> cir) {
Expand Down

0 comments on commit 061dfd0

Please sign in to comment.