I have an item that opens a gui allows you to write a question. After pressing the "save" button it creates a new ItemStack of another item with its own gui and writes a bunch of NBT values to this item.However, these values don't save properly. The booleanQuestion field is inverted (if you save it as a true/false question it saves it as a A-D question and vice versa). If it is a A-D question the buttons don't have a label, even though they should have the value of the text field that was used.
I have some in game examples of a A-D question here and a true/false question here. And no, I did not mix them up.
Rollback Post to RevisionRollBack
Teleporting XP, for when you want to improve performance with XP farms
In your message handler, you're checking if ItemStacks in the player's inventory are reference equal to an ItemStack you've read from the ByteBuf, which will never be true (since they'll never be the same object).
You need to use the static equality methods in the ItemStack class to check if two ItemStacks are equal.
That said, sending ItemStacks from the client to the server is a bad idea; you open the door for malicious clients to cheat in items. You should send the hand holding the paper and the data you want to save in the card (as individual values, not just an NBT compound tag) and let the server create the ItemStack with these values.
You could also reduce the ability to cheat at the quiz by not synchronising the correct answer ID to the client and letting the server determine whether the chosen answer was correct.
I'm not actually sure why the data isn't being saved properly. Have you tried stepping through the code in a debugger?
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Should I set the values in packet handler in an NBT, or somewhere else? And how do I get the correct answer in the server without syncing it to the client? The most I've done with packets at this point is just syncing values, not making the opposite.
Rollback Post to RevisionRollBack
Teleporting XP, for when you want to improve performance with XP farms
Should I set the values in packet handler in an NBT, or somewhere else? And how do I get the correct answer in the server without syncing it to the client? The most I've done with packets at this point is just syncing values, not making the opposite.
The packet handler should store the values from the packet in the ItemStack's NBT before giving it to the player.
The server will have the correct answer stored in the card ItemStack's NBT, you can send a packet from the client when the player makes a guess and then check the player's guess against the correct answer before sending a packet back to the client telling it whether or not the answer was correct.
You can override Item#getNBTShareTag to control what NBT data is sent to the client.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So now the packet handler sets the NBT data (CardWriteMessage now looks like this), but I don't understand what you mean with "the server" in this case. Where do I store it? How do I check it? Did I override getNBTShareTag properly?
Rollback Post to RevisionRollBack
Teleporting XP, for when you want to improve performance with XP farms
So now the packet handler sets the NBT data (CardWriteMessage now looks like this), but I don't understand what you mean with "the server" in this case. Where do I store it? How do I check it? Did I override getNBTShareTag properly?
By "the server", I mean store the data in the ItemStack that's in the inventory of the server-side player and use it in the server-side message handlers (or methods called from them).
Your override of Item#getNBTShareTag is incorrect, you need to create a copy of the stack's compound tag before removing the correct answer ID. You're currently removing it from the server-side stack, which you don't want to do.
CardWriteMessage is still sending the paper ItemStack and the handler is decrementing the ItemStack it's read from the buffer, which is completely separate from the paper ItemStack in the player's inventory. You need to send the EnumHand holding the paper ItemStack and decrement the ItemStack in that hand of the server-side player.
You should probably check that the player actually has paper in that hand before you decrement it and give them a card.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So I updated the answer packet again (it's now called AnswerHandlerMessage) and made it call the client equivalent of it (AnsweredMessage). I'm not really sure I know what I'm doing in this case though. The gui doesn't close, but it does give me a diamond (which is just for checking if it works). If I make the question a boolean question it also still shows answer C and D, which should be invisible.
Rollback Post to RevisionRollBack
Teleporting XP, for when you want to improve performance with XP farms
Don't send AnsweredMessage to everyone, only send it to the player that sent the AnswerHandlerMessage.
ItemQuizCard#getShareTag still has the same issue as before, the clientNBT variable references the same compound tag returned by ItemStack#getTagCompound so any changes made through the variable affect the ItemStack's compound tag.
Use NBTTagCompound#copy to create a copy of the ItemStack's compound tag before removing the correct answer ID from it.
I'm not sure why the boolean question status isn't working. Have you tried stepping through the code in a debugger to see where the incorrect value comes from?
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I just realised I haven't said this before, but making the packet handler save the NBT made it work better than before. The editor works fully as intended and the A-D questions on the card itself works as intended (4 answers that have the correct answer stored). The only thing that doesn't work properly is the true/false questions- they display 4 answers which say the correct things but two of them are visible even though they aren't supposed to.
I also figured out where the booleanQuestion variable is set to false, but not why. It's this line in CardWriteMessage.Handler. message#booleanQuestion is always false there, even though it was true in the class' constructor. Like I said I do not know why.
I also figured out where the booleanQuestion variable is set to false, but not why. It's this line in CardWriteMessage.Handler. message#booleanQuestion is always false there, even though it was true in the class' constructor. Like I said I do not know why.
You never write the booleanQuestion field to or read it from the byte buffer, so it's always false on the receiving side (after the packet has been instantiated with the zero-argument constructor).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I have an item that opens a gui allows you to write a question. After pressing the "save" button it creates a new ItemStack of another item with its own gui and writes a bunch of NBT values to this item.However, these values don't save properly. The booleanQuestion field is inverted (if you save it as a true/false question it saves it as a A-D question and vice versa). If it is a A-D question the buttons don't have a label, even though they should have the value of the text field that was used.
I have some in game examples of a A-D question here and a true/false question here. And no, I did not mix them up.
Teleporting XP, for when you want to improve performance with XP farms
In your message handler, you're checking if ItemStacks in the player's inventory are reference equal to an ItemStack you've read from the ByteBuf, which will never be true (since they'll never be the same object).
You need to use the static equality methods in the ItemStack class to check if two ItemStacks are equal.
That said, sending ItemStacks from the client to the server is a bad idea; you open the door for malicious clients to cheat in items. You should send the hand holding the paper and the data you want to save in the card (as individual values, not just an NBT compound tag) and let the server create the ItemStack with these values.
You could also reduce the ability to cheat at the quiz by not synchronising the correct answer ID to the client and letting the server determine whether the chosen answer was correct.
I'm not actually sure why the data isn't being saved properly. Have you tried stepping through the code in a debugger?
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Should I set the values in packet handler in an NBT, or somewhere else? And how do I get the correct answer in the server without syncing it to the client? The most I've done with packets at this point is just syncing values, not making the opposite.
Teleporting XP, for when you want to improve performance with XP farms
The packet handler should store the values from the packet in the ItemStack's NBT before giving it to the player.
The server will have the correct answer stored in the card ItemStack's NBT, you can send a packet from the client when the player makes a guess and then check the player's guess against the correct answer before sending a packet back to the client telling it whether or not the answer was correct.
You can override Item#getNBTShareTag to control what NBT data is sent to the client.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So now the packet handler sets the NBT data (CardWriteMessage now looks like this), but I don't understand what you mean with "the server" in this case. Where do I store it? How do I check it? Did I override getNBTShareTag properly?
Teleporting XP, for when you want to improve performance with XP farms
By "the server", I mean store the data in the ItemStack that's in the inventory of the server-side player and use it in the server-side message handlers (or methods called from them).
Your override of Item#getNBTShareTag is incorrect, you need to create a copy of the stack's compound tag before removing the correct answer ID. You're currently removing it from the server-side stack, which you don't want to do.
CardWriteMessage is still sending the paper ItemStack and the handler is decrementing the ItemStack it's read from the buffer, which is completely separate from the paper ItemStack in the player's inventory. You need to send the EnumHand holding the paper ItemStack and decrement the ItemStack in that hand of the server-side player.
You should probably check that the player actually has paper in that hand before you decrement it and give them a card.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So I updated the answer packet again (it's now called AnswerHandlerMessage) and made it call the client equivalent of it (AnsweredMessage). I'm not really sure I know what I'm doing in this case though. The gui doesn't close, but it does give me a diamond (which is just for checking if it works). If I make the question a boolean question it also still shows answer C and D, which should be invisible.
Teleporting XP, for when you want to improve performance with XP farms
Don't send AnsweredMessage to everyone, only send it to the player that sent the AnswerHandlerMessage.
ItemQuizCard#getShareTag still has the same issue as before, the clientNBT variable references the same compound tag returned by ItemStack#getTagCompound so any changes made through the variable affect the ItemStack's compound tag.
Use NBTTagCompound#copy to create a copy of the ItemStack's compound tag before removing the correct answer ID from it.
I'm not sure why the boolean question status isn't working. Have you tried stepping through the code in a debugger to see where the incorrect value comes from?
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I just realised I haven't said this before, but making the packet handler save the NBT made it work better than before. The editor works fully as intended and the A-D questions on the card itself works as intended (4 answers that have the correct answer stored). The only thing that doesn't work properly is the true/false questions- they display 4 answers which say the correct things but two of them are visible even though they aren't supposed to.
I also figured out where the booleanQuestion variable is set to false, but not why. It's this line in CardWriteMessage.Handler. message#booleanQuestion is always false there, even though it was true in the class' constructor. Like I said I do not know why.
Teleporting XP, for when you want to improve performance with XP farms
You never write the booleanQuestion field to or read it from the byte buffer, so it's always false on the receiving side (after the packet has been instantiated with the zero-argument constructor).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Ahh... It works properly finally! Thanks a ton!
One last question, however, if I may. I want the gui to close when a question is answered. How do I do this? The AnsweredMessage doesn't close it.
EDIT: Nevermind. I was overthinking it. All I have to do is close it in the gui. Thanks again!
Teleporting XP, for when you want to improve performance with XP farms