From 016c6c40b22d4775f60fd0db38347121d3d623e6 Mon Sep 17 00:00:00 2001 From: 90 Date: Sat, 7 Dec 2024 14:13:18 +0000 Subject: [PATCH] Backport non-broken config inv mixin to 1.19 --- .../arseng/mixin/ConfigInventoryMixin.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java b/src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java index e461ed1..8b7e05d 100644 --- a/src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java +++ b/src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java @@ -2,43 +2,32 @@ import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import appeng.api.stacks.GenericStack; -import appeng.helpers.externalstorage.GenericStackInv; import appeng.util.ConfigInventory; @Mixin(value = ConfigInventory.class, remap = false) -public abstract class ConfigInventoryMixin extends GenericStackInv { +public abstract class ConfigInventoryMixin { @Unique private GenericStack arseng$toStock; - public ConfigInventoryMixin(@Nullable Runnable listener, int size) { - super(listener, size); - } + @Shadow + @Nullable + public abstract GenericStack getStack(int slot); @Inject(method = "setStack", at = @At("HEAD")) private void rememberStack(int slot, GenericStack stack, CallbackInfo ci) { arseng$toStock = stack; } - // spotless:off - @Redirect( - method = "setStack", - at = @At( - value = "INVOKE", - target = "Lappeng/helpers/externalstorage/GenericStackInv;setStack(ILappeng/api/stacks/GenericStack;)V")) - // spotless:on - private void setForEmpty(GenericStackInv instance, int slot, GenericStack stack) { - if (arseng$toStock != null && arseng$toStock.amount() <= 0) { - var currentStack = instance.getStack(slot); - stack = currentStack == null ? new GenericStack(arseng$toStock.what(), 1) : null; - } - - super.setStack(slot, stack); + @ModifyVariable(method = "setStack", at = @At(value = "STORE", ordinal = 1), argsOnly = true) + private GenericStack handleEmptyContainer(GenericStack stack, int slot) { + return getStack(slot) == null && arseng$toStock != null ? new GenericStack(arseng$toStock.what(), 1) : null; } }