Skip to content

Commit bbbdc33

Browse files
add null checks to invwrapper mixins (#98)
* add null checks to invwrapper mixins * remove excess getStackInSlot calls
1 parent b83b0ad commit bbbdc33

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/main/java/club/sk1er/patcher/mixins/performance/forge/InvWrapperMixin_ImproveInsertion.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public class InvWrapperMixin_ImproveInsertion {
2222

2323
@Inject(method = "insertItem", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/items/ItemHandlerHelper;canItemStacksStack(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"), cancellable = true)
2424
private void patcher$earlyExit(int slot, ItemStack stack, boolean simulate, CallbackInfoReturnable<ItemStack> cir) {
25+
if (this.inv == null) return;
2526
ItemStack stackInSlot = this.inv.getStackInSlot(slot);
27+
if (stackInSlot == null) return;
2628
if (stackInSlot.stackSize >= Math.min(stackInSlot.getMaxStackSize(), this.inv.getInventoryStackLimit())) {
2729
cir.setReturnValue(stack);
2830
}

src/main/java/club/sk1er/patcher/mixins/performance/forge/SidedInvWrapperMixin_ImproveInsertion.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public class SidedInvWrapperMixin_ImproveInsertion {
2424

2525
@Inject(method = "insertItem", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/items/ItemHandlerHelper;canItemStacksStack(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z", shift = At.Shift.BEFORE), cancellable = true)
2626
private void patcher$earlyExit(int slot, ItemStack stack, boolean simulate, CallbackInfoReturnable<ItemStack> cir) {
27+
if (this.inv == null) return;
2728
ItemStack stackInSlot = this.inv.getStackInSlot(slot);
29+
if (stackInSlot == null) return;
2830
if (stackInSlot.stackSize >= Math.min(stackInSlot.getMaxStackSize(), this.inv.getInventoryStackLimit())) {
2931
cir.setReturnValue(stack);
3032
}

0 commit comments

Comments
 (0)