Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

My code:

    /**
     * defines what the plague effect does and clears the modifiers after the effect has ended
     * @param event : world events
     */
    @SubscribeEvent
    public static void plaguePotionActive(PlayerTickEvent event)
    {
        boolean isActive = false;
        if (event.player.isPotionActive(MystPotions.PLAGUE_EFFECT))
        {
            isActive = true;
        }
        
        if (isActive == true)
        {
            if(MystPotions.alreadyActive == false)
            {
                String UUID = MathHelper.getRandomUUID().toString();
                
                MystPotions.PLAGUE_EFFECT.registerPotionAttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED, UUID, -0.15000000596046448D * 0.5, 2);
                MystPotions.PLAGUE_EFFECT.registerPotionAttributeModifier(SharedMonsterAttributes.ATTACK_SPEED, UUID,  -0.10000000149011612D * 0.5, 2);
                MystPotions.alreadyActive = true;
            }
            
            if  (event.player.getHealth() > event.player.getMaxHealth() * 0.5 && event.player.world.getDifficulty() != EnumDifficulty.EASY)
            {
                event.player.attackEntityFrom(DamageSource.MAGIC, 1.0F);
            }
        }
        else
        {    
            //Map<IAttribute, AttributeModifier> tmp = MystPotions.PLAGUE_EFFECT.getAttributeModifierMap();
            //Multimap<String, AttributeModifier> modifiers =  (Multimap) tmp;
            //event.player.getAttributeMap().removeAttributeModifiers(modifiers);
            //MystPotions.PLAGUE_EFFECT.removeAttributesModifiersFromEntity(event.player, (AbstractAttributeMap) tmp, 2);
            MystPotions.alreadyActive = false;
        }
    }

 

Using the code that is in comments above causes the game to crash as i can't cast a Map to an AbstractAttributeMap.

What methods can i use to only remove the modifiers of this potion?

  • Author
16 hours ago, diesieben07 said:

The Potion class already has mechanisms that do already this, you do not need an event handler. Why have those not worked for you?

I'm going of off tutorials on youtube to find my way around the minecraft classes and this is one of the ways shown in the vid.

I just changed it and put it directly into the potion init class and everything works fine now. However i still need access to the player's hp for this code:

16 hours ago, nil said:

           if  (event.player.getHealth() > event.player.getMaxHealth() * 0.5 && event.player.world.getDifficulty() != EnumDifficulty.EASY)
            {
                event.player.attackEntityFrom(DamageSource.MAGIC, 1.0F);
            }

How do i get the player/entity affected by this effect?

  • Author

I tried using this in my CustomPotions class however this doesn't work:

    @Override
    public void performEffect(EntityLivingBase entityLivingBaseIn, int amplifier)
    {
        if (entityLivingBaseIn.isPotionActive(MystPotions.PLAGUE_EFFECT))
        {
            if(!entityLivingBaseIn.isEntityUndead())
            {
                if (entityLivingBaseIn.getHealth() > entityLivingBaseIn.getMaxHealth() * 0.5 && entityLivingBaseIn.world.getDifficulty() != EnumDifficulty.EASY)
                {
                    entityLivingBaseIn.attackEntityFrom(DamageSource.MAGIC, 1.0F);
                }
            }
            else
            {
                if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth())
                {
                    entityLivingBaseIn.heal(1.0F);
                }
            }
        }
    }

NOTE: i am not using a different class per potion so isPotionActive or sth similar has to be checked

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.