Jump to content

Recommended Posts

Posted

I am making a custom crafting table but whenever I try to shift click something out of an InventoryCrafting slot, minecraft crashes due to java.lang.ArrayIndexOutOfBounds: 3 and java.langIndexOutOfBounds: index40, Size 40 exceptions. The inventoryCrafting slot I used is from vanilla, so I don't know what caused the crash. Any ideas?

 

Container class:

public class ContainerArkenstoneTable extends Container{
    public InventoryCrafting inputInventory = new InventoryCrafting(this, 3, 1);
    public int inputSlotNumber;
    public InventoryArkenstoneResult outputInventory = new InventoryArkenstoneResult();
    public ArkenstoneRecipeHandler arkenstoneRecipeHandler;
    private final World world;
    private final BlockPos pos;
    private final InventoryPlayer playerInventory;

    public ContainerArkenstoneTable(InventoryPlayer playerInventory, World worldIn, BlockPos posIn){
        this.world = worldIn;
        this.pos = posIn;
        this.playerInventory = playerInventory;
        
        arkenstoneRecipeHandler = new ArkenstoneRecipeHandler();
        
        this.addSlotToContainer(new Slot(outputInventory, 0, 124, 35));
        this.addSlotToContainer(new Slot(inputInventory, 0, 30 + 0 * 18, 17 + 18));
        this.addSlotToContainer(new Slot(inputInventory, 1, 30 + 1 * 18, 17 + 18));
        this.addSlotToContainer(new Slot(inputInventory, 2, 30 + 2 * 18, 17 + 18));
        

        for (int k = 0; k < 3; ++k){
            for (int i1 = 0; i1 < 9; ++i1){
                this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
            }
        }

        for (int l = 0; l < 9; ++l){
            this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
        }
    }

    /**
     * Callback for when the crafting matrix is changed.
     */
    public void onCraftMatrixChanged(IInventory inventoryIn){
    	if (!world.isRemote) {
    		//if the inventory selected is actually input inventory
        	if(inventoryIn == inputInventory){
        		//if this thing is empty, stahp
                if(inputInventory.isEmpty()) {
                	return;
                }else {
                    ItemStack outputItemStack = arkenstoneRecipeHandler.getArkenstoneResults(inputInventory);
                    
                    if (outputItemStack == ItemStack.EMPTY ){
                        return;
                    }else {
                    	outputInventory.setInventorySlotContents(0, new ItemStack(Items.APPLE));;
                    }
                }
        	}
    	}
    }


    

    /**
     * Called when the container is closed.
     */
    @Override
    public void onContainerClosed(EntityPlayer playerIn)
    {
        super.onContainerClosed(playerIn);

        if (!this.world.isRemote)
        {
            this.clearContainer(playerIn, this.world, this.inputInventory);
        }
    }

    /**
     * Determines whether supplied player can use this container
     */
    @Override
    public boolean canInteractWith(EntityPlayer playerIn)
    {
        if (this.world.getBlockState(this.pos).getBlock() != ModBlocks.ArkenstoneTableBlock)
        {
            return false;
        }
        else
        {
            return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
        }
    }

    /**
     * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
     * inventory and the other inventory(s).
     */
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = this.inventorySlots.get(index);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (index == 0)
            {
                itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);

                if (!this.mergeItemStack(itemstack1, 10, 46, true))
                {
                    return ItemStack.EMPTY;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (index >= 10 && index < 37)
            {
                if (!this.mergeItemStack(itemstack1, 37, 46, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 37 && index < 46)
            {
                if (!this.mergeItemStack(itemstack1, 10, 37, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 10, 46, false))
            {
                return ItemStack.EMPTY;
            }

            if (itemstack1.isEmpty())
            {
                slot.putStack(ItemStack.EMPTY);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.getCount() == itemstack.getCount())
            {
                return ItemStack.EMPTY;
            }

            ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);

            if (index == 0)
            {
                playerIn.dropItem(itemstack2, false);
            }
        }

        return itemstack;
    }

    /**
     * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
     * is null for the initial slot that was double-clicked.
     */
    public boolean canMergeSlot(ItemStack stack, Slot slotIn){
        return slotIn.inventory != this.outputInventory && super.canMergeSlot(stack, slotIn);
    }
    
    @Override
    public Slot getSlot(int parSlotIndex)
    {
        if(parSlotIndex >= inventorySlots.size())
            parSlotIndex = inventorySlots.size() - 1;
        return super.getSlot(parSlotIndex);
    }
}

 

Posted
19 minutes ago, Lumby said:

so I don't know what caused the crash

You are requesting a slot that doesn't exist, find out why it doesn't exist. My best guess is that it has to do with these two lines.

20 minutes ago, Lumby said:

this.addSlotToContainer(new Slot(outputInventory, 0, 124, 35));

this.addSlotToContainer(new Slot(inputInventory, 0, 30 + 0 * 18, 17 + 18));

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
1 minute ago, Lumby said:

Any idea where that request might come from?

This?

2 hours ago, Lumby said:

this.addSlotToContainer(new Slot(outputInventory, 0, 124, 35)); this.addSlotToContainer(new Slot(inputInventory, 0, 30 + 0 * 18, 17 + 18)); this.addSlotToContainer(new Slot(inputInventory, 1, 30 + 1 * 18, 17 + 18)); this.addSlotToContainer(new Slot(inputInventory, 2, 30 + 2 * 18, 17 + 18));

This is your code that you posted. Can you clarify what you mean by request?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Sorry, I meant what might've called those inventory slots that I created, so that I can find how it induced the crash. My guess is since it's an out of bounds exception, it might have something to do with the index I created the slots with, so I want to see what methods called the slots and how it called them. 

Posted
Just now, Lumby said:

Sorry, I meant what might've called those inventory slots that I created, so that I can find how it induced the crash. My guess is since it's an out of bounds exception, it might have something to do with the index I created the slots with, so I want to see what methods called the slots and how it called them. 

Those methods are called to create the slots on the screen when the GUI is created. If your trying to find what called those methods use the debugger. What IDE are you using?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Double click the line-number on the line you want to break on, a blue dot should appear. Run the program _in debug mode_ and when the program reaches that line it will pause and Eclipse will ask you if you want to open the debug perspective. Click yes (you can switch back to the default java perspective in the top right later) and you will be able to see the call stack and the values of all your fields and more.

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

Thanks for the help! Sorry this is my first time using an eclipse debugger, but from what I can tell, this means I did indeed create three Slot() objects for my inputInventory. Any idea why minecraft is still crashing?

image.png.6ea25c050b45b61ccfc2b072b41a194b.png

My breakpoint is set right after their creation:

2 hours ago, Lumby said:

this.addSlotToContainer(new Slot(outputInventory, 0, 124, 35)); this.addSlotToContainer(new Slot(inputInventory, 0, 30 + 0 * 18, 17 + 18)); this.addSlotToContainer(new Slot(inputInventory, 1, 30 + 1 * 18, 17 + 18)); this.addSlotToContainer(new Slot(inputInventory, 2, 30 + 2 * 18, 17 + 18));

 

Edited by Lumby
Posted
Just now, Lumby said:

Thanks for the help! Sorry this is my first time using an eclipse debugger, but from what I can tell, this means I did indeed create three Slot() objects for my inputInventory. Any idea why minecraft is still crashing?

image.png.6ea25c050b45b61ccfc2b072b41a194b.png

That’s eclipse? Remember array indexes start at 0 not 1. So your array index range is between 0 and array.length-1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

So I'm guessing some method tried to reference the slots by calling inputInventory[3] since the error was arraysOutOfBounds: 3, my question is what method might've called that?

 

And yeah that's just eclipse dark mode haha. 

Posted

Make sure that both inventories are instantiated. And place a breakpoint where it crashes and find out why it does

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
1 minute ago, Lumby said:

So I'm guessing some method tried to reference the slots by calling inputInventory[3] since the error was arraysOutOfBounds: 3, my question is what method might've called that?

 

And yeah that's just eclipse dark mode haha. 

Looks good - I thought it was IntelliJ, I might try it. The only methods that would cause it would be methods called by with you or methods using parameters given by you. 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Where did you get these methods from?

2 hours ago, Lumby said:

public boolean canMergeSlot(ItemStack stack, Slot slotIn){

2 hours ago, Lumby said:

public Slot getSlot(int parSlotIndex)

2 hours ago, Lumby said:

public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)

 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
Just now, Lumby said:

The vanilla ContainerWorkbench class. I was following Jabelar's tutorial: http://jabelarminecraft.blogspot.com/p/blog-page_31.html and it had these methods in his container class, but they were outdated. Hence, I pulled it from the workbench class hoping they'd work. 

Those methods are specifically made for ContainerWorkbench & break when used in any other class.

Someone (shadow facts I think? The code was made for 1.7 or something and still works perfectly) made a method that works on any container and I copied it. Have a look at https://github.com/Cadiboo/WIPTechAlpha/blob/73e647149fd26bebf7d56d6bfbac4818e33dcf78/src/main/java/cadiboo/wiptech/util/ModUtil.java#L237-L270 and the method below it if you need it and have a look at any of the classes in https://github.com/Cadiboo/WIPTechAlpha/tree/73e647149fd26bebf7d56d6bfbac4818e33dcf78/src/main/java/cadiboo/wiptech/inventory

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.