Jump to content

Can't add more than two slots to Container 1.16.5


RoggyMan01

Recommended Posts

I'm working on a tile entity, and I'm struggling with the fact that I can't add more than two slots to the container, whenever I try to addSlot with index = 2, and I right click the block, it crashes with the error message: Slot 2 is out of range [0-2). Help would be appreciated. This is the part where I think the error is:

public BasicGemFusionBenchContainer(int windowID, World world, BlockPos pos,
                                        PlayerInventory playerInventory, PlayerEntity player) {
        super(ModContainers.BASIC_GEM_FUSION_BENCH_CONTAINER.get(), windowID);
        this.tileEntity = world.getBlockEntity(pos);
        playerEntity = player;
        this.playerInventory = new InvWrapper(playerInventory);

        layoutPlayerInventorySlots(8,86);

        if(tileEntity != null) {
            tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h ->{
                addSlot(new SlotItemHandler(h,0,60,25));
                addSlot(new SlotItemHandler(h,1,100,25));
                addSlot(new SlotItemHandler(h,2,80,50));

            });
        }
    }

 

Link to comment
Share on other sites

public class BasicGemFusionBenchTile extends TileEntity {

    private final ItemStackHandler itemHandler = createHandler();
    private final LazyOptional<IItemHandler> handler = LazyOptional.of(() -> itemHandler);

    public BasicGemFusionBenchTile(TileEntityType<?> tileEntityTypeIn) {
        super(tileEntityTypeIn);
    }

    public BasicGemFusionBenchTile() {
        this(ModTileEntities.BASIC_GEM_FUSION_BENCH_TILE.get());
    }

    @Override
    public void load(BlockState state, CompoundNBT nbt) {
        itemHandler.deserializeNBT(nbt.getCompound("inv"));
        super.load(state, nbt);
    }

    @Override
    public CompoundNBT save(CompoundNBT compound) {
        compound.put("inv", itemHandler.serializeNBT());
        return super.save(compound);
    }


    private ItemStackHandler createHandler(){
        return new ItemStackHandler(3){
                @Override
                protected void onContentsChanged(int slot){
                      setChanged();
                      gemsCombined();
                }

            @Override
            public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
                    switch (slot){
                        case 0: return stack.getItem() == ModItems.HEAVYSTONE.get() ||
                                stack.getItem() == ModItems.SWIFTSTONE.get() ||
                                stack.getItem() == ModItems.FIRESTONE.get();

                        case 1: return stack.getItem() == ModItems.HEAVYSTONE.get() ||
                                stack.getItem() == ModItems.SWIFTSTONE.get() ||
                                stack.getItem() == ModItems.FIRESTONE.get();

                        case 2: return stack.getItem() == Items.BLAZE_POWDER;

                        default:
                            return false;
                    }
            }

            @Nonnull
            @Override
            public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
                if (!isItemValid(slot,stack)){
                    return stack;
                }

                    return super.insertItem(slot, stack, simulate);
            }
        };
    }

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return handler.cast();
        }

        return super.getCapability(cap, side);
    }

    public void gemsCombined(){
        Item slot1 = this.itemHandler.getStackInSlot(0).getItem();
        Item slot2 = this.itemHandler.getStackInSlot(1).getItem();

        if((slot1 == ModItems.FIRESTONE.get() && slot2 == ModItems.HEAVYSTONE.get()) ||
                (slot2 == ModItems.FIRESTONE.get() && slot1 == ModItems.HEAVYSTONE.get())){
            //SUGILITE
        } else if ((slot1 == ModItems.SWIFTSTONE.get() && slot2 == ModItems.HEAVYSTONE.get()) ||
                (slot2 == ModItems.SWIFTSTONE.get() && slot1 == ModItems.HEAVYSTONE.get())){
            //PERIDOT
        } else if((slot1 == ModItems.FIRESTONE.get() && slot2 == ModItems.SWIFTSTONE.get()) ||
                (slot2 == ModItems.FIRESTONE.get() && slot1 == ModItems.SWIFTSTONE.get())){
            //AMBER
        }
        else{
            //eh
        }



    }
}

 

Link to comment
Share on other sites

java.lang.RuntimeException: Slot 2 not in valid range - [0,2)
	at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:221) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:73) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getItem(SlotItemHandler.java:54) ~[forge:?] {re:classloading}
	at net.minecraft.inventory.container.Container.getItems(Container.java:112) ~[forge:?] {re:classloading}
	at net.minecraft.inventory.container.Container.addSlotListener(Container.java:98) ~[forge:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:232) ~[forge:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:192) ~[forge:?] {re:classloading}
	at net.roggyman.forceofgems.block.custom.BasicGemFusionBenchBlock.use(BasicGemFusionBenchBlock.java:46) ~[?:?] {re:classloading}
	at net.minecraft.block.AbstractBlock$AbstractBlockState.use(AbstractBlock.java:640) ~[forge:?] {re:classloading}
	at net.minecraft.server.management.PlayerInteractionManager.useItemOn(PlayerInteractionManager.java:338) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.handleUseItemOn(ServerPlayNetHandler.java:958) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.handle(CPlayerTryUseItemOnBlockPacket.java:36) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.handle(CPlayerTryUseItemOnBlockPacket.java:12) ~[forge:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$ensureRunningOnSameThread$0(PacketThreadUtil.java:19) ~[forge:?] {re:classloading}
	at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:17) ~[forge:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.doRunTask(ThreadTaskExecutor.java:136) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.doRunTask(RecursiveEventLoop.java:22) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:734) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:159) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.pollTask(ThreadTaskExecutor.java:109) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:717) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:711) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.managedBlock(ThreadTaskExecutor.java:119) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:697) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:646) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202] {}
[10:43:30] [Server thread/FATAL] [ne.mi.co.ForgeMod/]: Preparing crash report with UUID 5a43420c-a45c-405d-83b9-787646112246
[10:43:30] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Ticking entity
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:855) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:787) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tickServer(IntegratedServer.java:78) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:642) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202] {}
Caused by: java.lang.RuntimeException: Slot 2 not in valid range - [0,2)
	at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:221) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:73) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getItem(SlotItemHandler.java:54) ~[forge:?] {re:classloading}
	at net.minecraft.inventory.container.Container.broadcastChanges(Container.java:120) ~[forge:?] {re:classloading}
	at net.minecraft.entity.player.ServerPlayerEntity.tick(ServerPlayerEntity.java:360) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tickNonPassenger(ServerWorld.java:611) ~[forge:?] {re:classloading}
Caused by: java.lang.RuntimeException: Slot 2 not in valid range - [0,2)

	at net.minecraft.world.World.guardEntityTick(World.java:554) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:404) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:851) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	... 5 more
[10:43:30] [Server thread/ERROR] [minecraft/MinecraftServer]: This crash report has been saved to: C:\Users\Usuari\Desktop\RUMBA\modding\Force Of Gems\run\.\crash-reports\crash-2022-01-31_10.43.30-server.txt
[10:43:30] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server
[10:43:30] [Server thread/INFO] [minecraft/MinecraftServer]: Saving players
[10:43:30] [Server thread/INFO] [minecraft/ServerPlayNetHandler]: Dev lost connection: Disconnected
[10:43:30] [Server thread/INFO] [minecraft/MinecraftServer]: Dev left the game
[10:43:30] [Server thread/ERROR] [minecraft/MinecraftServer]: Exception stopping the server
java.lang.IllegalStateException: Removing entity while ticking!
	at net.minecraft.world.server.ServerWorld.removeEntity(ServerWorld.java:947) ~[forge:?] {re:classloading}
	at net.minecraft.world.server.ServerWorld.removePlayer(ServerWorld.java:968) ~[forge:?] {re:classloading}
	at net.minecraft.world.server.ServerWorld.removePlayerImmediately(ServerWorld.java:964) ~[forge:?] {re:classloading}
	at net.minecraft.server.management.PlayerList.remove(PlayerList.java:339) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.onDisconnect(ServerPlayNetHandler.java:1021) ~[forge:?] {re:classloading}
	at net.minecraft.network.NetworkManager.handleDisconnection(NetworkManager.java:368) ~[forge:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.executeBlocking(ThreadTaskExecutor.java:72) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.network.play.ServerPlayNetHandler.disconnect(ServerPlayNetHandler.java:296) ~[forge:?] {re:classloading}
	at net.minecraft.server.management.PlayerList.removeAll(PlayerList.java:742) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:557) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:167) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:679) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202] {}
[10:43:30] [Render thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:realStdoutPrintln:123]: ---- Minecraft Crash Report ----
// My bad.

Time: 31/01/22 10:43
Description: Ticking entity

java.lang.RuntimeException: Slot 2 not in valid range - [0,2)
	at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:221) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:73) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getItem(SlotItemHandler.java:54) ~[forge:?] {re:classloading}
	at net.minecraft.inventory.container.Container.broadcastChanges(Container.java:120) ~[forge:?] {re:classloading}
	at net.minecraft.entity.player.ServerPlayerEntity.tick(ServerPlayerEntity.java:360) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tickNonPassenger(ServerWorld.java:611) ~[forge:?] {re:classloading}
	at net.minecraft.world.World.guardEntityTick(World.java:554) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:404) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:851) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:787) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tickServer(IntegratedServer.java:78) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:642) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_202] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:221) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:73) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getItem(SlotItemHandler.java:54) ~[forge:?] {re:classloading}
	at net.minecraft.inventory.container.Container.broadcastChanges(Container.java:120) ~[forge:?] {re:classloading}
	at net.minecraft.entity.player.ServerPlayerEntity.tick(ServerPlayerEntity.java:360) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tickNonPassenger(ServerWorld.java:611) ~[forge:?] {re:classloading}
-- Entity being ticked --
Details:
	Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity)
	Entity ID: 156
	Entity Name: Dev
	Entity's Exact location: 17.61, 13.00, 255.41
	Entity's Block location: World: (17,13,255), Chunk: (at 1,0,15 in 1,15; contains blocks 16,0,240 to 31,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Entity's Momentum: 0.00, -0.08, 0.00
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.world.World.guardEntityTick(World.java:554) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:404) ~[forge:?] {re:classloading}


-- Affected level --
Details:
	All players: 1 total; [ServerPlayerEntity['Dev'/156, l='ServerLevel[New World]', x=17.61, y=13.00, z=255.41]]
	Chunk stats: ServerChunkCache: 3118
	Level dimension: minecraft:overworld
	Level spawn location: World: (-256,66,128), Chunk: (at 0,4,0 in -16,8; contains blocks -256,0,128 to -241,255,143), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Level time: 12315 game time, 12315 day time
	Level name: New World
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
	Level weather: Rain time: 153512 (now: false), thunder time: 26909 (now: false)
	Known server brands: forge
	Level was modded: true
	Level storage version: 0x04ABD - Anvil
Stacktrace:
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:851) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:787) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tickServer(IntegratedServer.java:78) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:642) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_202] {}

 

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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