Jump to content

Recommended Posts

Posted

Hey there!

 

So updating my mod to the latest forge version, I seem to get this crash when I open up my containers:

java.util.concurrent.ExecutionException: java.lang.RuntimeException: Slot 6 not in valid range - [0,6)
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_91]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_91]
at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
Caused by: java.lang.RuntimeException: Slot -1 not in valid range - [0,6)
at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:209) ~[itemStackHandler.class:?]
at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:75) ~[itemStackHandler.class:?]
at com.github.dynamicgenerators.inventory.slot.SlotCustomItemHandler.getStack(SlotCustomItemHandler.java:39) ~[slotCustomItemHandler.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:64) ~[Container.class:?]
at net.minecraft.inventory.Container.addListener(Container.java:53) ~[Container.class:?]
at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:100) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2733) ~[EntityPlayer.class:?]
at com.github.dynamicgenerators.blocks.BlockInfuser.onBlockActivated(BlockInfuser.java:47) ~[blockInfuser.class:?]
at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:474) ~[PlayerInteractionManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:712) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_91]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_91]
at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?]
... 5 more

 

Here is the code for the container:

public class ContainerInfuser extends Container {

    public final TileEntityInfuser infuser;

    public ContainerInfuser(InventoryPlayer inventoryPlayer, TileEntityBase tileEntityBase) {
        this.infuser = (TileEntityInfuser)tileEntityBase;

        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_INPUT, 80, 20)); //todo forloop
        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD, 100, 20));
        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_1, 120, 20));
        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_2, 140, 20));
        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_3, 160, 20));
        this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_4, 180, 20));

        this.addSlotToContainer(new SlotOutput(this.infuser.slots, TileEntityInfuser.SLOT_OUTPUT, 80, 5));

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 9; j++){
                this.addSlotToContainer(new Slot(inventoryPlayer, j+i*9+9, 8+j*18, 97+i*18));
            }
        }
        for(int i = 0; i < 9; i++){
            this.addSlotToContainer(new Slot(inventoryPlayer, i, 8+i*18, 155));
        }
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slot){
        int inventoryStart = 7;
        int inventoryEnd = inventoryStart+26;
        int hotbarStart = inventoryEnd+1;
        int hotbarEnd = hotbarStart+8;

        Slot theSlot = this.inventorySlots.get(slot);

        if(theSlot != null && theSlot.getHasStack()){
            ItemStack newStack = theSlot.getStack();
            ItemStack currentStack = newStack.copy();
            if(slot == TileEntityInfuser.SLOT_OUTPUT){
                if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
                    return StackUtil.getNull();
                }
                theSlot.onSlotChange(newStack, currentStack);
            }
            else if(slot >= inventoryStart){
                if(InfuserRecipeHandler.getRecipeFromInputs(newStack, newStack, newStack, newStack, newStack, newStack) != null){
                    if(!this.mergeItemStack(newStack, TileEntityInfuser.SLOT_INPUT, TileEntityInfuser.SLOT_INPUT+1, false)){
                        {
                            return StackUtil.getNull();
                        }
                    }
                }
                else if(slot >= inventoryStart && slot <= inventoryEnd){
                    if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
                        return StackUtil.getNull();
                    }
                }
                else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
                    return StackUtil.getNull();
                }
            }
            else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
                return StackUtil.getNull();
            }

            if(!StackUtil.isValid(newStack)){
                theSlot.putStack(StackUtil.getNull());
            }
            else{
                theSlot.onSlotChanged();
            }

            if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
                return StackUtil.getNull();
            }
            theSlot.onTake(player, newStack);

            return currentStack;
        }
        return StackUtil.getNull();
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn) {
        return infuser.canPlayerUse(playerIn);
    }
}

 

And here is the 'CustomSlot'

public class SlotCustomItemHandler extends SlotItemHandler{

    private final ItemStackHandlerCustom handler;

    public SlotCustomItemHandler(ItemStackHandlerCustom handler, int index, int xPosition, int yPosition){
        super(handler, index, xPosition, yPosition);
        this.handler = handler;
    }

    @Override
    public boolean isItemValid(ItemStack stack){
        if(StackUtil.isValid(stack)){
            ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex());
            this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY);
            ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), stack, true);
            this.handler.setStackInSlot(this.getSlotIndex(), currentStack);
            return remainder == null || remainder.getCount() < stack.getCount();
        }
        return false;
    }

    @Override
    @Nonnull
    public ItemStack getStack(){
        return this.handler.getStackInSlot(this.getSlotIndex());
    }

    @Override
    public void putStack(ItemStack stack){
        this.handler.setStackInSlot(this.getSlotIndex(), stack);
        this.onSlotChanged();
    }

    @Override
    public int getItemStackLimit(ItemStack stack){
        ItemStack maxAdd = stack.copy();
        maxAdd.setCount(stack.getMaxStackSize());
        ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex());
        this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY);
        ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), maxAdd, true);
        this.handler.setStackInSlot(this.getSlotIndex(), currentStack);
        return stack.getMaxStackSize()-remainder.getCount();
    }

    @Override
    public boolean canTakeStack(EntityPlayer playerIn){
        return !this.handler.extractItemInternal(this.getSlotIndex(), 1, true).isEmpty();
    }

    @Override
    public ItemStack decrStackSize(int amount){
        return this.handler.extractItemInternal(this.getSlotIndex(), amount, false);
    }
}

 

And it crashes at:

    @Override
    @Nonnull
    public ItemStack getStack(){
        return this.handler.getStackInSlot(this.getSlotIndex());
    }

 

Thanks.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.