Skip to content

Commit

Permalink
do not rely on mod not overriding getSizeInventory
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Oct 1, 2017
1 parent bc80b91 commit 4a809dc
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -49,25 +50,24 @@
@Implements(value = @Interface(iface = MinecraftInventoryAdapter.class, prefix = "inventory$"))
public abstract class MixinInventoryCrafting implements IInventory, LensProvider<IInventory, ItemStack> {

@Shadow private NonNullList<ItemStack> stackList;
protected Fabric<IInventory> fabric;
protected SlotCollection slots;
protected Lens<IInventory, ItemStack> lens;

@Shadow public abstract int getSizeInventory();

@Inject(method = "<init>", at = @At("RETURN"))
public void onConstructed(CallbackInfo ci) {
this.fabric = new DefaultInventoryFabric(this);
this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
this.slots = new SlotCollection.Builder().add(this.stackList.size()).build();
this.lens = getRootLens(fabric, ((InventoryAdapter) this));
}

@Override
public Lens<IInventory, ItemStack> getRootLens(Fabric<IInventory> fabric, InventoryAdapter<IInventory, ItemStack> adapter) {
if (this.getSizeInventory() == 0) {
if (this.stackList.size() == 0) {
return null; // No Lens when inventory has no slots
}
return new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, this.slots);
return new OrderedInventoryLensImpl(0, this.stackList.size(), 1, this.slots);
}

public SlotProvider<IInventory, ItemStack> inventory$getSlotProvider() {
Expand Down

0 comments on commit 4a809dc

Please sign in to comment.