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:

Spoiler

package com.fantasticsource.dynamicstealth.common.potions;

import com.fantasticsource.dynamicstealth.common.DynamicStealth;
import com.fantasticsource.dynamicstealth.server.senses.EntityVisionData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class PotionSoulSight extends Potion
{
    private final ResourceLocation iconTexture;

    public PotionSoulSight()
    {
        super(false, 0xFFFF55);
        setPotionName(DynamicStealth.MODID + ".soulSight");
        setRegistryName(DynamicStealth.MODID, "soulSight");
        iconTexture = new ResourceLocation(DynamicStealth.MODID, "potions/soulsight.png");
    }

    @Override
    public boolean isInstant()
    {
        return false;
    }

    @Override
    public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
    {
        //Should be called "onPotionStart"
        EntityVisionData.potionSoulSightEntities.add(entityLivingBaseIn);
    }

    @Override
    public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
    {
        //Should be called "onPotionEnd"
        EntityVisionData.potionSoulSightEntities.remove(entityLivingBaseIn);
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc)
    {
        if (mc.currentScreen != null)
        {
            mc.getTextureManager().bindTexture(iconTexture);
            Gui.drawModalRectWithCustomSizedTexture(x + 6, y + 7, 0, 0, 18, 18, 18, 18);
        }
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha)
    {
        mc.getTextureManager().bindTexture(iconTexture);
        Gui.drawModalRectWithCustomSizedTexture(x + 3, y + 3, 0, 0, 18, 18, 18, 18);
    }
}

 

 

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

Spoiler

package com.fantasticsource.dynamicstealth.common.potions;

import com.fantasticsource.dynamicstealth.common.DynamicStealth;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class Potions
{
    @SubscribeEvent
    public static void registerPotions(RegistryEvent.Register<Potion> event)
    {
        event.getRegistry().register(new PotionSoulSight());
    }

    @SubscribeEvent
    public static void registerPotionTypes(RegistryEvent.Register<PotionType> event)
    {
        event.getRegistry().register(new PotionType(DynamicStealth.MODID + ".soulSight", new PotionEffect(new PotionSoulSight(), 200)).setRegistryName(DynamicStealth.MODID, "soulSight"));
    }
}

 

 

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

Spoiler

    @SubscribeEvent
    public static void test(TickEvent.PlayerTickEvent event)
    {
        if (MCTools.isClient(event.player.world))
        {
            for (PotionEffect effect : event.player.getActivePotionEffects())
            {
                System.out.println("Client: " + effect.getEffectName());
            }
        }
        else
        {
            for (PotionEffect effect : event.player.getActivePotionEffects())
            {
                System.out.println("Server: " + effect.getEffectName());
            }
        }
    }

 

 

Edited by Laike_Endaril
Solved
Posted
8 hours ago, Laike_Endaril said:

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

 

8 hours ago, Laike_Endaril said:

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

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.

 

8 hours ago, Laike_Endaril said:

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

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
19 hours ago, 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.

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.

 

19 hours ago, V0idWa1k3r said:

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

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):
 

Spoiler

package com.fantasticsource.dynamicstealth.common.potions;

import com.fantasticsource.dynamicstealth.common.DynamicStealth;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class Potions
{
    public static final Potion POTION_SOULSIGHT = new PotionSoulSight();
    public static final PotionType POTIONTYPE_SOULSIGHT_NORMAL = new PotionType(DynamicStealth.MODID + ".soulSight", new PotionEffect(POTION_SOULSIGHT, 200)).setRegistryName(DynamicStealth.MODID, "soulSight");

    @SubscribeEvent
    public static void registerPotions(RegistryEvent.Register<Potion> event)
    {
        event.getRegistry().register(POTION_SOULSIGHT);
    }

    @SubscribeEvent
    public static void registerPotionTypes(RegistryEvent.Register<PotionType> event)
    {
        event.getRegistry().register(POTIONTYPE_SOULSIGHT_NORMAL);
    }
}

 

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Which mod was this? What are all the mods that were in use? It will help if enough information to replicate the problem is available.
    • I have been attempting to create a supplementary resource pack with Patchouli in order to add back the guidebook for Better End but unfortunately in every prototype I have made pack.mcmeta and my resource pack are not recognized. I have tested both zipped and unzipped and either way curseforge does not recognize my resource pack as existing. For testing I stripped my pack down to just the pack.mcmeta file and two empty folders labelled data and assets and I know the data folder is not the problem as firstly my first attempts just had an assets folder following Patchouli instructions and data came later in my flailing attempts to make anything in my pack work. The mcmeta file is not recognized whether or not I use this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } "language": { "en_US": { "name": "English", "region": "United States" } } } ,or this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } } I have made sure to only use lowercase and the pack folder is named better-end-guide. Is this some magic nonsense from me doing this manually instead of using an IDE or similar tool? Could it be because my files are by default in UTF-8 even though ANSI gives the same results? Is there a specific community secret tool I am supposed to use for zipping or specific settings? I am pulling my hair in distress. Unfortunately as there are no errors involved I lack logs to offer, if that disqualifies this thread please do not be harsh and instead if you can then please direct me to a forum with different rules and sufficiently respectful but knowledgeable as to be of assistance. Most of my experience with the programming community has been poor and so naturally I find myself wary.
    • I never picked up a tier 0 dragon skull to my knowledge. One of my other skulls must have bugged out and randomly became one. I was confused on what the heck it was and tried placing it, now the game will only crash because it can't render in whatever the heck the tier 0 skull is. This is on a server and it crashes anyone within render distance.
    • After setting up forge, making sure my drivers are updated, and downloading the create mod i tried to run forge and it said it crashed while trying to render the overlay, i heard about deleting a file called forge-client.toml, but when i looked at the config files(and all the files on my computer) it was nowhere to be found. https://pastebin.com/raw/TTyWWyeS
    • Post logs as described in the FAQ, there might be a clue in there what is going on.
  • Topics

×
×
  • Create New...

Important Information

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