SSslimer Posted October 12, 2014 Share Posted October 12, 2014 Hi, I managed to create inventory for my mob, it is simillar to horse. But there is one problem. I dont know how to open it, I tried to use method player.displayGUIChest(), but after that my gui looks like chest.Horse gui use method: displayGUIHorse(), but I cant use it due to different entity class. What method should I use to display my gui? Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 12, 2014 Author Share Posted October 12, 2014 Thanks for fast reply. I have my own GuiHandler ,but do I realy need it for my gui when it is opening from another gui? Quote Link to comment Share on other sites More sharing options...
MultiMote Posted October 12, 2014 Share Posted October 12, 2014 http://www.minecraftforge.net/forum/index.php/topic,21001.msg106575.html#msg106575 Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 12, 2014 Author Share Posted October 12, 2014 Thanks, should I use client and server or only client side gui element? Quote Link to comment Share on other sites More sharing options...
MultiMote Posted October 12, 2014 Share Posted October 12, 2014 For server you should return your Container, for client - your GuiContainer. Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 12, 2014 Author Share Posted October 12, 2014 I get an error when I open my gui. In server side, again NPE Entity entity = world.getEntityByID(x); Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 18, 2014 Author Share Posted October 18, 2014 Now I try to use SimpleNetworkWrapper as MultiMote suggested me. Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 19, 2014 Author Share Posted October 19, 2014 He suggested me to do it in PM. The code is mostly from MultiMode to make it only working Maybe all code for inventory and error log will help. public class InventoryVillager extends InventoryBasic { public InventoryVillager(String name, int slots) { super(name, false, slots); } } Code from container. public class ContainerVillager extends Container { protected IInventory inventory; private int player_inventory_x = 70; private int player_inventory_y = 8; private int loot_x = 8; private int loot_y = 10; public ContainerVillager(InventoryPlayer inventoryPlayer, IInventory iInventory) { inventory = iInventory; { for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { addSlotToContainer(new Slot(iInventory, j + i * 2, (loot_x + j * 18), (loot_y + i * 18))); } } } bindPlayerInventory(inventoryPlayer); } public boolean canInteractWith(EntityPlayer player) { return inventory.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, player_inventory_x + j * 18, player_inventory_y + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, player_inventory_x + i * 18, player_inventory_y + 54 + 4)); } } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); int s = inventory.getSizeInventory(); if (par2 < s) { if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, s, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack(null); } else { slot.onSlotChanged(); } } return itemstack; } public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); this.inventory.closeInventory(); } } Code in GUI. @SideOnly(Side.CLIENT) public class GuiVillagerInventory extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation("BetterWorld:textures/gui/VillagerInventory.png"); private int invW = 176; private int invH = 90; private int lootH = 90; private int lootW = 50; public GuiVillagerInventory(InventoryPlayer inventoryPlayer, InventoryVillager inv) { super(new ContainerVillager(inventoryPlayer, inv)); this.xSize=300; this.ySize=90; } protected void drawGuiContainerForegroundLayer(int param1, int param2) {} protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(texture); int x = (width - invW) / 2; int y = (height - invH) / 2; this.drawTexturedModalRect(x, y, 0, 0, invW, invH); x = (width/ 2)-150; y = (height - lootH) / 2; this.drawTexturedModalRect(x, y, 176, 0, lootW, lootH); } } Code in entity class. public class EntityBetterVillager extends EntityVillagerType implements INpc, IRangedAttackMob, IInvBasic { private InventoryVillager inventoryVillager; public IInventory inventory; public EntityBetterVillager(World par1World) { this(par1World, 0); this.setupInventory(); } public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); if (!this.isChild()) { NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.inventoryVillager.getSizeInventory(); ++i) { ItemStack itemstack = this.inventoryVillager.getStackInSlot(i); if (itemstack != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); itemstack.writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } par1NBTTagCompound.setTag("Items", nbttaglist); } } } public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); if (!this.isChild()) { NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 20); this.setupInventory(); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.inventoryVillager.getSizeInventory()) { this.inventoryVillager.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1)); } } } } public int howManySlots() { return 8; } private void setupInventory() { InventoryVillager inventory = this.inventoryVillager; this.inventoryVillager = new InventoryVillager("Villager Inventory", howManySlots()); this.inventoryVillager.func_110133_a(this.getCommandSenderName()); if (inventory != null) { inventory.func_110132_b(this); int i = Math.min(inventory.getSizeInventory(), this.inventoryVillager.getSizeInventory()); for (int j = 0; j < i; ++j) { ItemStack itemstack = inventory.getStackInSlot(j); if (itemstack != null) { this.inventoryVillager.setInventorySlotContents(j, itemstack.copy()); } } inventory = null; } this.inventoryVillager.func_110134_a(this); } @Override public void onInventoryChanged(InventoryBasic var1) {} } Code from another gui, in method actionPerformed(GuiButton guiButton) ModBetterWorld.packets.sendToServer(new GuiRequestPacket(3, this.villager.getEntityId())); In main class public static SimpleNetworkWrapper packets; @EventHandler public void postInit(FMLPostInitializationEvent event) { packets = NetworkRegistry.INSTANCE.newSimpleChannel("ModBetterWorld"); packets.registerMessage(GuiRequestPacket.class, GuiRequestPacket.class, 0, Side.SERVER); } Packet Handler public class GuiRequestPacket implements IMessage, IMessageHandler<GuiRequestPacket, IMessage> { int type; int entityID; public GuiRequestPacket() { } public GuiRequestPacket(int type, int entityID) { this.type = type; this.entityID = entityID; } @Override public void toBytes(ByteBuf target) { target.writeInt(type); target.writeInt(entityID); } @Override public void fromBytes(ByteBuf dat) { type = dat.readInt(); entityID = dat.readInt(); } @Override public IMessage onMessage(GuiRequestPacket message, MessageContext ctx) { System.out.println("requested guiID" + message.type + " for entity ID " + message.entityID); EntityPlayer player = ctx.getServerHandler().playerEntity; World world = player.worldObj; player.openGui(ModBetterWorld.instance, message.type, world, message.entityID, 0, 0); return null; } } When I open gui by button the game crashes. I can see for a while gui screen. Then crash occure. It says sth about forge error. Here is error log: 12:56:36] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?] at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?] at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] [12:56:36] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel ModBetterWorld java.lang.NullPointerException at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?] at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?] at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] [12:56:36] [server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking player at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.NullPointerException at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) ~[ContainerVillager.class:?] at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) ~[PlayerOpenContainerEvent.class:?] at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) ~[ForgeHooks.class:?] at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) ~[EntityPlayer.class:?] at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) ~[C03PacketPlayer.class:?] at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) ~[C03PacketPlayer.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?] ... 5 more And next part: Time: 19.10.14 12:56 Description: Ticking player java.lang.NullPointerException: Ticking player at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 109 Entity Name: Player170 Entity's Exact location: 642,57, 4,00, 174,03 Entity's Block location: World: (642,4,174), Chunk: (at 2,0,14 in 40,10; contains blocks 640,0,160 to 655,255,175), Region: (1,0; contains chunks 32,0 to 63,31, blocks 512,0,0 to 1023,255,511) Entity's Momentum: 0,00, -0,08, 0,00 Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@3d7e16 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) I know that is a lot of code but I will be very thankful if someone help me Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 19, 2014 Author Share Posted October 19, 2014 What do you mean by normal GuiHandler? Quote Link to comment Share on other sites More sharing options...
MultiMote Posted October 19, 2014 Share Posted October 19, 2014 Message received on the server. He has button in gui that opens entity inventory. Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 19, 2014 Author Share Posted October 19, 2014 Sorry, it is not very visible and clearly by: Code from another gui, in method actionPerformed(GuiButton guiButton) Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 19, 2014 Author Share Posted October 19, 2014 I thinks the same, alse the line with .getEntityByID() is wrong. Is any other way to choose entity? Quote Link to comment Share on other sites More sharing options...
SSslimer Posted October 24, 2014 Author Share Posted October 24, 2014 Have you some suggestions or tips how to make it working? Can someone help just a bit? Quote Link to comment Share on other sites More sharing options...
SSslimer Posted November 11, 2014 Author Share Posted November 11, 2014 Still doesnt work. Do you know some tutorials or sollution? Solved. It was my fault. I made a mistake. Thanks for help. Quote 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.