Jump to content

Slot 2 not in a valide range [1.16]


Thanatos_0173_2

Recommended Posts

First, let me tell you that I know I'm not the only one posting about this error, but I haven't found anything with my specific error.

 

So, I've created a GUI (well I've actually copy-paste it but don't say it to anyone : - )   ), and I wanted to add a new slot. I've changed the value TE_INVENTORY_SLOT_COUNT from 2 to 3, but I kept on havving the error. Can someone help me?

 

My code :

 

package com.thanatos.magicalgems.container;
import com.thanatos.magicalgems.init.ModBlocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;


public class LightningChannelerContainer extends Container {
    private final TileEntity tileEntity;
    private final PlayerEntity playerEntity;
    private final IItemHandler playerInventory;

    public LightningChannelerContainer(int windowId, World world, BlockPos pos,
                                       PlayerInventory playerInventory, PlayerEntity player) {
        super(ModContainer.LIGHTNING_CHANNELER_CONTAINER.get(), windowId);
        this.tileEntity = world.getTileEntity(pos);
        playerEntity = player;
        this.playerInventory = new InvWrapper(playerInventory);
        layoutPlayerInventorySlots(8, 106);

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

    public boolean isLightningStorm() {
        return tileEntity.getWorld().isThundering();
    }

    @Override
    public boolean canInteractWith(PlayerEntity playerIn) {
        return isWithinUsableDistance(IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()),
                playerIn, ModBlocks.LIGHTNING_CHANNELER.get());
    }


    private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx) {
        for (int i = 0; i < amount; i++) {
            addSlot(new SlotItemHandler(handler, index, x, y));
            x += dx;
            index++;
        }

        return index;
    }

    private int addSlotBox(IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy) {
        for (int j = 0; j < verAmount; j++) {
            index = addSlotRange(handler, index, x, y, horAmount, dx);
            y += dy;
        }

        return index;
    }

    private void layoutPlayerInventorySlots(int leftCol, int topRow) {
        addSlotBox(playerInventory, 9, leftCol, topRow, 9, 18, 3, 18);

        topRow += 58;
        addSlotRange(playerInventory, 0, leftCol, topRow, 9, 18);

    }

    // CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
    // must assign a slot number to each of the slots used by the GUI.
    // For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
    // Each time we add a Slot to the container, it automatically increases the slotIndex, which means
    //  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8)
    //  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
    //  36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8)
    private static final int HOTBAR_SLOT_COUNT = 9;
    private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
    private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
    private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
    private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
    private static final int VANILLA_FIRST_SLOT_INDEX = 0;
    private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

    // THIS YOU HAVE TO DEFINE!
    private static final int TE_INVENTORY_SLOT_COUNT = 3;  // must match TileEntityInventoryBasic.NUMBER_OF_SLOTS

    @Override
    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
        Slot sourceSlot = inventorySlots.get(index);
        if (sourceSlot == null || !sourceSlot.getHasStack()) return ItemStack.EMPTY;  //EMPTY_ITEM
        ItemStack sourceStack = sourceSlot.getStack();
        ItemStack copyOfSourceStack = sourceStack.copy();

        // Check if the slot clicked is one of the vanilla container slots
        if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
            // This is a vanilla container slot so merge the stack into the tile inventory
            if (!mergeItemStack(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
                    + TE_INVENTORY_SLOT_COUNT, false)) {
                return ItemStack.EMPTY;  // EMPTY_ITEM
            }
        } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
            // This is a TE slot so merge the stack into the players inventory
            if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
                return ItemStack.EMPTY;
            }
        } else {
            System.out.println("Invalid slotIndex:" + index);
            return ItemStack.EMPTY;
        }
        // If stack size == 0 (the entire stack was moved) set slot contents to null
        if (sourceStack.getCount() == 0) {
            sourceSlot.putStack(ItemStack.EMPTY);
        } else {
            sourceSlot.onSlotChanged();
        }
        sourceSlot.onTake(playerEntity, sourceStack);
        return copyOfSourceStack;
    }
}

Error log:

---- Minecraft Crash Report ----
// I bet Cylons wouldn't have this problem.

Time: 17/11/2022, 23:51
Description: Rendering screen

java.lang.RuntimeException: Slot 2 not in valid range - [0,2)
	at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:207) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:59) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:40) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.moveItems(ContainerScreen.java:191) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.render(ContainerScreen.java:106) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at com.thanatos.magicalgems.screen.LightningChannelerScreen.render(LightningChannelerScreen.java:24) ~[main/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreenInternal(ForgeHooksClient.java:363) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:356) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:492) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:977) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:607) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:38) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:94) [forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {}


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:207) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:59) ~[forge:?] {re:classloading}
	at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:40) ~[forge:?] {re:classloading}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.moveItems(ContainerScreen.java:191) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.render(ContainerScreen.java:106) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at com.thanatos.magicalgems.screen.LightningChannelerScreen.render(LightningChannelerScreen.java:24) ~[?:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreenInternal(ForgeHooksClient.java:363) ~[forge:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:356) ~[forge:?] {re:classloading}
-- Screen render details --
Details:
	Screen name: com.thanatos.magicalgems.screen.LightningChannelerScreen
	Mouse location: Scaled: (213, 120). Absolute: (427.000000, 240.000000)
	Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2.000000

-- Affected level --
Details:
	All players: 1 total; [ClientPlayerEntity['Dev'/16, l='ClientLevel', x=267.70, y=-1.40, z=-254.25]]
	Chunk stats: Client Chunk Cache: 841, 529
	Level dimension: minecraft:overworld
	Level spawn location: World: (240,4,-256), Chunk: (at 0,0,0 in 15,-16; contains blocks 240,0,-256 to 255,255,-241), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
	Level time: 77807 game time, 49490 day time
	Server brand: forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.world.ClientWorld.fillCrashReport(ClientWorld.java:458) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2031) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:623) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:38) ~[forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:94) [forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5.jar:?] {}


-- System Details --
Details:
	Minecraft Version: 1.16.5
	Minecraft Version ID: 1.16.5
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 17.0.5, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation
	Memory: 232471112 bytes (221 MB) / 1044381696 bytes (996 MB) up to 2080374784 bytes (1984 MB)
	CPUs: 8
	JVM Flags: 2 total; -XX:+IgnoreUnrecognizedVMOptions -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 8.1.3+8.1.3+main-8.1.x.c94d18ec
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/mixin-0.8.4.jar mixin PLUGINSERVICE 
		/eventbus-4.0.0.jar eventbus PLUGINSERVICE 
		/forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE 
		/forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/mixin-0.8.4.jar mixin TRANSFORMATIONSERVICE 
		/forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16.5-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 36.2
	Forge: net.minecraftforge:36.2.39
	FML Language Providers: 
		javafml@36.2
		minecraft@1
	Mod List: 
		client-extra.jar                                  |Minecraft                     |minecraft                     |1.16.5              |DONE      |Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f
		main                                              |Magicalgems                   |magicalgems                   |NONE                |DONE      |Manifest: NOSIGNATURE
		forge-1.16.5-36.2.39_mapped_snapshot_20210309-1.16|Forge                         |forge                         |36.2.39             |DONE      |Manifest: NOSIGNATURE
	Crash Report UUID: c3ef2b80-28c7-40ba-8c1b-8cd618a5c32d
	Launched Version: MOD_DEV
	Backend library: LWJGL version 3.2.2 build 10
	Backend API: Intel(R) Iris(R) Xe Graphics GL version 4.6.0 - Build 30.0.101.1692, Intel
	GL Caps: Using framebuffer using OpenGL 3.0
	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'forge'
	Type: Client (map_client.txt)
	Graphics mode: fancy
	Resource Packs: 
	Current Language: English (United Kingdom)
	CPU: 8x 11th Gen Intel(R) Core(TM) i5-11320H @ 3.20GHz

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I try to make a katana, with katana and scabbard, is that possible to make 2 different models to be on player while he holding item? Katana in hands, and scabbard at belt. 
    • I created a server with the Pixelmon mod, it's fine and everything but a person enters and the server closes, I don't know how to explain it very well but I attach the detailed file of the error that happens to me https://mclo.gs/eSemvtq This error had not happened to me until now, so I don't understand very well why this happens, could you help me solve it?
    • When I create the server and log in it lets me play, but a person ends up joining and it sends me an error and the server closes The report says Exception in server tick Loop I put here what the console tells me because I honestly don't know how to explain it: https://mclo.gs/eSemvtq I use Forge mods and this has not happened to me until now 
    • Sorry I wasn't on this site for a few days. But anyways, if you just simply want to install forge to play with mods, you need to click on the installer option, thqat way, forge will be automatically installed to your device at the version you chose. Then you could just open Minecraft launcher to play on that version.
    • I've been putting together a modpack for a few weeks, and it's worked just fine. Until today, I logged onto my survival world and went exploring. As soon as I entered my boat the game froze and crashed. Now when I try to start the world, nothing loads and the game crashes. I tried creating a new world and the same thing happened when I tried to use a boat. Here's the latest crash report from the original world: If anyone knows how to fix the issue, I'd really appreciate the help, thanks.
  • Topics

×
×
  • Create New...

Important Information

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