I'm working on my mod Exp Chest and am having issues saving the tile entity's data. This is the code I have for saving in my tile entity class. When I change the exp values and then exit the game and return into the game the values are reset to 0.
Did you register the tile entity with the game registry? Make sure the string to entity mapping is correct, that can be a reason why data won't load. Look for any outputs in the console that are errors.
Tutorial: http://www.minecraftforge.net/wiki/Packet_Handling
In most cases you use PacketDispatcher class to deal with sending the packet to the appropriate parties. For a tile entity, override the getDescriptionPacket() to send your custom packet when the tile entity is loaded.
Make sure you've got a packet handler and you're using the Packet250CustomPayload packets with your custom channel and that you're registering the handler with the same channel, in the @NetworkMod annotation.
Also it's good to understand the relationship between the client and the server and which direction packets should go in which cases. Also be sure you're not packet spamming and sending wayyyy too many. Easy mistake.
Some of my code here contains a simple example of a packet. In my GUI class, here, when the button is pressed it calls this method:
public boolean mousePressed(Minecraft mc, int par2, int par3) {
boolean fireButton = super.mousePressed(mc, par2, par3);
if(fireButton){
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketDispatcher.sendPacketToServer(new Packet250CustomPayload(PBPacketHandler.PACKET_CHANNEL, new byte[]{1}));
}
return fireButton;
}
Since we're obviously on the client, since we're in a gui, we want to send the packet to the server and have it do something. So I make a simple little packet with my channel and a byte array (typical format) with the only byte in it being a "1". Once the PacketHandler, here, gets the packet passed to it (forge does this because of the channel I registered) it checks the length of the byte array, sees that the length of the array is only one and passes it off to the the method that handles the "tiny" packets in my handler. Then the server executes some code to clear the inventory and then sends it all to the player so it updates correctly.
This isn't an example of syncing information really, but rather of the client causing the server to do something in response to the client's action. It's pretty much the core idea of packets.
would you mind sharing the exact fix for the first issue? I'm having the exact same issue and can't see where I went wrong. at this point 90% of my code is just borrowed temporarily from skeleton heads and I haven't touched the tile entity code whatsoever apart from some name swapping.
would you mind sharing the exact fix for the first issue? I'm having the exact same issue and can't see where I went wrong. at this point 90% of my code is just borrowed temporarily from skeleton heads and I haven't touched the tile entity code whatsoever apart from some name swapping.
The above answer should be all which is needed.
You will need to learn about packet and syncing server<->client if you are to do anything involving client input such as keybindings or gui input.
If you are unfamiliar with programming, then you should start there.
Most people will just ignore such advise, but if you care to learn see below
I don't believe in 14 year olds on youtube rambling on about java basics, simply because they tend to do one or more of the following:
Skip important things.
Lack real insight in what they are teaching and why (Aka. Do this, don't care why, it just works!)
Lacks a proper learning path and progression towards terminology, programming and logic design which are your goals to learn when learning a programming language, is it not?
Now I've found some exceptions to this, and you may find things that suit you better.
But I do whole heartedly recommend the course I'm linking below.
CS106A - Programming Methodology
It's a professional beginner course in programming, focused in Java.
100% Free course, made by Stanford university. No real pre-requisites to taking the course and it's just like the real course.
The real course was filmed and all the lecture videos are available along with all handouts and other materials given (Including their modified eclipse version, and example exams!).
From experience I can promise you that you will NOT be wasting your time by doing this first, you will be modding so much faster after mastering the basics that you will wonder why you didn't do this earlier. It's a small time to spend learning the basics compared to the time you waste struggling with simple things if you don't
The above answer should be all which is needed.You will need to learn about packet and syncing server<->client if you are to do anything involving client input such as keybindings or gui input.If you are unfamiliar with programming, then you should start there.Most people will just ignore such advise, but if you care to learn see below
I don't believe in 14 year olds on youtube rambling on about java basics, simply because they tend to do one or more of the following:Skip important things.Lack real insight in what they are teaching and why (Aka. Do this, don't care why, it just works!)Lacks a proper learning path and progression towards terminology, programming and logic design which are your goals to learn when learning a programming language, is it not? Now I've found some exceptions to this, and you may find things that suit you better.But I do whole heartedly recommend the course I'm linking below.CS106A - Programming MethodologyIt's a professional beginner course in programming, focused in Java.100% Free course, made by Stanford university. No real pre-requisites to taking the course and it's just like the real course.The real course was filmed and all the lecture videos are available along with all handouts and other materials given (Including their modified eclipse version, and example exams!).From experience I can promise you that you will NOT be wasting your time by doing this first, you will be modding so much faster after mastering the basics that you will wonder why you didn't do this earlier. It's a small time to spend learning the basics compared to the time you waste struggling with simple things if you don't Anyways here's the link; use it as you wish and good luck to you!http://see.stanford....aa-866adcae1111PS:Have fun coding!
Maz... seriously I wish someone like you had told me that back in 2010. (The link there WILL teach you java and give you a great foundation in programming (pre-8, of course)) I'm a CS major now, but learning programming from random youtube videos caused me a lot of confusion in the past.
I cannot rate this post any higher than +1 vote up, but if I could I would give this post plus 9001
Edit: Have you though about including that link in your Modding Database?
Follow @jamolnng
The best way to contact me is via twitter.
Follow @jamolnng
The best way to contact me is via twitter.
What's the problem?
Syncing the tile entity and player between the server and the player.
Follow @jamolnng
The best way to contact me is via twitter.
http://www.minecraftforge.net/wiki/Packet_Handling
In most cases you use PacketDispatcher class to deal with sending the packet to the appropriate parties. For a tile entity, override the getDescriptionPacket() to send your custom packet when the tile entity is loaded.
Make sure you've got a packet handler and you're using the Packet250CustomPayload packets with your custom channel and that you're registering the handler with the same channel, in the @NetworkMod annotation.
Also it's good to understand the relationship between the client and the server and which direction packets should go in which cases. Also be sure you're not packet spamming and sending wayyyy too many. Easy mistake.
Some of my code here contains a simple example of a packet. In my GUI class, here, when the button is pressed it calls this method:
Since we're obviously on the client, since we're in a gui, we want to send the packet to the server and have it do something. So I make a simple little packet with my channel and a byte array (typical format) with the only byte in it being a "1". Once the PacketHandler, here, gets the packet passed to it (forge does this because of the channel I registered) it checks the length of the byte array, sees that the length of the array is only one and passes it off to the the method that handles the "tiny" packets in my handler. Then the server executes some code to clear the inventory and then sends it all to the player so it updates correctly.
This isn't an example of syncing information really, but rather of the client causing the server to do something in response to the client's action. It's pretty much the core idea of packets.
Hope that helps a little bit.
How do you make mods?
The above answer should be all which is needed.
You will need to learn about packet and syncing server<->client if you are to do anything involving client input such as keybindings or gui input.
If you are unfamiliar with programming, then you should start there.
Most people will just ignore such advise, but if you care to learn see below
I don't believe in 14 year olds on youtube rambling on about java basics, simply because they tend to do one or more of the following:
Skip important things.
Lack real insight in what they are teaching and why (Aka. Do this, don't care why, it just works!)
Lacks a proper learning path and progression towards terminology, programming and logic design which are your goals to learn when learning a programming language, is it not?
Now I've found some exceptions to this, and you may find things that suit you better.
But I do whole heartedly recommend the course I'm linking below.
CS106A - Programming Methodology
It's a professional beginner course in programming, focused in Java.
100% Free course, made by Stanford university. No real pre-requisites to taking the course and it's just like the real course.
The real course was filmed and all the lecture videos are available along with all handouts and other materials given (Including their modified eclipse version, and example exams!).
From experience I can promise you that you will NOT be wasting your time by doing this first, you will be modding so much faster after mastering the basics that you will wonder why you didn't do this earlier. It's a small time to spend learning the basics compared to the time you waste struggling with simple things if you don't
Anyways here's the link; use it as you wish and good luck to you!
http://see.stanford.edu/see/lecturelist.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111
PS:
Have fun coding!
I cannot rate this post any higher than +1 vote up, but if I could I would give this post plus 9001
Edit: Have you though about including that link in your Modding Database?