Text and video are both visual... perhaps you need someone to verbally explain it to you during the video? Sorry I don't do video tutorials, but perhaps someone else might.
Hey coolalias I tried the 1.6.4 version of the on item right click inventory, and when I right click it says "A mod tried to open a gui on the server without being a NetworkMod" please help!
Hey coolalias I tried the 1.6.4 version of the on item right click inventory, and when I right click it says "A mod tried to open a gui on the server without being a NetworkMod" please help!
Post your main mod class - there is probably something missing.
Thanks for your help and it now works but when I put something in it and close the bag it works, but then when I reopen it crashes my game and corrupts the world. If you need any of my classes just tell me.
EDIT: Hey I'm also wondering if you could help me with making a bigger inventory that doesn't extend off into space. When I set the inv size the containers run off the screen. I would like to make there be 10 rows with 9 slots in each row, if you could help me with this that would be awesome!
It shouldn't really be possible to corrupt the world save with a simple inventory item. If your game crashes, you must always post the crash log and the related code; otherwise, you make other people waste their time asking for it when they could be helping you fix it.
As for the inventory size, you can make it whatever size you want, you just have to reposition the slots on the screen. If you spend some time reading the code, then you would be able to figure it out for yourself. It's really not complicated.
It shouldn't really be possible to corrupt the world save with a simple inventory item. If your game crashes, you must always post the crash log and the related code; otherwise, you make other people waste their time asking for it when they could be helping you fix it.
As for the inventory size, you can make it whatever size you want, you just have to reposition the slots on the screen. If you spend some time reading the code, then you would be able to figure it out for yourself. It's really not complicated.
Thanks for tips (I'm a newbie to the forums :P)
Crash Log
2014-12-30 21:07:26 [INFO] [STDERR] net.minecraft.util.ReportedException: Reading NBT data
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:63)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:699)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:595)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:134)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:489)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2014-12-30 21:07:26 [INFO] [STDERR] Caused by: java.lang.ClassCastException: net.minecraft.nbt.NBTTagInt cannot be cast to net.minecraft.nbt.NBTTagByte
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.nbt.NBTTagCompound.getByte(NBTTagCompound.java:203)
2014-12-30 21:07:26 [INFO] [STDERR] at net.brandoncom.mod.item.extensions.InventoryItem.readFromNBT(InventoryItem.java:114)
2014-12-30 21:07:26 [INFO] [STDERR] at net.brandoncom.mod.item.extensions.InventoryItem.<init>(InventoryItem.java:21)
2014-12-30 21:07:26 [INFO] [STDERR] at net.brandoncom.mod.proxy.CommonProxy.getServerGuiElement(CommonProxy.java:17)
2014-12-30 21:07:26 [INFO] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:320)
2014-12-30 21:07:26 [INFO] [STDERR] at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:371)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2555)
2014-12-30 21:07:26 [INFO] [STDERR] at net.brandoncom.mod.item.itemBag.onItemRightClick(itemBag.java:24)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:177)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:365)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
2014-12-30 21:07:26 [INFO] [STDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
2014-12-30 21:07:26 [INFO] [STDERR] ... 6 more
2014-12-30 21:07:26 [SEVERE] [Minecraft-Server] Encountered an unexpected exception ReportedException
net.minecraft.util.ReportedException: Reading NBT data
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:63)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:699)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:595)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:134)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:489)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.ClassCastException: net.minecraft.nbt.NBTTagInt cannot be cast to net.minecraft.nbt.NBTTagByte
at net.minecraft.nbt.NBTTagCompound.getByte(NBTTagCompound.java:203)
at net.brandoncom.mod.item.extensions.InventoryItem.readFromNBT(InventoryItem.java:114)
at net.brandoncom.mod.item.extensions.InventoryItem.<init>(InventoryItem.java:21)
at net.brandoncom.mod.proxy.CommonProxy.getServerGuiElement(CommonProxy.java:17)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:320)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:371)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2555)
at net.brandoncom.mod.item.itemBag.onItemRightClick(itemBag.java:24)
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:177)
at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:365)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
... 6 more
2014-12-30 21:07:26 [SEVERE] [Minecraft-Server] This crash report has been saved to: C:\Users\Sage King\Desktop\ModCreation\MCP - BCN - Copy\jars\.\crash-reports\crash-2014-12-30_21.07.26-server.txt
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Stopping server
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving players
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Player79 left the game
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving worlds
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving chunks for level 'New World'/Overworld
2014-12-30 21:07:26 [INFO] [STDOUT] ---- Minecraft Crash Report ----
2014-12-30 21:07:26 [INFO] [STDOUT] // I feel sad now
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] Time: 12/30/14 9:07 PM
2014-12-30 21:07:26 [INFO] [STDOUT] Description: Reading NBT data
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] java.lang.ClassCastException: net.minecraft.nbt.NBTTagInt cannot be cast to net.minecraft.nbt.NBTTagByte
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.nbt.NBTTagCompound.getByte(NBTTagCompound.java:203)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.extensions.InventoryItem.readFromNBT(InventoryItem.java:114)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.extensions.InventoryItem.<init>(InventoryItem.java:21)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.proxy.CommonProxy.getServerGuiElement(CommonProxy.java:17)
2014-12-30 21:07:26 [INFO] [STDOUT] at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:320)
2014-12-30 21:07:26 [INFO] [STDOUT] at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:371)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2555)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.itemBag.onItemRightClick(itemBag.java:24)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:177)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:365)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:699)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:595)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:134)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:489)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] A detailed walkthrough of the error, its code path and all known details is as follows:
2014-12-30 21:07:26 [INFO] [STDOUT] ---------------------------------------------------------------------------------------
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] -- Corrupt NBT tag --
2014-12-30 21:07:26 [INFO] [STDOUT] Details:
2014-12-30 21:07:26 [INFO] [STDOUT] Tag type found: INT
2014-12-30 21:07:26 [INFO] [STDOUT] Tag type expected: BYTE
2014-12-30 21:07:26 [INFO] [STDOUT] Tag name: Slot
2014-12-30 21:07:26 [INFO] [STDOUT] Stacktrace:
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.nbt.NBTTagCompound.getByte(NBTTagCompound.java:203)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.extensions.InventoryItem.readFromNBT(InventoryItem.java:114)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.extensions.InventoryItem.<init>(InventoryItem.java:21)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.proxy.CommonProxy.getServerGuiElement(CommonProxy.java:17)
2014-12-30 21:07:26 [INFO] [STDOUT] at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:320)
2014-12-30 21:07:26 [INFO] [STDOUT] at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:371)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2555)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.brandoncom.mod.item.itemBag.onItemRightClick(itemBag.java:24)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:177)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:365)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] -- Ticking connection --
2014-12-30 21:07:26 [INFO] [STDOUT] Details:
2014-12-30 21:07:26 [INFO] [STDOUT] Connection: [email protected]
2014-12-30 21:07:26 [INFO] [STDOUT] Stacktrace:
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:699)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:595)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:134)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:489)
2014-12-30 21:07:26 [INFO] [STDOUT] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2014-12-30 21:07:26 [INFO] [STDOUT]
2014-12-30 21:07:26 [INFO] [STDOUT] -- System Details --
2014-12-30 21:07:26 [INFO] [STDOUT] Details:
2014-12-30 21:07:26 [INFO] [STDOUT] Minecraft Version: 1.6.4
2014-12-30 21:07:26 [INFO] [STDOUT] Operating System: Windows 7 (amd64) version 6.1
2014-12-30 21:07:26 [INFO] [STDOUT] Java Version: 1.7.0_71, Oracle Corporation
2014-12-30 21:07:26 [INFO] [STDOUT] Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
2014-12-30 21:07:26 [INFO] [STDOUT] Memory: 821427968 bytes (783 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
2014-12-30 21:07:26 [INFO] [STDOUT] JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
2014-12-30 21:07:26 [INFO] [STDOUT] AABB Pool Size: 3141 (175896 bytes; 0 MB) allocated, 2743 (153608 bytes; 0 MB) used
2014-12-30 21:07:26 [INFO] [STDOUT] Suspicious classes: FML and Forge are installed
2014-12-30 21:07:26 [INFO] [STDOUT] IntCache: cache: 0, tcache: 0, allocated: 3, tallocated: 63
2014-12-30 21:07:26 [INFO] [STDOUT] FML: MCP v8.11 FML v6.4.49.965 Minecraft Forge 9.11.1.965 4 mods loaded, 4 mods active
2014-12-30 21:07:26 [INFO] [STDOUT] mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2014-12-30 21:07:26 [INFO] [STDOUT] FML{6.4.49.965} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2014-12-30 21:07:26 [INFO] [STDOUT] Forge{9.11.1.965} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2014-12-30 21:07:26 [INFO] [STDOUT] brandoncom{0.0.1} [BrandonCo. Magika] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2014-12-30 21:07:26 [INFO] [STDOUT] Profiler Position: N/A (disabled)
2014-12-30 21:07:26 [INFO] [STDOUT] Vec3 Pool Size: 2473 (138488 bytes; 0 MB) allocated, 2343 (131208 bytes; 0 MB) used
2014-12-30 21:07:26 [INFO] [STDOUT] Player Count: 1 / 8; [EntityPlayerMP['Player79'/205, l='New World', x=223.58, y=74.00, z=236.13]]
2014-12-30 21:07:26 [INFO] [STDOUT] Type: Integrated Server (map_client.txt)
2014-12-30 21:07:26 [INFO] [STDOUT] Is Modded: Definitely; Client brand changed to 'fml,forge'
2014-12-30 21:07:26 [INFO] [STDOUT] #@[email protected]# Game crashed! Crash report saved to: #@[email protected]# .\crash-reports\crash-2014-12-30_21.07.26-server.txt
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Stopping server
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving players
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving worlds
2014-12-30 21:07:26 [INFO] [Minecraft-Server] Saving chunks for level 'New World'/Overworld
AL lib: (EE) alc_cleanup: 1 device not closed
I've checked everything twice and I personally can't find a x and y variable that the inventory starts at. If you could just point me in the right direction that would be great. Thanks
Okay so everything about this post makes sense until I get to the Packet Handler, I have researched about it from your posts on GitHub and Forums but on the update to 1.7 when you say to just copy over the code into the Packet Handler code presented in your examples I don't understand which code and where, the PacketPipeline class is its own class, this is what I have with the Handler. I dont know what to put, I have my GuiHandler as my Server Proxy. The only thing I have no clue on how to do is setup the Packet Handler. All I want is to add one extra Armor slot.
private void handleOpenServerGui(Packet250CustomPayload packet, EntityPlayer player, DataInputStream inputStream)
{
int guiID;
// inputStream is already open, so we don't need to do anything other than continue reading from it:
try {
guiID = inputStream.readInt();
} catch (IOException e) {
e.printStackTrace();
return;
}
// Now we can open the server gui element:
player.openGui(MainRegistry.instance, guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
}
Okay so everything about this post makes sense until I get to the Packet Handler, I have researched about it from your posts on GitHub and Forums but on the update to 1.7 when you say to just copy over the code into the Packet Handler code presented in your examples I don't understand which code and where, the PacketPipeline class is its own class, this is what I have with the Handler. I dont know what to put, I have my GuiHandler as my Server Proxy. The only thing I have no clue on how to do is setup the Packet Handler. All I want is to add one extra Armor slot.
That's assuming you had at least updated your 1.7 network code to use a sane packet system rather than the mess that was so popular in 1.6.4 and earlier. So yes, IF you had been using the PacketPipeline, which is itself outdated, you could have easily updated your packet classes to implement IMessage and embed the handler as a static inner class.
Since your code is not like that, however, you will have to write real packet classes as well as handlers for your code. Here is my tutorial on updating the network, but you may want to try the simpler one linked from there instead.
I actually already have your tutorial in my program, the tutorial on the Packet Handler really confused me so I have been just adding in outdated classes apparently, so for the PacketHandler stuff, would that be put into the AbstractMessageHandler?
I actually already have your tutorial in my program, the tutorial on the Packet Handler really confused me so I have been just adding in outdated classes apparently, so for the PacketHandler stuff, would that be put into the AbstractMessageHandler?
If you don't understand it, don't use it - that's why I linked to the simpler SimpleNetworkWrapper tutorial by diesieben07. Just use that one, there is no real difference in functionality.
Hello, CoolAlias.
I tried to add a custom player inventory to 1.6.4, but i have a crash (In smp) and an internal server error (in mp) when i try to open inventory
My Internal Error on server
2015-01-11 15:24:21 [SEVERE] [ForgeModLoader] A critical server error occured handling a packet, kicking 279
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.TcpConnection.processReadPackets(TcpConnection.java:462)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.dedicated.DedicatedServerListenThread.networkTick(DedicatedServerListenThread.java:30)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:276)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
2015-01-11 15:24:21 [WARNING] [Minecraft-Server] Failed to handle packet for Player1234/127.0.0.1: java.lang.NullPointerException
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.TcpConnection.processReadPackets(TcpConnection.java:462)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.dedicated.DedicatedServerListenThread.networkTick(DedicatedServerListenThread.java:30)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:276)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
My crash in single game
---- Minecraft Crash Report ----
// Don't do that.
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
-- Ticking connection --
Details:
Connection: [email protected]
Stacktrace:
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class ContainerCustomPlayer extends Container
{
/** Avoid magic numbers! This will greatly reduce the chance of you making errors in 'transferStackInSlot' method */
private static final int ARMOR_START = InventoryCustomPlayer.INV_SIZE, ARMOR_END = ARMOR_START+3,
INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,
HOTBAR_END = HOTBAR_START+8;
public ContainerCustomPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer inventoryCustom)
{
int i;
// Add CUSTOM slots - we'll just add two for now, both of the same type.
// Make a new Slot class for each different item type you want to add
this.addSlotToContainer(new SlotCustom(inventoryCustom, 0, 80, 8));
this.addSlotToContainer(new SlotCustom(inventoryCustom, 1, 80, 26));
// Add ARMOR slots; note you need to make a public version of SlotArmor
// just copy and paste the vanilla code into a new class and change what you need
for (i = 0; i < 4; ++i)
{
this.addSlotToContainer(new SlotArmor(player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18,
i));
}
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// Add ACTION BAR - just copied/pasted from vanilla classes
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
/**
* This should always return true, since custom inventory can be accessed from anywhere
*/
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/
public ItemStack transferStackInSlot(EntityPlayer player, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
// Either armor slot or custom item slot was clicked
if (par2 < INV_START)
{
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else
{
// if item is our custom item
if (itemstack1.getItem() instanceof Item)
{
if (!this.mergeItemStack(itemstack1, 0, InventoryCustomPlayer.INV_SIZE, false))
{
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor)
{
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
{
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
{
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false))
{
return null;
}
}
}
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
@SideOnly(Side.CLIENT)
public class GuiCustomPlayerInventory extends GuiContainer
{
/** x size of the inventory window in pixels. Defined as float, passed as int */
private float xSize_lo;
/** y size of the inventory window in pixels. Defined as float, passed as int. */
private float ySize_lo;
/** Normally I use '(ModInfo.MOD_ID, "textures/...")', but it can be done this way as well */
private static final ResourceLocation iconLocation = new ResourceLocation("tutorial:textures/gui/custom_inventory.png");
/** Could use IInventory type to be more generic, but this way will save an import... */
private final InventoryCustomPlayer inventory;
public GuiCustomPlayerInventory(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer
inventoryCustom)
{
super(new ContainerCustomPlayer(player, inventoryPlayer, inventoryCustom));
this.inventory = inventoryCustom;
// if you need the player for something later on, store it in a local variable here as well
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float f)
{
super.drawScreen(mouseX, mouseY, f);
xSize_lo = mouseX;
ySize_lo = mouseY;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
// This method will simply draw inventory names on the screen - you could do without it entirely
// if that's not important to you, since we are overriding the default inventory rather than
// creating a specific type of inventory
String s = this.inventory.isInvNameLocalized() ? this.inventory.getInvName() : I18n.getString(this.inventory.getInvName());
// with the name "Custom Inventory", the 'Cu' will be drawn in the first slot
this.fontRenderer.drawString(s, this.xSize - this.fontRenderer.getStringWidth(s), 12, 4210752);
// this just adds "Inventory" above the player's inventory below
this.fontRenderer.drawString(I18n.getString("container.inventory"), 80, this.ySize - 96, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(iconLocation);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
drawPlayerModel(guiLeft + 51, guiTop + 75, 30, guiLeft + 51 - xSize_lo, guiTop + 25 - ySize_lo, mc.thePlayer);
}
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class InventoryCustomPlayer implements IInventory
{
/** The name your custom inventory will display in the GUI, possibly just "Inventory" */
private final String name = "Custom Inventory";
/** The key used to store and retrieve the inventory from NBT */
private final String tagName = "CustomInvTag";
/** Define the inventory size here for easy reference */
// This is also the place to define which slot is which if you have different types,
// for example SLOT_SHIELD = 0, SLOT_AMULET = 1;
public static final int INV_SIZE = 2;
/** Inventory's size must be same as number of slots you add to the Container class */
private ItemStack[] inventory = new ItemStack[INV_SIZE];
public InventoryCustomPlayer()
{
// don't need anything here!
}
@Override
public int getSizeInventory()
{
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize > amount)
{
stack = stack.splitStack(amount);
this.onInventoryChanged();
}
else
{
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public String getInvName()
{
return name;
}
@Override
public boolean isInvNameLocalized()
{
return name.length() > 0;
}
/**
* Our custom slots are similar to armor - only one item per slot
*/
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void onInventoryChanged()
{
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
inventory = null;
}
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
@Override
public void openChest() {}
@Override
public void closeChest() {}
/**
* This method doesn't seem to do what it claims to do, as
* items can still be left-clicked and placed in the inventory
* even when this returns false
*/
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
// If you have different kinds of slots, then check them here:
// if (slot == SLOT_SHIELD && itemstack.getItem() instanceof ItemShield) return true;
// For now, only ItemUseMana items can be stored in these slots
return itemstack.getItem() instanceof Item;
}
public void writeToNBT(NBTTagCompound compound)
{
NBTTagList items = new NBTTagList();
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null)
{
NBTTagCompound item = new NBTTagCompound();
item.setByte("Slot", (byte) i);
getStackInSlot(i).writeToNBT(item);
items.appendTag(item);
}
}
// We're storing our items in a custom tag list using our 'tagName' from above
// to prevent potential conflicts
compound.setTag(tagName, items);
}
public void readFromNBT(NBTTagCompound compound)
{
NBTTagList items = compound.getTagList(tagName);
for (int i = 0; i < items.tagCount(); ++i)
{
NBTTagCompound item = (NBTTagCompound) items.tagAt(i);
byte slot = item.getByte("Slot");
/**
* Created by Alexey(DominuS) on 11.01.2015.
*/
public class SlotArmor extends Slot
{
/** The armor type that can be placed on that slot, it uses the same values of armorType field on ItemArmor. */
final int armorType;
/** The parent class of this slot, ContainerPlayer, SlotArmor is a Anon inner class. */
final EntityPlayer player;
public SlotArmor(EntityPlayer player, IInventory inventory, int slotIndex, int x, int y, int armorType)
{
super(inventory, slotIndex, x, y);
this.player = player;
this.armorType = armorType;
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
* of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
public boolean isItemValid(ItemStack itemstack)
{
Item item = (itemstack == null ? null : itemstack.getItem());
return item != null && item.isValidArmor(itemstack, armorType, player);
}
/**
* Returns the icon index on items.png that is used as background image of the slot.
*/
@SideOnly(Side.CLIENT)
public Icon getBackgroundIconIndex()
{
return ItemArmor.func_94602_b(this.armorType);
}
}
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class SlotCustom extends Slot
{
public SlotCustom(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots
* (and now also not always true for our custom inventory slots)
*/
@Override
public boolean isItemValid(ItemStack stack)
{
// We only want our custom item to be storable in this slot
return stack.getItem() instanceof Item;
}
}
/**
* Created by Alexey on 28.12.2014.
*/
public class CommonProxy implements IGuiHandler {
public void load() {}
public void openGui(EntityPlayer player, Object guiscreen) {
}
public void spawnParticle(EntityLivingBase player, String string, float[]Color, int Number) {}
/* public boolean hasClient() {
return false;
}*/
public EntityPlayer getPlayer() {
return null;
}
public void registerItem(int itemID) {}
/* public Object loadResource(String texture) {
return null;
}*/
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) {
return new ContainerCustomPlayer(player, player.inventory, ExtendedPlayer.get(player).inventory);
} else {
return null;
}
}
@Override
public Object getClientGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) {
return new GuiCustomPlayerInventory(player, player.inventory, ExtendedPlayer.get(player).inventory);
} else {
return null;
}
}
}
@Mod(modid = Main.MODID, name = Main.MODNAME/*, version = Main.VERSION*/)
public class Main {
public static final String MODID = "mesminemod";
public static final String MODNAME = "SFSI";
@SidedProxy(
clientSide = "ru.alexey.dominus.mesminemod.service.ClientProxy",
serverSide = "ru.alexey.dominus.mesminemod.service.CommonProxy"
)
public static CommonProxy proxy;
private static int modGuiIndex = 0;
public static final int GUI_CUSTOM_INV = modGuiIndex++;
@Mod.Instance
public static Main instance = new Main();
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e)
NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy());
}
@Mod.EventHandler
public void Init(FMLInitializationEvent e){
Did you even read your crash report? It tells you exactly what the problem is:
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
Whatever line 44 is has a NULL value somewhere. Add a break point or put each part of the call on a different line to figure out what is NULL, and then you can figure out how to make it not null.
Did you even read your crash report? It tells you exactly what the problem is:
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
Whatever line 44 is has a NULL value somewhere. Add a break point or put each part of the call on a different line to figure out what is NULL, and then you can figure out how to make it not null.
I read it.
44 line is
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) { return new ContainerCustomPlayer(player, player.inventory, ExtendedPlayer.get(player).inventory); <--- it is 44 line
} else {
return null;
}
}
I can't understand how to fix it. I tried to System.out.Println every argument which uses there, it was OK.
I can't understand how to fix it. I tried to System.out.Println every argument which uses there, it was OK.
Ok, then try this:
if (guiId == Main.GUI_CUSTOM_INV) {
return new ContainerCustomPlayer(
player,
player.inventory,
ExtendedPlayer.get(player).inventory);
}
Then tell me which line it is. My guess is 'ExtendedPlayer.get(player).inventory' - did you register your extended properties during entity construction?
if (guiId == Main.GUI_CUSTOM_INV) {
return new ContainerCustomPlayer(
player,
player.inventory,
ExtendedPlayer.get(player).inventory);
}
Then tell me which line it is. My guess is 'ExtendedPlayer.get(player).inventory' - did you register your extended properties during entity construction?
Oh.. Really, I fogot to register extended properties.. I'm sorry. Forge Api is difficult to me after 1 year developing under bukkit. Thank you very much.
The last question:
I want to make an overlay which will display items from this inventory near ingame hotbar.
I added "public static IInventory inv;" to my Container, after that I tried to call it from another class to get item in slot with this code:
Item item = Container.inv.getStackInSlot(1).getItem();
But I had an "NPE" error because Container wasn't initislized.
How I can initialize Container to get items from this inventory without openning gui (with realtime refreshing)?
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumPost your main mod class - there is probably something missing.
package net.brandoncom.mod; import net.brandoncom.mod.block.oreAirGem; import net.brandoncom.mod.block.oreLavaGem; import net.brandoncom.mod.block.oreWaterGem; import net.brandoncom.mod.item.itemAirPendant; import net.brandoncom.mod.item.itemBag; import net.brandoncom.mod.item.itemBasic; import net.brandoncom.mod.item.itemLavaPendant; import net.brandoncom.mod.item.itemWaterPendant; import net.brandoncom.mod.proxy.CommonProxy; import net.brandoncom.mod.worldGen.WorldGeneratorAirGem; import net.brandoncom.mod.worldGen.WorldGeneratorLavaGem; import net.brandoncom.mod.worldGen.WorldGeneratorWaterGem; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Mod(modid = BrandonCoM.modid, name = "BrandonCo. Magika", version = "0.0.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false) public class BrandonCoM { public static final String modid = "brandoncom"; @Instance("BrandonCo.") public static BrandonCoM instance = new BrandonCoM(); @SidedProxy(clientSide = "net.brandoncom.mod.proxy.ClientProxy", serverSide = "net.brandoncom.mod.proxy.CommonProxy") public static CommonProxy proxy; private static int brandoncomGuiIndex = 0; public static final int GUI_ITEM_INV = brandoncomGuiIndex++; //-------------------------Block Item stating----------------- public static Item itemLavaPendant; public static Item itemWaterPendant; public static Item itemAirPendant; public static Item itemEmptyPendant; public static Item itemLavaGem; public static Item itemWaterGem; public static Item itemAirGem; public static Item itemBag; public static Block oreLavaGem; public static Block oreWaterGem; public static Block oreAirGem; //CreativeTawbs public static CreativeTabs brandoncomTab; @EventHandler public void preInit(FMLPreInitializationEvent e) { } @EventHandler public void load(FMLInitializationEvent e) { NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy()); //Custom CreativeTab Creation | [ TABNAME ] brandoncomTab = new CreativeTabs("brandoncomTab") { //Custom CreativeTab Icon Creation @SideOnly(Side.CLIENT) public int getTabIconItemIndex() { return Block.blockEmerald.blockID; } }; itemLavaPendant = new itemLavaPendant(9001, Block.lavaMoving).setUnlocalizedName("itemLavaPendant"); itemWaterPendant = new itemWaterPendant(9002, Block.waterMoving).setUnlocalizedName("itemWaterPendant"); itemAirPendant = new itemAirPendant(9003).setUnlocalizedName("itemAirPendant"); itemEmptyPendant = new itemBasic(9004).setUnlocalizedName("itemEmptyPendant"); itemLavaGem = new itemBasic(9005).setUnlocalizedName("itemLavaGem"); itemWaterGem = new itemBasic(9006).setUnlocalizedName("itemWaterGem"); itemAirGem = new itemBasic(9007).setUnlocalizedName("itemAirGem"); itemBag = new itemBag(9008).setUnlocalizedName("itemBag"); oreLavaGem = new oreLavaGem(3200, Material.rock).setTextureName("BrandonCoM:oreLavaGem"); MinecraftForge.setBlockHarvestLevel(oreLavaGem, "pickaxe", 2); oreWaterGem = new oreWaterGem(3201, Material.rock).setTextureName("BrandonCoM:oreWaterGem").setUnlocalizedName("oreWaterGem"); MinecraftForge.setBlockHarvestLevel(oreWaterGem, "pickaxe", 2); oreAirGem = new oreAirGem(3202, Material.rock).setTextureName("BrandonCoM:oreAirGem").setUnlocalizedName("oreAirGem"); MinecraftForge.setBlockHarvestLevel(oreAirGem, "pickaxe", 2); GameRegistry.addRecipe(new ItemStack(itemEmptyPendant), "XXX", "X X", "XXX",'X', Item.ingotIron); GameRegistry.addRecipe(new ItemStack(itemLavaPendant)," "," X "," Y ", 'X', itemEmptyPendant,'Y', itemLavaGem); GameRegistry.addRecipe(new ItemStack(itemWaterPendant)," "," X "," Y ", 'X', itemEmptyPendant,'Y', itemWaterGem); GameRegistry.addRecipe(new ItemStack(itemAirPendant)," "," X "," Y ", 'X', itemEmptyPendant,'Y', itemAirGem); GameRegistry.registerWorldGenerator(new WorldGeneratorLavaGem()); GameRegistry.registerWorldGenerator(new WorldGeneratorWaterGem()); GameRegistry.registerWorldGenerator(new WorldGeneratorAirGem()); registerItem(itemLavaPendant, "Lava Pendant"); registerItem(itemAirPendant, "Air Pendant"); registerItem(itemWaterPendant, "Water Pendant"); registerItem(itemEmptyPendant, "Empty Pendant"); registerItem(itemLavaGem, "Lava Gem"); registerItem(itemWaterGem, "Water Gem"); registerItem(itemAirGem, "Air Gem"); registerItem(itemBag, "Bag(Told you I could do it)"); registerBlock(oreLavaGem, "Lava Gem Ore"); registerBlock(oreWaterGem, "Water Gem Ore"); registerBlock(oreAirGem, "Air Gem Ore"); //Proxy Register proxy.registerThings(); proxy.registerRenderers(); } //Block Register public void registerBlock(Block block, String name) { GameRegistry.registerBlock(block, block.getUnlocalizedName()); LanguageRegistry.addName(block, name); } //Item Register public void registerItem(Item item, String name) { GameRegistry.registerItem(item, item.getUnlocalizedName()); LanguageRegistry.addName(item, name); } }Thanks for your help! Awesome tutorial
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumEDIT: Hey I'm also wondering if you could help me with making a bigger inventory that doesn't extend off into space. When I set the inv size the containers run off the screen. I would like to make there be 10 rows with 9 slots in each row, if you could help me with this that would be awesome!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAs for the inventory size, you can make it whatever size you want, you just have to reposition the slots on the screen. If you spend some time reading the code, then you would be able to figure it out for yourself. It's really not complicated.
Thanks for tips (I'm a newbie to the forums :P)
Crash Log
I've checked everything twice and I personally can't find a x and y variable that the inventory starts at. If you could just point me in the right direction that would be great. Thanks
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou wrote a Byte, but are trying to read an Integer - NBT must match exactly.
Slot positions are set in your Container class - all the 'addSlotToContainer(new Slot(inventory, index, posX, posY))' stuff.
import ibxm.Player;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import com.phantasyrealms.main.MainRegistry;
public class PacketHandler implements IPacketHandler{
public static final byte EXTENDED_PROPERTIES = 1, OPEN_SERVER_GUI = 2;
@Override
public void onPacketData(INetworkManager manager,
Packet250CustomPayload packet, Player player) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
byte packetType;
try {
// Read the packet type
packetType = inputStream.readByte();
} catch (IOException e) {
e.printStackTrace();
return;
}
if(packet.channel.equals("GenericClass")){
switch(packetType) {
case EXTENDED_PROPERTIES: handleClass(packet, player, inputStream); break;
case OPEN_SERVER_GUI: handleOpenServerGui(packet, (EntityPlayer) player, inputStream); break;
default: System.out.println("[PACKET][WARNING] Unknown packet type " + packetType);
}
}
//handleClass(packet, player);
/* }else if(packet.channel.equals("GenericSpec")){
handleSpec(packet, player, inputStream);
}*/
}
private void handleOpenServerGui(Packet250CustomPayload packet, EntityPlayer player, DataInputStream inputStream)
{
int guiID;
// inputStream is already open, so we don't need to do anything other than continue reading from it:
try {
guiID = inputStream.readInt();
} catch (IOException e) {
e.printStackTrace();
return;
}
// Now we can open the server gui element:
player.openGui(MainRegistry.instance, guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThat's assuming you had at least updated your 1.7 network code to use a sane packet system rather than the mess that was so popular in 1.6.4 and earlier. So yes, IF you had been using the PacketPipeline, which is itself outdated, you could have easily updated your packet classes to implement IMessage and embed the handler as a static inner class.
Since your code is not like that, however, you will have to write real packet classes as well as handlers for your code. Here is my tutorial on updating the network, but you may want to try the simpler one linked from there instead.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you don't understand it, don't use it - that's why I linked to the simpler SimpleNetworkWrapper tutorial by diesieben07. Just use that one, there is no real difference in functionality.
I tried to add a custom player inventory to 1.6.4, but i have a crash (In smp) and an internal server error (in mp) when i try to open inventory
My Internal Error on server
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.TcpConnection.processReadPackets(TcpConnection.java:462)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.dedicated.DedicatedServerListenThread.networkTick(DedicatedServerListenThread.java:30)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:276)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
2015-01-11 15:24:21 [WARNING] [Minecraft-Server] Failed to handle packet for Player1234/127.0.0.1: java.lang.NullPointerException
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.TcpConnection.processReadPackets(TcpConnection.java:462)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.dedicated.DedicatedServerListenThread.networkTick(DedicatedServerListenThread.java:30)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:276)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
My crash in single game
// Don't do that.
Time: 11.01.15 15:25
Description: Ticking memory connection
java.lang.NullPointerException
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at ru.alexey.dominus.mesminemod.service.CommonProxy.getServerGuiElement(CommonProxy.java:44)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:353)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.server(PacketHandlerServer.java:46)
at ru.alexey.dominus.mesminemod.service.packets.PacketHandlerServer.onPacketData(PacketHandlerServer.java:25)
at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130)
at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:61)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
-- Ticking connection --
Details:
Connection: [email protected]
Stacktrace:
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)
--CODE--
My ContainerCustomPlayer
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class ContainerCustomPlayer extends Container
{
/** Avoid magic numbers! This will greatly reduce the chance of you making errors in 'transferStackInSlot' method */
private static final int ARMOR_START = InventoryCustomPlayer.INV_SIZE, ARMOR_END = ARMOR_START+3,
INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,
HOTBAR_END = HOTBAR_START+8;
public ContainerCustomPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer inventoryCustom)
{
int i;
// Add CUSTOM slots - we'll just add two for now, both of the same type.
// Make a new Slot class for each different item type you want to add
this.addSlotToContainer(new SlotCustom(inventoryCustom, 0, 80, 8));
this.addSlotToContainer(new SlotCustom(inventoryCustom, 1, 80, 26));
// Add ARMOR slots; note you need to make a public version of SlotArmor
// just copy and paste the vanilla code into a new class and change what you need
for (i = 0; i < 4; ++i)
{
this.addSlotToContainer(new SlotArmor(player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18,
i));
}
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// Add ACTION BAR - just copied/pasted from vanilla classes
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
/**
* This should always return true, since custom inventory can be accessed from anywhere
*/
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/
public ItemStack transferStackInSlot(EntityPlayer player, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// Either armor slot or custom item slot was clicked
if (par2 < INV_START)
{
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else
{
// if item is our custom item
if (itemstack1.getItem() instanceof Item)
{
if (!this.mergeItemStack(itemstack1, 0, InventoryCustomPlayer.INV_SIZE, false))
{
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor)
{
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
{
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
{
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false))
{
return null;
}
}
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
}
}
My GuiCustomPlayerInventory
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
@SideOnly(Side.CLIENT)
public class GuiCustomPlayerInventory extends GuiContainer
{
/** x size of the inventory window in pixels. Defined as float, passed as int */
private float xSize_lo;
/** y size of the inventory window in pixels. Defined as float, passed as int. */
private float ySize_lo;
/** Normally I use '(ModInfo.MOD_ID, "textures/...")', but it can be done this way as well */
private static final ResourceLocation iconLocation = new ResourceLocation("tutorial:textures/gui/custom_inventory.png");
/** Could use IInventory type to be more generic, but this way will save an import... */
private final InventoryCustomPlayer inventory;
public GuiCustomPlayerInventory(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer
inventoryCustom)
{
super(new ContainerCustomPlayer(player, inventoryPlayer, inventoryCustom));
this.inventory = inventoryCustom;
// if you need the player for something later on, store it in a local variable here as well
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float f)
{
super.drawScreen(mouseX, mouseY, f);
xSize_lo = mouseX;
ySize_lo = mouseY;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
// This method will simply draw inventory names on the screen - you could do without it entirely
// if that's not important to you, since we are overriding the default inventory rather than
// creating a specific type of inventory
String s = this.inventory.isInvNameLocalized() ? this.inventory.getInvName() : I18n.getString(this.inventory.getInvName());
// with the name "Custom Inventory", the 'Cu' will be drawn in the first slot
this.fontRenderer.drawString(s, this.xSize - this.fontRenderer.getStringWidth(s), 12, 4210752);
// this just adds "Inventory" above the player's inventory below
this.fontRenderer.drawString(I18n.getString("container.inventory"), 80, this.ySize - 96, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(iconLocation);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
drawPlayerModel(guiLeft + 51, guiTop + 75, 30, guiLeft + 51 - xSize_lo, guiTop + 25 - ySize_lo, mc.thePlayer);
}
/**
* Copied straight out of vanilla - renders the player model on screen
*/
public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) {
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef(x, y, 50.0F);
GL11.glScalef(-scale, scale, scale);
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
float f2 = entity.renderYawOffset;
float f3 = entity.rotationYaw;
float f4 = entity.rotationPitch;
float f5 = entity.prevRotationYawHead;
float f6 = entity.rotationYawHead;
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F;
entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F;
entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F;
entity.rotationYawHead = entity.rotationYaw;
entity.prevRotationYawHead = entity.rotationYaw;
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180.0F;
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
entity.renderYawOffset = f2;
entity.rotationYaw = f3;
entity.rotationPitch = f4;
entity.prevRotationYawHead = f5;
entity.rotationYawHead = f6;
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
}
My InventoryCustomPlayer
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class InventoryCustomPlayer implements IInventory
{
/** The name your custom inventory will display in the GUI, possibly just "Inventory" */
private final String name = "Custom Inventory";
/** The key used to store and retrieve the inventory from NBT */
private final String tagName = "CustomInvTag";
/** Define the inventory size here for easy reference */
// This is also the place to define which slot is which if you have different types,
// for example SLOT_SHIELD = 0, SLOT_AMULET = 1;
public static final int INV_SIZE = 2;
/** Inventory's size must be same as number of slots you add to the Container class */
private ItemStack[] inventory = new ItemStack[INV_SIZE];
public InventoryCustomPlayer()
{
// don't need anything here!
}
@Override
public int getSizeInventory()
{
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize > amount)
{
stack = stack.splitStack(amount);
this.onInventoryChanged();
}
else
{
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
ItemStack stack = getStackInSlot(slot);
setInventorySlotContents(slot, null);
return stack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack)
{
this.inventory[slot] = itemstack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
{
itemstack.stackSize = this.getInventoryStackLimit();
}
this.onInventoryChanged();
}
@Override
public String getInvName()
{
return name;
}
@Override
public boolean isInvNameLocalized()
{
return name.length() > 0;
}
/**
* Our custom slots are similar to armor - only one item per slot
*/
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void onInventoryChanged()
{
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
inventory = null;
}
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
@Override
public void openChest() {}
@Override
public void closeChest() {}
/**
* This method doesn't seem to do what it claims to do, as
* items can still be left-clicked and placed in the inventory
* even when this returns false
*/
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
// If you have different kinds of slots, then check them here:
// if (slot == SLOT_SHIELD && itemstack.getItem() instanceof ItemShield) return true;
// For now, only ItemUseMana items can be stored in these slots
return itemstack.getItem() instanceof Item;
}
public void writeToNBT(NBTTagCompound compound)
{
NBTTagList items = new NBTTagList();
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null)
{
NBTTagCompound item = new NBTTagCompound();
item.setByte("Slot", (byte) i);
getStackInSlot(i).writeToNBT(item);
items.appendTag(item);
}
}
// We're storing our items in a custom tag list using our 'tagName' from above
// to prevent potential conflicts
compound.setTag(tagName, items);
}
public void readFromNBT(NBTTagCompound compound)
{
NBTTagList items = compound.getTagList(tagName);
for (int i = 0; i < items.tagCount(); ++i)
{
NBTTagCompound item = (NBTTagCompound) items.tagAt(i);
byte slot = item.getByte("Slot");
if (slot >= 0 && slot < getSizeInventory()) {
inventory[slot] = ItemStack.loadItemStackFromNBT(item);
}
}
}
}
My SlotArmor
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
/**
* Created by Alexey(DominuS) on 11.01.2015.
*/
public class SlotArmor extends Slot
{
/** The armor type that can be placed on that slot, it uses the same values of armorType field on ItemArmor. */
final int armorType;
/** The parent class of this slot, ContainerPlayer, SlotArmor is a Anon inner class. */
final EntityPlayer player;
public SlotArmor(EntityPlayer player, IInventory inventory, int slotIndex, int x, int y, int armorType)
{
super(inventory, slotIndex, x, y);
this.player = player;
this.armorType = armorType;
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
* of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
public boolean isItemValid(ItemStack itemstack)
{
Item item = (itemstack == null ? null : itemstack.getItem());
return item != null && item.isValidArmor(itemstack, armorType, player);
}
/**
* Returns the icon index on items.png that is used as background image of the slot.
*/
@SideOnly(Side.CLIENT)
public Icon getBackgroundIconIndex()
{
return ItemArmor.func_94602_b(this.armorType);
}
}
SlotArmor
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Created by Alexey(DominuS) on 10.01.2015.
*/
public class SlotCustom extends Slot
{
public SlotCustom(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots
* (and now also not always true for our custom inventory slots)
*/
@Override
public boolean isItemValid(ItemStack stack)
{
// We only want our custom item to be storable in this slot
return stack.getItem() instanceof Item;
}
}
My CommonProxy
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import ru.alexey.dominus.mesminemod.Main;
import ru.alexey.dominus.mesminemod.srs.ExtendedPlayer;
import ru.alexey.dominus.mesminemod.srs.gui.sgui.ContainerCustomPlayer;
import ru.alexey.dominus.mesminemod.srs.gui.sgui.GuiCustomPlayerInventory;
/**
* Created by Alexey on 28.12.2014.
*/
public class CommonProxy implements IGuiHandler {
public void load() {}
public void openGui(EntityPlayer player, Object guiscreen) {
}
public void spawnParticle(EntityLivingBase player, String string, float[]Color, int Number) {}
/* public boolean hasClient() {
return false;
}*/
public EntityPlayer getPlayer() {
return null;
}
public void registerItem(int itemID) {}
/* public Object loadResource(String texture) {
return null;
}*/
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) {
return new ContainerCustomPlayer(player, player.inventory, ExtendedPlayer.get(player).inventory);
} else {
return null;
}
}
@Override
public Object getClientGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) {
return new GuiCustomPlayerInventory(player, player.inventory, ExtendedPlayer.get(player).inventory);
} else {
return null;
}
}
}
channels = {"SFSI Player"},
clientPacketHandlerSpec = @NetworkMod.SidedPacketHandler(
channels = {"SFSI Client", "SFSI Player"},
packetHandler = PacketHandlerClient.class
),
serverPacketHandlerSpec = @NetworkMod.SidedPacketHandler(
channels = {"SFSI Server", "SFSI Player"},
packetHandler = PacketHandlerServer.class
)
)
@Mod(modid = Main.MODID, name = Main.MODNAME/*, version = Main.VERSION*/)
public class Main {
public static final String MODID = "mesminemod";
public static final String MODNAME = "SFSI";
@SidedProxy(
clientSide = "ru.alexey.dominus.mesminemod.service.ClientProxy",
serverSide = "ru.alexey.dominus.mesminemod.service.CommonProxy"
)
public static CommonProxy proxy;
private static int modGuiIndex = 0;
public static final int GUI_CUSTOM_INV = modGuiIndex++;
@Mod.Instance
public static Main instance = new Main();
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e)
NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy());
}
@Mod.EventHandler
public void Init(FMLInitializationEvent e){
proxy.load();
}
}
My button actionperformed method
public void actionPerformed(GuiButton button){
switch(button.id) {
case 100:
// Main.proxy.openGui(player, 228);
// player.openGui(Main.instance, Main.GUI_CUSTOM_INV, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
try {
Util.sendOpenGuiPacket(Main.GUI_CUSTOM_INV);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
My PacketHandlerServer
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import ru.alexey.dominus.mesminemod.Main;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
/**
* Created by Alexey on 02.01.2015.
*/
public class PacketHandlerServer implements IPacketHandler {
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
if(packet.channel.equals("SFSI Server")) {
try {
DataInputStream e = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(packet.data))));
this.server(e, (EntityPlayerMP)player, EnumPacketType.values()[e.readInt()]);
e.close();
} catch (IOException var5) {
var5.printStackTrace();
}
}
}
private void server(DataInputStream dis, EntityPlayerMP player, EnumPacketType type) throws IOException {
if (type == EnumPacketType.SInv){
int guiID;
// inputStream is already open, so we don't need to do anything other than continue reading from it:
guiID = dis.readInt();
player.openGui(Main.instance, guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
}
}
My Util Class
import cpw.mods.fml.common.network.PacketDispatcher;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.zip.GZIPOutputStream;
/**
* Created by Alexey on 02.01.2015.
*/
public class Util {
public static DataOutputStream getDataOutputStream(ByteArrayOutputStream stream) throws IOException {
return new DataOutputStream(new GZIPOutputStream(stream));
}
public static void sendOpenGuiPacket(int guiID) throws IOException {
ByteArrayOutputStream e = new ByteArrayOutputStream();
DataOutputStream outputStream = getDataOutputStream(e);
System.out.println(guiID);
try {
outputStream.writeInt(EnumPacketType.SInv.ordinal());
outputStream.writeInt(guiID);
outputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
}
PacketDispatcher.sendPacketToServer(PacketDispatcher.getPacket("SFSI Server", e.toByteArray()));
}
}
I checked packet handling and it works well, but i can't say it about gui open methods - they don't work.
Help me please with it.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWhatever line 44 is has a NULL value somewhere. Add a break point or put each part of the call on a different line to figure out what is NULL, and then you can figure out how to make it not null.
I read it.
44 line is
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
{
if (guiId == Main.GUI_CUSTOM_INV) {
return new ContainerCustomPlayer(player, player.inventory, ExtendedPlayer.get(player).inventory); <--- it is 44 line
} else {
return null;
}
}
I can't understand how to fix it. I tried to System.out.Println every argument which uses there, it was OK.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumOk, then try this:
if (guiId == Main.GUI_CUSTOM_INV) { return new ContainerCustomPlayer( player, player.inventory, ExtendedPlayer.get(player).inventory); }Then tell me which line it is. My guess is 'ExtendedPlayer.get(player).inventory' - did you register your extended properties during entity construction?Oh.. Really, I fogot to register extended properties.. I'm sorry. Forge Api is difficult to me after 1 year developing under bukkit. Thank you very much.
I want to make an overlay which will display items from this inventory near ingame hotbar.
I added "public static IInventory inv;" to my Container, after that I tried to call it from another class to get item in slot with this code:
Item item = Container.inv.getStackInSlot(1).getItem();
But I had an "NPE" error because Container wasn't initislized.
How I can initialize Container to get items from this inventory without openning gui (with realtime refreshing)?