this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel"));
// and remove this line, as it's not needed anymore:
this.level = properties.getInteger("newLevel");
Also, since you are using DataWatcher to track your level, you don't need to send a packet or worry about syncing anything at this point.
I changed the code as you said, but it did not help.
@Override
public void saveNBTData(NBTTagCompound compound) {
NBTTagCompound properties = new NBTTagCompound();
properties.setInteger("newLevel", this.player.getDataWatcher().getWatchableObjectInt(levelID));
compound.setTag(EXT_PROP_NAME, properties);
}
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel"));
System.out.println("[NBT] Level from NBT: " + this.level);
}
I changed the code as you said, but it did not help.
// I'm guessing this doesn't print what you expect
System.out.println("[NBT] Level from NBT: " + this.level);
// but this should, provided that your getLevel() method returns the value from DataWatcher
System.out.println("[NBT] Level from NBT: " + getLevell());
You are using DataWatcher, so why do you have a field 'level'? Get rid of that and ONLY use getLevel() and setLevel() methods. The value is stored in DataWatcher, not in the 'level' field.
Well, that was stupid, I just forgot to change it from the old code.
Thank you very much, I certainly would have spent several more hours before noticing this ^^
I think every coder in the world has had plenty of experiences just like yours - I know I certainly have xD
Hello again! I found the spelling in the code!
For example, consider saving variables through DataWatcher.
If after we have died and we came GUI (GuiGameOver) close Minecraft! IMPORTANT! DO NOT press "RESPAWN"! If you re-enter the game, the variables will be reset.
I'm sorry to ask this, but I need some help with am having, I'am on 1.7.2, I'am following your IExtendedEntityProperties tutorial, in the way that I'am adding a form of mana, but before the player can use it the player has to do something first. So when the player joins for the first time he has 0 for maxMana, but throught the initiation the maxMana goes up to 50, but when this happens the gui does not show up. It is probably because Im not saving the changes correctly, i got it to work on 1.6.4, because i use the sync() method, but I don't get the new one, please help!
Hello again! I found the spelling in the code! For example, consider saving variables through DataWatcher. If after we have died and we came GUI (GuiGameOver) close Minecraft! IMPORTANT! DO NOT press "RESPAWN"! If you re-enter the game, the variables will be reset.
I'm sorry, I don't understand what you need help with. Please see the section on keeping properties persistent through death if that's what you need.
I'm sorry to ask this, but I need some help with am having, I'am on 1.7.2, I'am following your IExtendedEntityProperties tutorial, in the way that I'am adding a form of mana, but before the player can use it the player has to do something first. So when the player joins for the first time he has 0 for maxMana, but throught the initiation the maxMana goes up to 50, but when this happens the gui does not show up. It is probably because Im not saving the changes correctly, i got it to work on 1.6.4, because i use the sync() method, but I don't get the new one, please help!
You need to use the new packet system. The page I linked shows you everything you need to get started, literally just copy and paste those 2 classes into your network package, follow the instructions for setting up the PacketPipeline, then create a class extending AbstractPacket for syncing your max mana and send it when your max mana changes.
Or use DataWatcher for your max mana as well, if that's going to be changing a lot.
No, I did update to 1.7.2, using ur tools, but I can't open the GUI when the maxMana changes, but I might change maxMana to a data watcher, but I'm not sure if it a good change
No, I did update to 1.7.2, using ur tools, but I can't open the GUI when the maxMana changes, but I might change maxMana to a data watcher, but I'm not sure if it a good change
Which GUI? The mana bar overlay? How are you telling it to render or not? If you use something like:
if (YourProperties.get(mc.thePlayer).getMaxMana() == 0) {
return;
}
to prevent it from showing when the player has no mana, and as soon as the client sided properties' max mana is above 0, the mana bar should show up. If it's not, then you are not synchronizing the data correctly.
That what I thought problem was, because the way I synchronized data with ur 1.6.4 version I just called the sync method, but now I'm not sure.
Well did you fix your sync method to use the new packet system? Is your packet registered in the PacketPipeline class? Put some debugging println's around in your packet class as well as when you set the max mana to see what's going on. Be sure to print which side you are on as well ("is client? " + world.isRemote). That should give you an idea of what is failing.
This works because the packets now do all of the work for you as far as creating the packet, so you don't need extraneous methods for building packets using BosArrays and all that crap. You do, however, still need to sync your data somehow if you want it available on the client side.
Using that method how would I call it? Do I just call that line?
Please read the section on updating your network again, and check the one in my inventory tutorial as well because that one goes into more detail. Also make sure you have read and understood the wiki guide on setting up the Packet Pipeline that I have linked in both tutorials. You have to set up your network before you can send packets.
I changed the code as you said, but it did not help.
@Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("newLevel", this.player.getDataWatcher().getWatchableObjectInt(levelID)); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel")); System.out.println("[NBT] Level from NBT: " + this.level); }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou are using DataWatcher, so why do you have a field 'level'? Get rid of that and ONLY use getLevel() and setLevel() methods. The value is stored in DataWatcher, not in the 'level' field.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou're welcome
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou can only use the "public" modifier when subscribing to an event, otherwise how is the event supposed to call your method?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI think every coder in the world has had plenty of experiences just like yours - I know I certainly have xD
For example, consider saving variables through DataWatcher.
If after we have died and we came GUI (GuiGameOver) close Minecraft! IMPORTANT! DO NOT press "RESPAWN"! If you re-enter the game, the variables will be reset.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI'm sorry, I don't understand what you need help with. Please see the section on keeping properties persistent through death if that's what you need.
You need to use the new packet system. The page I linked shows you everything you need to get started, literally just copy and paste those 2 classes into your network package, follow the instructions for setting up the PacketPipeline, then create a class extending AbstractPacket for syncing your max mana and send it when your max mana changes.
Or use DataWatcher for your max mana as well, if that's going to be changing a lot.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWhich GUI? The mana bar overlay? How are you telling it to render or not? If you use something like:
if (YourProperties.get(mc.thePlayer).getMaxMana() == 0) { return; }to prevent it from showing when the player has no mana, and as soon as the client sided properties' max mana is above 0, the mana bar should show up. If it's not, then you are not synchronizing the data correctly.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWell did you fix your sync method to use the new packet system? Is your packet registered in the PacketPipeline class? Put some debugging println's around in your packet class as well as when you set the max mana to see what's going on. Be sure to print which side you are on as well ("is client? " + world.isRemote). That should give you an idea of what is failing.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThe method you choose to sync your data is up to you; I just replaced the sync method with a packet:
This works because the packets now do all of the work for you as far as creating the packet, so you don't need extraneous methods for building packets using BosArrays and all that crap. You do, however, still need to sync your data somehow if you want it available on the client side.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-
View User Profile
-
View Posts
-
Send Message
Curse PremiumPlease read the section on updating your network again, and check the one in my inventory tutorial as well because that one goes into more detail. Also make sure you have read and understood the wiki guide on setting up the Packet Pipeline that I have linked in both tutorials. You have to set up your network before you can send packets.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou are both welcome. Thanks for stopping by and leaving me a nice message