From b2d722a4c596289670a0a3dbe458b9ade759009e Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 4 Dec 2014 00:12:07 -0800 Subject: [PATCH] Make Apiarist's Armor protect against potion effects from bees --- .../genetics/AlleleEffectPotion.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java index 568d8b91c..e32e30f0f 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java @@ -10,25 +10,25 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import forestry.apiculture.items.ItemArmorApiarist; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.genetics.IEffectData; +import java.util.List; public class AlleleEffectPotion extends AlleleEffectThrottled { - private int potionId = 0; + private final Potion potion; private final int duration; public AlleleEffectPotion(String uid, String name, boolean isDominant, Potion potion, int duration, boolean requiresWorking) { super(uid, name, isDominant, 200, requiresWorking, false); - potionId = potion.getId(); + this.potion = potion; this.duration = duration; } @@ -39,12 +39,29 @@ public class AlleleEffectPotion extends AlleleEffectThrottled { return storedData; AxisAlignedBB beatifyBox = getBounding(genome, housing, 1.0f); - @SuppressWarnings("rawtypes") List list = housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, beatifyBox); - for (Object obj : list) { - EntityPlayer player = (EntityPlayer) obj; - player.addPotionEffect(new PotionEffect(potionId, duration, 0)); + for (Object entity : list) { + if (!(entity instanceof EntityPlayer)) + continue; + + EntityPlayer player = (EntityPlayer) entity; + + int duration = this.duration; + if (potion.isBadEffect()) { + // Players are not attacked if they wear a full set of apiarist's armor. + int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true); + if (count >= 4) + continue; // Full set, no damage/effect + else if (count == 3) + duration = this.duration / 4; + else if (count == 2) + duration = this.duration / 2; + else if (count == 1) + duration = this.duration * 3 / 4; + } + + player.addPotionEffect(new PotionEffect(potion.getId(), duration, 0)); } return storedData;