Posted October 16, 20196 yr 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?
October 17, 20196 yr 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?
October 17, 20196 yr 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.