Skip to content

Commit

Permalink
Backport non-broken config inv mixin to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Dec 7, 2024
1 parent e511c10 commit 016c6c4
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 016c6c4

Please sign in to comment.