Jump to content

Recommended Posts

Posted (edited)

I've been delving into the potion-related code in MC and it *seems* like custom potion effects on the player should automatically sync to the client, but for some reason my potion effect only exists server-side.  The potion itself works, and the particle effect is spawned, but I must be missing something to allow the existing synchronization system to sync my potion effect, because iterating through + printing the potion effects shows the effect server-side, but not client-side.

 

Potion:

  Reveal hidden contents

 

Registration (added to event bus in main mod class constructor):

  Reveal hidden contents

 

Test (For vanilla potions, both debug messages print.  For my own potion, only the server message prints):

  Reveal hidden contents

 

Edited by Laike_Endaril
Solved
Posted
  On 1/27/2019 at 9:01 PM, Laike_Endaril said:

event.getRegistry().register(new PotionSoulSight());

Expand  

 

  On 1/27/2019 at 9:01 PM, Laike_Endaril said:

event.getRegistry().register(new PotionType(DynamicStealth.MODID + ".soulSight", new PotionEffect(new PotionSoulSight(), 200)).setRegistryName(DynamicStealth.MODID, "soulSight"));

Expand  

You can't just instantinate your potion twice and call it good. The potion type needs a reference to an existing potion. To get a reference you can use @ObjectHolder. I don't know how you are applying your potion but if it is through a bottle then this is your issue.

 

  On 1/27/2019 at 9:01 PM, Laike_Endaril said:

if (MCTools.isClient(event.player.world))

Expand  

Why do you need this helper? World.isRemote is enough and shorter. The reason I am wary of this is you might have implemented it incorrectly and are mixing the client and the server which would be the cause of your problem(although I don't know how you are adding the potion itself).

 

Fix these two, they are big culprits and if that didn't help proceed with the debugging:

Place a breakpoint in EntityPlayerMP#onNewPotionEffect to see if it is triggered for your potion and one in NetHandlerPlayClient#handleEntityEffect to see if the client is receiving the packet for your potion effect.

Posted
  On 1/28/2019 at 5:56 AM, V0idWa1k3r said:

You can't just instantiate your potion twice and call it good. The potion type needs a reference to an existing potion. To get a reference you can use @ObjectHolder. I don't know how you are applying your potion but if it is through a bottle then this is your issue.

Expand  

Ah, thank you.  This is most likely my issue.  At the time, for whatever reason, I was thinking it would do an equivalency check using the `ResourceLocation`s, which was a bad line of thinking on my part since a `PotionType` can contain multiple `Potion`s.

 

  On 1/28/2019 at 5:56 AM, V0idWa1k3r said:

Why do you need this helper? World.isRemote is enough and shorter.

Expand  

The internals of that method simply return world.isRemote.  The only reason I made that method is because I kept mixing up whether "isRemote" is true on client or server, and got tired of going back to look at it every time (though I realize my extra method call makes it a bit less efficient; I don't think the compiler is optimizing it out).

 

I'll try fixing my registries and post the results.

Posted (edited)

Yes, that was the issue.  The potion is synchronizing to the client now, and all I did was make sure the same Potion instance was used in both registration events.

 

My new, working Potions class (which handles the registrations):
 

  Reveal hidden contents

 

I have a couple minor changes to make on it still (such as changing it from a debuff to a buff, so milk doesn't remove it), but it works, and both of my icons are displaying.

 

Edit: Forgot that milk removes buffs as well.  W/e.

Edited by Laike_Endaril

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.