Jump to content

[1.13.2] Potion Effect + Tag mechanic


Simon_kungen

Recommended Posts

Hi

 

I want a "Radiation" mechanic to the game whenever you are exposed to either radioactive materials such as Uranium 235 or close proximity to a radioactive block. I made a Potion Effect called "Radiation Sickness" which changes the player's max health but also prevents natural health regeneration from food.

I got the initial effect working and can change the player's max health, but preventing natural regeneration has proved trickier:

PotionRadiationSickness.java

Spoiler

public class PotionRadiationSickness extends Potion {

    private static float oldMaxHealth;
    private static boolean maxHealthCheck = false;

    public static final float healthAmplifier = 4;

    public PotionRadiationSickness(boolean isBadEffectIn, int liquidColorIn) {
        super(isBadEffectIn, liquidColorIn);


        setRegistryName("radiation_sickness");

    }
    public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier) {
        if (entityLivingBaseIn instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer)entityLivingBaseIn;

            if (!maxHealthCheck) {
                oldMaxHealth = player.getMaxHealth();
                maxHealthCheck = true;
            }
            IAttributeInstance health = player.getAttribute(SharedMonsterAttributes.MAX_HEALTH);

            float maxHealth = oldMaxHealth-(amplifier*healthAmplifier+healthAmplifier);

            player.setHealth(maxHealth);
            health.setBaseValue(maxHealth);
        }
    }
    public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier) {
        if (entityLivingBaseIn instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer)entityLivingBaseIn;
            IAttributeInstance health = player.getAttribute(SharedMonsterAttributes.MAX_HEALTH);

            health.setBaseValue(oldMaxHealth);
        }

    }
}

 

 

 

I do not understand how "setIconIndex()" works either. Setting the different values in the function changes it to vanilla potion effect icons but I have no idea how to add my resource icon to the index. And because this is a negative effect and can potentially kill you it would be good if I can set a custom death message sent to the server.

 

 

 

Obviously, this effect is not called "Radiation" but "Radiation Sickness" which going on real life happens when someone is exposed to a high dose of radiation during a short time. You either will feel really bad for a while or, well, you die. My idea was to add a tag called "radiation_exposure" to the player which starts and 0 and if exposed to something radioactive will increase the value. Over time it will slowly vanish, but if it goes beyond a certain threshold will apply Radiation Sickness to the player which will increase in amplifier depending on how long the radiation_exposure value is over the threshold. With this logic, a large number to the value will kill the player if continued exposure or being exposed to a highly radioactive object.

 

 

I don't know if this is the right approach, but here is a beginning of a class:

Radiation.java

Spoiler

public abstract class Radiation extends EntityPlayer {


    public Radiation(World worldIn, GameProfile playerProfile) {
        super(worldIn,playerProfile);

        getEntityData().setLong(Reference.MODID+"_radiation_exposure",0);
    }


    public void tick() {
        long exposure = getEntityData().getLong(Reference.MODID+"_radiation_exposure");
        if (exposure > 0) {
            getEntityData().setLong(Reference.MODID + "_radiation_exposure", exposure - 1);
            System.out.println(exposure);
        }
    }




    public void expose(int intensity) {
        long exposure = getEntityData().getLong(Reference.MODID+"_radiation_exposure");

        getEntityData().setLong(Reference.MODID+"_radiation_exposure",exposure+intensity);



    }
}

 

 

 

Edited by Simon_kungen
Editor bug.
Link to comment
Share on other sites

8 hours ago, Simon_kungen said:

preventing natural regeneration has proved trickier:

Disabling natural regeneration for one player is very tricky, because you don't want to cancel every other regeneration source.

What you can do is subscribe to the player tick event, check whether the player is affected by your effect or not, if they are then disable the "naturalRegeneration" gamerule in the Start phase and re-enable it in the End phase(if it was enabled in the first place).

Your way won't work any way since this method is called when the effect is applied.

 

8 hours ago, Simon_kungen said:

I do not understand how "setIconIndex()" works either.

Well, it sets the index of the icon on the spritesheet for the potion effects. For example, if we have a 4x4 spritesheet with a 1x1 sprite resolution then index 0 is sprite at 0,0, index 1 is 1,0, index 4 is 0,1, etc.

 

8 hours ago, Simon_kungen said:

I have no idea how to add my resource icon to the index.

This sentence doesn't make any sense. You can't add anything to the index. 

Make your own texture for your potion effects and use it for rendering by overriding Potion#renderInventoryEffect and Potion#renderHUDEffect.

 

8 hours ago, Simon_kungen said:

would be good if I can set a custom death message sent to the server.

Use a custom DamageSource implementation/instance.

 

8 hours ago, Simon_kungen said:

add a tag called "radiation_exposure" to the player

Use capabilities.https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

For the sake of everything holy don't ever think about doing what you are showing in your "beginning of a ckass" ever.

Link to comment
Share on other sites

22 hours ago, V0idWa1k3r said:

Disabling natural regeneration for one player is very tricky, because you don't want to cancel every other regeneration source.

What you can do is subscribe to the player tick event, check whether the player is affected by your effect or not, if they are then disable the "naturalRegeneration" gamerule in the Start phase and re-enable it in the End phase(if it was enabled in the first place).

Your way won't work any way since this method is called when the effect is applied.

 

Well, it sets the index of the icon on the spritesheet for the potion effects. For example, if we have a 4x4 spritesheet with a 1x1 sprite resolution then index 0 is sprite at 0,0, index 1 is 1,0, index 4 is 0,1, etc.

 

This sentence doesn't make any sense. You can't add anything to the index. 

Make your own texture for your potion effects and use it for rendering by overriding Potion#renderInventoryEffect and Potion#renderHUDEffect.

 

Use a custom DamageSource implementation/instance.

 

Use capabilities.https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

For the sake of everything holy don't ever think about doing what you are showing in your "beginning of a ckass" ever.

 

Alright, capabilities seem like they are the way to go, but I don't have the faintest idea of how to go about it.

Radiation.java

Spoiler

package net.intercraft.intercraftcore.init.capabilities;

public class Radiation implements IRadiation {

    private long exposure = 0;

    private final long[] levels = {
            5000,
            10000,
            20000,
            40000
    };


    @Override
    public long getExposure() {
        return this.exposure;
    }

    @Override
    public long getLevel(int index) {
        return this.levels[index];
    }

    @Override
    public void tick() {
        if (this.exposure >= 0) {
            this.exposure--;
            System.out.println(this.exposure);
        }
    }

    @Override
    public void increase(int value) {
        if (value > 0)
            this.exposure += value;
    }

}

 

 

 

The docs don't make it particularly clear how to do it. The code now obviously don't really do anything except for holding a value, but how do I have it applied to the player for example and what does the register part come into all of it? I did watch a video about it from 2017 for version 1.10/ and 11 but I didn't really do anything except for copy-pasting his code and can only assume I did something wrong when it didn't compile. And it doesn't help that Mojang re-structured everything after 1.13.

 

I'm not asking you to do it for me, but explain what it really does. I know capabilities are what most energy systems are such as RedstoneFlux (RF) and TESLA.

Link to comment
Share on other sites

A working example helps.

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/farming/entities/capabilities

There's also some bits in my EventHandler class that are relevant.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

On 5/27/2019 at 1:12 AM, Draco18s said:

A working example helps.

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/farming/entities/capabilities

There's also some bits in my EventHandler class that are relevant.

Alright, I got it registered without errors. I do still have some question though:

If I for example want to apply this to every player, how would I do that? I want one function to happen every tick for each player and then if they have a radioactive item in their inventory should increase it.

Uranium.java

Spoiler

public class Uranium extends ItemElement
{
    /*
     *
     * */
    public Uranium()
    {
        super("u", "uranium", 0x92d67d);
    }

    @Override
    public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
        /*
        * Exposure should go up when in inventory, even faster when selected.
        */
    }
}

 

 

Interfaces:

Spoiler

IRadiation.java


public interface IRadiation {
    long getExposure();

    void tick();

    void setExposure(long value);
}

IRadiationEmitter.java


public interface IRadiationEmitter {

    void emission(long exposure, float distance);
}

 

 
Link to comment
Share on other sites

4 hours ago, Simon_kungen said:

If I for example want to apply this to every player, how would I do that?

EntityJoinWorldEvent and check if the entity is a player.

 

Then you would need a PlayerTickEvent handler that would:

  • Get the capability from the event's player object
  • Call the function, passing the capability so that...
  • ...the function can modify the radioactivity level of the player

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.