Basically, I'm trying to figure out if an entity is an effect with a potion effect from the client side. I have the entity reference, but when I test for potion effects I get the above issue. I poisoned my entity and had a method get a list of the potion effects and even though the entity was clearly poisoned, the effect did not populate on the list. Any ideas?
Rollback Post to RevisionRollBack
My Mods:
Working on updating Little Maid Mod to 1.12 with my own twist. I am a Japanese anime fan :3 Teasers here
Blood Baubles - An addon for BloodMagic that adds related Baubles to the game. (Currently on hold)
Blood Magic Wiki - A Blood Mages Choice Encylopedia (Currently on hold)
LazyModder- A libary that makes modding easier. Currently being developed for 1.12)
Deobfuscator - A program used to deobfuscate obfuscated mods.
You need to look at the updatePotionEffects() method in EntityLivingBase class. You can see there how it checks for potions. Looking at it quickly I think it is using the data manager to check for value of potion effects.
I looked at that code, and it looks like it handles having potion effects on the server side. I bet there is a packet somewhere to check for potion effects, let me look.
Edit:
So I confirmed that potion effect is handled by the server and it saves it to the tag. When the world is reloaded it will loaded the nbt to the client side, but the effects will always be there with a duration of 0 until the tag is reloaded. I wonder if this is what they intended.
Ok, I found a solution. It involves using the data watcher and I think will be helpful for anyone having problems having trouble with entity server-client data sync. First create a DataParameter<NBTTagCompund> using the DataSerializers.COMPOUND_TAG. Then when the server changes your value, change the datawatcher. You can override notifyDataManagerChange if you need further processing, but otherwise it should now sync with client-server.
For me, I created a datawatcher like above. Then, I overrided updatePotionMetadata called the super and checked if the world was remote (if it was i returned because the client didn't have any useful data and effectively making the changes one way). I also overrided removeactivepotion effect and had it call updatePotionMetadata if it was the server. Then, overrided clear active potion effects and had it call on both sides, since by default it only calls on server side. Finally, I overrided notifyDataManagerChange, checked to see if the world was the client (don't need to change the server, again making it one way), cleared all active potion effects and had it create new potion effects from the ones provided.
I haven't tested it on a live server, but it seems like it should work. If it doesn't ill let you know when i do test it.
Rollback Post to RevisionRollBack
My Mods:
Working on updating Little Maid Mod to 1.12 with my own twist. I am a Japanese anime fan :3 Teasers here
Blood Baubles - An addon for BloodMagic that adds related Baubles to the game. (Currently on hold)
Blood Magic Wiki - A Blood Mages Choice Encylopedia (Currently on hold)
LazyModder- A libary that makes modding easier. Currently being developed for 1.12)
Deobfuscator - A program used to deobfuscate obfuscated mods.
You need to look at the updatePotionEffects() method in EntityLivingBase class. You can see there how it checks for potions. Looking at it quickly I think it is using the data manager to check for value of potion effects.
Minecraft does not use datawatches for potion effects by default. It saves potion effects to the nbttag. I think this leaves some remnants in the nbttag that are not properly handled and are left there until next reload of the world or the entity is reloaded.
Rollback Post to RevisionRollBack
My Mods:
Working on updating Little Maid Mod to 1.12 with my own twist. I am a Japanese anime fan :3 Teasers here
Blood Baubles - An addon for BloodMagic that adds related Baubles to the game. (Currently on hold)
Blood Magic Wiki - A Blood Mages Choice Encylopedia (Currently on hold)
LazyModder- A libary that makes modding easier. Currently being developed for 1.12)
Deobfuscator - A program used to deobfuscate obfuscated mods.
Basically, I'm trying to figure out if an entity is an effect with a potion effect from the client side. I have the entity reference, but when I test for potion effects I get the above issue. I poisoned my entity and had a method get a list of the potion effects and even though the entity was clearly poisoned, the effect did not populate on the list. Any ideas?
My Mods:
- Happy Coding -
You need to look at the updatePotionEffects() method in EntityLivingBase class. You can see there how it checks for potions. Looking at it quickly I think it is using the data manager to check for value of potion effects.
I looked at that code, and it looks like it handles having potion effects on the server side. I bet there is a packet somewhere to check for potion effects, let me look.
Edit:
So I confirmed that potion effect is handled by the server and it saves it to the tag. When the world is reloaded it will loaded the nbt to the client side, but the effects will always be there with a duration of 0 until the tag is reloaded. I wonder if this is what they intended.
My Mods:
- Happy Coding -
Ok, I found a solution. It involves using the data watcher and I think will be helpful for anyone having problems having trouble with entity server-client data sync. First create a DataParameter<NBTTagCompund> using the DataSerializers.COMPOUND_TAG. Then when the server changes your value, change the datawatcher. You can override notifyDataManagerChange if you need further processing, but otherwise it should now sync with client-server.
For me, I created a datawatcher like above. Then, I overrided updatePotionMetadata called the super and checked if the world was remote (if it was i returned because the client didn't have any useful data and effectively making the changes one way). I also overrided removeactivepotion effect and had it call updatePotionMetadata if it was the server. Then, overrided clear active potion effects and had it call on both sides, since by default it only calls on server side. Finally, I overrided notifyDataManagerChange, checked to see if the world was the client (don't need to change the server, again making it one way), cleared all active potion effects and had it create new potion effects from the ones provided.
I haven't tested it on a live server, but it seems like it should work. If it doesn't ill let you know when i do test it.
My Mods:
- Happy Coding -
Minecraft does not use datawatches for potion effects by default. It saves potion effects to the nbttag. I think this leaves some remnants in the nbttag that are not properly handled and are left there until next reload of the world or the entity is reloaded.
My Mods:
- Happy Coding -