Alright, I cleaned up and corrected parts of the tutorial related to the Inventory-storing Item; seems I'd forgotten to update this page with the newer information from the github. For example, the Item#onUpdate is no longer needed for saving data, since it's all taken care of internally by the IInventory class now.
@CiDsPlay - you need to store the ItemStack that opened the inventory as a field in your Inventory class, and then write to NBT using that ItemStack's NBT tag in the markDirty method:
/** Provides NBT Tag Compound to reference */
private final ItemStack invItem;
public InventoryMagicBag(ItemStack stack) {
this.invItem = stack;
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
readFromNBT(stack.getTagCompound());
}
@Override
public void markDirty() {
for (int i = 0; i < getSizeInventory(); ++i) {
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
inventory[i] = null;
}
writeToNBT(invItem.getTagCompound());
}
My apologies to anyone who had trouble due to the outdated information. It should all be correct now.
Sorry to hijack your thread coolAlias, but Yekos: you need to add packetHandler=PacketHandler.class in your @NetworkMod statement in your main mod file.
I think that is all the code. It's all on the github otherwise
Thanks in advance, and thanks for the tutorial
Sorry to hijack your thread coolAlias, but Yekos: you need to add packetHandler=PacketHandler.class in your @NetworkMod statement in your main mod file.
You are crashing because your keybinding doesn't check if the player is actually holding the item needed for the inventory. If the player presses your key with the wrong item, or worse, nothing in their hand, you will have problems.
I have a little problem , Eclipse tell me : 2014-04-05 20:00:15 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod
Sorry for my bad english , i'm french ^^
Thanks for help.
Pas de problème - tu l'écrits mieux que j'écris français
Anyway, a large part of your problem is in your CommonProxy/GuiHandler class:
@SideOnly(Side.CLIENT) // oops! you don't want this in here!
@Override
public Object getServerGuiElement(
You are crashing because your keybinding doesn't check if the player is actually holding the item needed for the inventory. If the player presses your key with the wrong item, or worse, nothing in their hand, you will have problems.
Sorry, I forgot to say/didn't make it clear, I am trying to do a 'Custom Inventory in Player', like Tinker's Construct Armour GUI.
Sorry, I forgot to say/didn't make it clear, I am trying to do a 'Custom Inventory in Player', like Tinker's Construct Armour GUI.
Alright, well a few pointers then:
1. In your PacketHandler, you define IDs for your packets, but then use magic numbers in your handling switch (e.g. "case 10:" instead of "case PACKET_UPDATE:"; no point defining the IDs if you don't use them
2. When you write packets, you MUST write the packet ID first; in your ExtendedPlayer, you have:
First point, you don't need to write the name of the properties; second, what is "PACKET_OPEN_SERVER_GUI + 1" supposed to be? Certainly not any of your packet IDs... and finally, you never write any of your custom properties to the packet, so the client side will never update with any information! See the example "SyncPlayerPropsPacket" in the tutorial - in 1.6.4, you can still write and read the properties to NBT and send/receive that NBT data across the network.
3. Based on point #2 and the fact that you are getting a null pointer trying to open the client side GUI, I suspect that your ExtendedPlayer.get(player).inventory is null on the client side. To test this, try writing your code like this:
case GuiIDs.GUI_ID_VANITY:
return new GuiVanity(
player,
player.inventory,
ExtendedPlayer.get(player) // if the error is here, your ExtendedPlayer is returning null
.inventory); // if the error is here, your inventory field is null client side
4. When opening a GUI, you only need do so on the server - it will automatically attempt to open it for you on the client side; this means that you shouldn't open a gui client side directly if it has a server-side element. In your "keyDown" method, you send a packet and then try to open the gui directly on the client - try removing that line.
1. Thanks
2. Misinterpretation of instructions. (You commented "do this in your ExtendedPlayer.sync() method as well and add 1 to the size." in PacketOpenServerGUI)
3. It's the inventory that is null. Not sure why as I am initialising it: public final PlayerInventoryVanity inventory = new PlayerInventoryVanity();
4. Ah, good spot
2014-04-06 10:41:59 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod
2014-04-06 10:41:59 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod
Ah, I think I found it; in your CommonProxy:
NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy());
registerGuiHandler takes 2 parameters: Instance of your MainMod class, and the IGuiHandler. Either move that line of code to your main mod's preInit method, or change the parameters to (YourMainMod.instance, this).
Speaking of instance of your main mod, you have 2:
@Mod(modid = "WarOfUldah" // modid should be all lowercase! "warofuldah" is ok, "WarOfUldah" is not
// this is your main mod instance; to be clear, it would be better to rename it to "instance"
@Instance("warofuldah") // <-- this part is correct
public static WarOfUldia_Base warofuldah; // <-- rename this one to "instance"
// a duplicate! delete this one:
public static WarOfUldia_Base instance;
@Instance("warofuldah")
// your instance should go here
@SidedProxy(clientSide="_WarOfUldah.ClientProxy", serverSide="_WarOfUldah.CommonProxy")
// but it finds the CommonProxy first, and tries to assign it as your MainMod instance
// that's why you are crashing
public static CommonProxy proxy;
// oops - here is your instance way down here! move it up above so it's directly under "@Instance"
public static WarOfUldia_Base instance;
Also, in your main mod class, you never tell the proxy to register the gui handler.
@EventHandler
public void Init(FMLInitializationEvent event) // method names should start with lowercase: "init", not "Init"
{
// you commented it out, but this should work fine
// and then you can remove the registration code from your CommonProxy
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
// or you could tell the proxy to register the gui handler:
// proxy.registerGuiHandler();
// you shouldn't be doing this:
instance = this;
Hi , I have little problem on my custom inventory player.
If you can help me for fix this =)
Thanks for Help
Probably not related to your problem, but you should not create an instance of ClientProxy, remove this line from your main class: "public static ClientProxy cproxy"
The Inventory code seems to be missing from your post, and I may need to see each of your custom Slot classes as well.
@CiDsPlay - you need to store the ItemStack that opened the inventory as a field in your Inventory class, and then write to NBT using that ItemStack's NBT tag in the markDirty method:
My apologies to anyone who had trouble due to the outdated information. It should all be correct now.
I am getting this crash when I press my key:
http://pastebin.com/Sws24Zwu
And the relevant code:
Container, Inventory and stuff
https://github.com/warlordjones/SteamCraft2/tree/master/common/steamcraft/common/inventory
PacketHandler:
https://github.com/warlordjones/SteamCraft2/blob/master/common/steamcraft/common/network/PacketHandler.java
PacketOpenServerGui:
https://github.com/warlordjones/SteamCraft2/blob/master/common/steamcraft/common/network/PacketOpenServerGui.java
GuiHandler and Key Binding Things
https://github.com/warlordjones/SteamCraft2/tree/master/common/steamcraft/client/core/handler
ClientProxy:
https://github.com/warlordjones/SteamCraft2/blob/master/common/steamcraft/client/core/proxy/ClientProxy.java
I think that is all the code. It's all on the github otherwise
Thanks in advance, and thanks for the tutorial
Sorry to hijack your thread coolAlias, but Yekos: you need to add packetHandler=PacketHandler.class in your @NetworkMod statement in your main mod file.
You are crashing because your keybinding doesn't check if the player is actually holding the item needed for the inventory. If the player presses your key with the wrong item, or worse, nothing in their hand, you will have problems.
Pas de problème - tu l'écrits mieux que j'écris français
Anyway, a large part of your problem is in your CommonProxy/GuiHandler class:
Sorry, I forgot to say/didn't make it clear, I am trying to do a 'Custom Inventory in Player', like Tinker's Construct Armour GUI.
Alright, well a few pointers then:
1. In your PacketHandler, you define IDs for your packets, but then use magic numbers in your handling switch (e.g. "case 10:" instead of "case PACKET_UPDATE:"; no point defining the IDs if you don't use them
2. When you write packets, you MUST write the packet ID first; in your ExtendedPlayer, you have:
First point, you don't need to write the name of the properties; second, what is "PACKET_OPEN_SERVER_GUI + 1" supposed to be? Certainly not any of your packet IDs... and finally, you never write any of your custom properties to the packet, so the client side will never update with any information! See the example "SyncPlayerPropsPacket" in the tutorial - in 1.6.4, you can still write and read the properties to NBT and send/receive that NBT data across the network.
3. Based on point #2 and the fact that you are getting a null pointer trying to open the client side GUI, I suspect that your ExtendedPlayer.get(player).inventory is null on the client side. To test this, try writing your code like this:
4. When opening a GUI, you only need do so on the server - it will automatically attempt to open it for you on the client side; this means that you shouldn't open a gui client side directly if it has a server-side element. In your "keyDown" method, you send a packet and then try to open the gui directly on the client - try removing that line.
In your main mod class, you need to designate your PacketHandler class and channel:
2. Misinterpretation of instructions. (You commented "do this in your ExtendedPlayer.sync() method as well and add 1 to the size." in PacketOpenServerGUI)
3. It's the inventory that is null. Not sure why as I am initialising it: public final PlayerInventoryVanity inventory = new PlayerInventoryVanity();
4. Ah, good spot
I am now getting an NPE on the server side: http://pastebin.com/W09pib0G
Thanks so much for the help!
Ah, I think I found it; in your CommonProxy:
registerGuiHandler takes 2 parameters: Instance of your MainMod class, and the IGuiHandler. Either move that line of code to your main mod's preInit method, or change the parameters to (YourMainMod.instance, this).
Speaking of instance of your main mod, you have 2:
Also, in your main mod class, you never tell the proxy to register the gui handler.
Github somehow removed my onEntityConstructing method in my event handler.
It all works now, will post pictures soon. Thanks again for the awesome tutorial!
EDIT: Here
Now to fine tune the placement of stuff
Awesome Glad you got it working!
It's 100% working on 1.5.2, 1.6.4, 1.7.2
You're welcome, and awesome that you got it working on all three versions xD
Please, help me for fix code.
http://www.mediafire.com/download/zzk1iypir1z9fz0/aJamigaPack1.rar
(Sorry, I,m bad eng)
Sorry, I'm not going to download some random link. Either post your code here, use an online service such as Pastebin, or create a GitHub repository.
Try reading the tutorial again - I explicitly covered how to go about getting armor slots to work.
Probably not related to your problem, but you should not create an instance of ClientProxy, remove this line from your main class: "public static ClientProxy cproxy"
The Inventory code seems to be missing from your post, and I may need to see each of your custom Slot classes as well.
Please, help me for fix code.
--- ClientProxy ---
http://pastebin.com/YE2sFhMN
--- CommonProxy ---
http://pastebin.com/hH4sU57S
--- MainMod ---
http://pastebin.com/nVc9iTD5
--- ContainerCustomPlayer ---
http://pastebin.com/G33tCgsG
--- ExtendedPlayer ---
http://pastebin.com/NL9MiCRS
--- GuiCustomPlayerInventory ---
http://pastebin.com/zatQpUW6
--- InventoryCustomPlayer ---
http://pastebin.com/mEbGstKn
--- PacketHandler ---
http://pastebin.com/3LUegfga
--- PacketOpenServerGui ---
http://pastebin.com/mJmWWhAU
--- RegisterKeyBindings ---
http://pastebin.com/9TN69qJq
--- TutEventHandler ---
http://pastebin.com/jEHSvaYp
Thank.