NikolaTheProgrammerNoob Posted November 8, 2015 Share Posted November 8, 2015 Hey there, fellow forum addicts ! I have a problem with my custom crafting table ! There are no errors in code ! Game doesn't crash on start ! Code is almost as same as in the Minecraft Workbench ! Note: I changed the field_178145_h to blockPos World loads fine, I try to click on the custom crafting table, and bam ! Nothing happens. I do get an error in my console which I will put down bellow. If I have an item in my hotbar, or more and I click the custom crafting table, it moves/ they move by one space. Sometimes when my hotbar is empty and I click the custom crafting table I get an item that I had before when I clicked the custom crafting table. Here is the error I get when I click the block: [18:50:03] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 45, Size: 45 java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 45, Size: 45 at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_51] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1077) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.IndexOutOfBoundsException: Index: 45, Size: 45 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_51] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_51] at net.minecraft.inventory.Container.getSlot(Container.java:138) ~[Container.class:?] at net.minecraft.inventory.Container.putStacksInSlots(Container.java:574) ~[Container.class:?] at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1215) ~[NetHandlerPlayClient.class:?] at net.minecraft.network.play.server.S30PacketWindowItems.func_180732_a(S30PacketWindowItems.java:67) ~[s30PacketWindowItems.class:?] at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:81) ~[s30PacketWindowItems.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_51] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?] ... 11 more Quote To Craft, or not to Craft. That is the question. Link to comment Share on other sites More sharing options...
Jedispencer21 Posted November 8, 2015 Share Posted November 8, 2015 Hard to help without any code. Quote Link to comment Share on other sites More sharing options...
NikolaTheProgrammerNoob Posted November 8, 2015 Author Share Posted November 8, 2015 Ok here is the code [embed=425,349]package com.nikola.carbonmod.container; import com.nikola.carbonmod.crafting.IronForgeCraftingManager; import com.nikola.carbonmod.init.CarbonBlocks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class ContainerIronForge extends Container { public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); public IInventory craftResult = new InventoryCraftResult();; private World worldObj; private BlockPos blockPos; public ContainerIronForge(InventoryPlayer invPlayer, World world, BlockPos blockPos) { this.blockPos = blockPos; worldObj = world; this.addSlotToContainer(new SlotCrafting(invPlayer.player, this.craftMatrix, this.craftResult, 0, 124, 35)); int i; int j; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18)); } } for (i = 0; i < 3; ++i) { for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142)); } onCraftMatrixChanged(craftMatrix); } //GuiHandlerConstructor public ContainerIronForge(InventoryPlayer invPlayer, World world, int x, int y, int z) { } @Override public boolean canInteractWith(EntityPlayer playerIn) { return this.worldObj.getBlockState(this.blockPos).getBlock() != CarbonBlocks.ironForge ? false : playerIn.getDistanceSq((double)this.blockPos.getX() + 0.5D, (double)this.blockPos.getY() + 0.5D, (double)this.blockPos.getZ() + 0.5D) <= 64.0D; } public void onCraftMatrixChanged(IInventory inventoryIn) { //this.craftResult.setInventorySlotContents(0, IronForgeCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } public void onContainerClosed(EntityPlayer playerIn) { super.onContainerClosed(playerIn); if (!this.worldObj.isRemote) { for (int i = 0; i < 9; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { playerIn.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (index >= 10 && index < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (index >= 37 && index < 46) { if (!this.mergeItemStack(itemstack1, 10, 37, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 10, 46, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(playerIn, itemstack1); } return itemstack; } @Override public boolean canMergeSlot(ItemStack stack, Slot slot) { return slot.inventory != this.craftResult && super.canMergeSlot(stack, slot); } } [/embed] [embed=425,349]package com.nikola.carbonmod.blocks; import com.nikola.carbonmod.CarbonMod; import com.nikola.carbonmod.container.ContainerIronForge; import com.nikola.carbonmod.init.CarbonBlocks; import net.minecraft.block.Block; import net.minecraft.block.BlockWorkbench; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; import net.minecraft.world.IInteractionObject; import net.minecraft.world.World; public class IronForge extends Block { public IronForge(Material materialIn) { super(materialIn); this.setHardness(3.0F); this.setResistance(15.0F); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } else { playerIn.displayGui(new IronForge.InterfaceCraftingTable(worldIn, pos)); return true; } } public static class InterfaceCraftingTable implements IInteractionObject { private final World world; private final BlockPos position; private static final String __OBFID = "CL_00002127"; public InterfaceCraftingTable(World worldIn, BlockPos pos) { this.world = worldIn; this.position = pos; } public String getName() { return null; } public boolean hasCustomName() { return false; } public IChatComponent getDisplayName() { return new ChatComponentTranslation(CarbonBlocks.ironForge.getUnlocalizedName() + ".name", new Object[0]); } public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerIronForge(playerInventory, this.world, this.position); } public String getGuiID() { return "carbonmod:ironForge"; } } } [/embed] [embed=425,349]package com.nikola.carbonmod.gui; import org.lwjgl.opengl.GL11; import com.nikola.carbonmod.Reference; import com.nikola.carbonmod.container.ContainerIronForge; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class GuiIronForge extends GuiContainer { private ResourceLocation texture = new ResourceLocation(Reference.MOD_ID + ":" + "minecraft/texuters/gui/container/ironForge.png"); public GuiIronForge(InventoryPlayer invPlayer, World world, int x, int y, int z) { super(new ContainerIronForge(invPlayer, world, x, y, z)); this.xSize = 176; this.ySize = 166; } public void onGuiClosed() { super.onGuiClosed(); } protected void drawGuiContainerForgroundLayer(int i, int j) { this.fontRendererObj.drawString(StatCollector.translateToLocal("Iron Forge"), 100, 5, 0xFFFFFF); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GL11.glColor4f(1F, 1F, 1F, 1F); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } } [/embed] [embed=425,349]package com.nikola.carbonmod.gui; import com.nikola.carbonmod.container.ContainerIronForge; import com.nikola.carbonmod.init.CarbonBlocks; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(new BlockPos(x, y, z)); if(ID == CarbonBlocks.guiIDIronForge) { return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new ContainerIronForge(player.inventory, world, x, y, z) : null; } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(new BlockPos(x, y, z)); if(ID == CarbonBlocks.guiIDIronForge) { return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new ContainerIronForge(player.inventory, world, x, y, z) : null; } return null; } } [/embed] Quote To Craft, or not to Craft. That is the question. Link to comment Share on other sites More sharing options...
Jedispencer21 Posted November 8, 2015 Share Posted November 8, 2015 In onBlockActivated, don't use EntityPlayer#displayGui. First check if World#getTileEntity is an instanceof your tileentity then use FMLNetworkHandler#openGui Quote Link to comment Share on other sites More sharing options...
NikolaTheProgrammerNoob Posted November 8, 2015 Author Share Posted November 8, 2015 You mean like this: ? public boolean onBlockActivated(World worldIn, int x, int y , int z, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return false; } else { FMLNetworkHandler.openGui(playerIn, CarbonMod.instance, CarbonBlocks.guiIDIronForge, worldIn, x, y, z); return true; } } Quote To Craft, or not to Craft. That is the question. Link to comment Share on other sites More sharing options...
Jedispencer21 Posted November 8, 2015 Share Posted November 8, 2015 if World#isRemote then return true, but just try it out for yourself Quote Link to comment Share on other sites More sharing options...
NikolaTheProgrammerNoob Posted November 8, 2015 Author Share Posted November 8, 2015 Didn't work Quote To Craft, or not to Craft. That is the question. Link to comment Share on other sites More sharing options...
Jedispencer21 Posted November 8, 2015 Share Posted November 8, 2015 In your GuiHandler class you have: public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(new BlockPos(x, y, z)); if (ID == CarbonBlocks.guiIDIronForge) { return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new ContainerIronForge(player.inventory, world, x, y, z) : null; } return null; } public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(new BlockPos(x, y, z)); if (ID == CarbonBlocks.guiIDIronForge) { return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new ContainerIronForge(player.inventory, world, x, y, z) : null; } return null; } In getClientGuiElement it should not return new ContainerIronForge, but instead should return new GuiIronForge Quote Link to comment Share on other sites More sharing options...
NikolaTheProgrammerNoob Posted November 9, 2015 Author Share Posted November 9, 2015 Still nothing Quote To Craft, or not to Craft. That is the question. Link to comment Share on other sites More sharing options...
Recommended Posts
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.