Posted February 23, 20169 yr I am trying to update custom crafting table from 1.7.10 to 1.8 and can't seem to get the Gui to open. I have been able to update other blocks that have tile entities, but I cannot get the table to open. Here is my GuiHandler: package com.nealegaming.mod.handler; import com.nealegaming.mod.NGGlobal; import com.nealegaming.mod.blocks.NGBlocks; import com.nealegaming.mod.container.ContainerAlloySmelter; import com.nealegaming.mod.container.ContainerDraftingBoard; import com.nealegaming.mod.container.ContainerGraniteOven; import com.nealegaming.mod.container.ContainerIngotMasher; import com.nealegaming.mod.gui.GuiAlloySmelter; import com.nealegaming.mod.gui.GuiDraftingBoard; import com.nealegaming.mod.gui.GuiGraniteOven; import com.nealegaming.mod.gui.GuiIngotMasher; import com.nealegaming.mod.tileentity.TileEntityAlloySmelter; import com.nealegaming.mod.tileentity.TileEntityGraniteOven; import com.nealegaming.mod.tileentity.TileEntityIngotMasher; 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 NGGuiHandler 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 (entity != null) { switch(ID) { case NGGlobal.graniteOvenGUIID: if (entity instanceof TileEntityGraniteOven) { return new ContainerGraniteOven(player.inventory, (TileEntityGraniteOven) entity); } return null; case NGGlobal.alloySmelterGUIID: if (entity instanceof TileEntityAlloySmelter) { return new ContainerAlloySmelter(player.inventory, (TileEntityAlloySmelter) entity); } return null; case NGGlobal.ingotMasherGUIID: if (entity instanceof TileEntityIngotMasher) { return new ContainerIngotMasher(player.inventory, (TileEntityIngotMasher) entity); } return null; } } if(ID == NGGlobal.draftingBoardGUIID) { return ID == NGGlobal.draftingBoardGUIID && world.getBlockState(new BlockPos (x, y, z)) == NGBlocks.draftingTable ? new ContainerDraftingBoard(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(entity != null) { switch(ID) { case NGGlobal.graniteOvenGUIID: if (entity instanceof TileEntityGraniteOven) { return new GuiGraniteOven(player.inventory, (TileEntityGraniteOven) entity); } return null; case NGGlobal.alloySmelterGUIID: if (entity instanceof TileEntityAlloySmelter) { return new GuiAlloySmelter(player.inventory, (TileEntityAlloySmelter) entity); } return null; case NGGlobal.ingotMasherGUIID: if (entity instanceof TileEntityIngotMasher) { return new GuiIngotMasher(player.inventory, (TileEntityIngotMasher) entity); } return null; } } if(ID == NGGlobal.draftingBoardGUIID) { return ID == NGGlobal.draftingBoardGUIID && world.getBlockState(new BlockPos (x, y, z)) == NGBlocks.draftingTable ? new GuiDraftingBoard(player.inventory, world, x, y, z) : null; } return null; } } And my Block class for the crafting table: package com.nealegaming.mod.blocks; import com.nealegaming.mod.Main; import com.nealegaming.mod.NGGlobal; import com.nealegaming.mod.container.ContainerDraftingBoard; import net.minecraft.block.Block; 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.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 NGDraftingBoard extends Block { protected NGDraftingBoard(String name) { super(Material.wood); this.setCreativeTab(NGGlobal.ngCreativeTab); this.setUnlocalizedName(name); } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { playerIn.openGui(Main.instance, NGGlobal.draftingBoardGUIID, worldIn, pos.getX(), pos.getY(), pos.getZ()); } return true; } public static class InterfaceCraftingTable implements IInteractionObject { private final World world; private final BlockPos position; public InterfaceCraftingTable(World worldIn, BlockPos pos) { this.world = worldIn; this.position = pos; } /** * Get the name of this object. For players this returns their username */ public String getName() { return null; } /** * Returns true if this thing is named */ public boolean hasCustomName() { return false; } /** * Get the formatted ChatComponent that will be used for the sender's username in chat */ public IChatComponent getDisplayName() { return new ChatComponentTranslation(NGBlocks.draftingTable.getUnlocalizedName() + ".name", new Object[0]); } public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerDraftingBoard(playerInventory, this.world, this.position); } public String getGuiID() { return "ng:draftingBoard"; } } } I can post more classes, if I need to. Just a point in the general direction would be greatly appreciated.
February 23, 20169 yr In your GuiHandler, you are getting block state and trying to compare it to block. Either get block from state, or compare to default state of block. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
February 23, 20169 yr Author I guess I have been staring at it too long. I don't even need to compare them. I did this for getServerGuiElement instead and the GUI opens for a second, but only just: if(ID == NGGlobal.draftingBoardGUIID) { return new ContainerDraftingBoard(player.inventory, world, x, y, z); } It's the same with getClientGuiElement: if(ID == NGGlobal.draftingBoardGUIID) { return new GuiDraftingBoard(player.inventory, world, x, y, z); }
February 23, 20169 yr Author I should say (shame on me) is that my console has the following when I RClick on it: java.lang.NullPointerException: Ticking entity at com.nealegaming.mod.container.ContainerDraftingBoard.canInteractWith(ContainerDraftingBoard.java:93) That method is this: public boolean canInteractWith(EntityPlayer playerIn) { return this.worldObj.getBlockState(this.pos).getBlock() != NGBlocks.draftingTable ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; }
February 23, 20169 yr I should say (shame on me) is that my console has the following when I RClick on it: java.lang.NullPointerException: Ticking entity at com.nealegaming.mod.container.ContainerDraftingBoard.canInteractWith(ContainerDraftingBoard.java:93) That method is this: public boolean canInteractWith(EntityPlayer playerIn) { return this.worldObj.getBlockState(this.pos).getBlock() != NGBlocks.draftingTable ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } Then there's something null there (it should be obvious). Now, use your IDE's debug mode to see what actually is null. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
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.