Skip to content

Commit

Permalink
Fix #21: View cells only accept one item at a time, config inventorie…
Browse files Browse the repository at this point in the history
…s do not persist between reloads
  • Loading branch information
62832 committed Jun 12, 2024
1 parent 4a76edd commit e12dee9
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/main/java/gripe/_90/arseng/mixin/ConfigInventoryMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

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;
Expand All @@ -21,24 +22,17 @@ 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 e12dee9

Please sign in to comment.