Extracted Apiarist Armor checking methods to API so addons can use them

This commit is contained in:
Vexatos authored and mezz committed 2015-09-20 15:33:01 -07:00
1 parent 901318c2b0
commit 614305c690
10 files changed
+64 -33

No files matched your search

@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IArmorApiarist;
import forestry.api.apiculture.IArmorApiaristHelper;
public class ArmorApiaristHelper implements IArmorApiaristHelper {
@Override
public boolean isArmorApiarist(ItemStack stack, EntityPlayer player, String cause, boolean doProtect) {
if(stack == null) {
return false;
}
Item item = stack.getItem();
if (!(item instanceof IArmorApiarist)) {
return false;
}
IArmorApiarist armorApiarist = (IArmorApiarist) item;
return armorApiarist.protectPlayer(player, stack, cause, doProtect);
}
@Override
public int wearsItems(EntityPlayer player, String cause, boolean doProtect) {
int count = 0;
for (ItemStack armorItem : player.inventory.armorInventory) {
if (isArmorApiarist(armorItem, player, cause, doProtect)) {
count++;
}
}
return count;
}
}
@@ -12,6 +12,7 @@ package forestry.apiculture.genetics;
import java.util.List;
import forestry.api.apiculture.BeeManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
@@ -45,7 +46,7 @@ public class AlleleEffectAggressive extends AlleleEffectThrottled {
// Players are not attacked if they wear a full set of apiarist's
// armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3) {
continue;
@@ -12,6 +12,7 @@ package forestry.apiculture.genetics;
import java.util.List;
import forestry.api.apiculture.BeeManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
@@ -73,7 +74,7 @@ public class AlleleEffectCreeper extends AlleleEffectThrottled {
// Players are not attacked if they wear a full set of apiarist's
// armor.
int count = ItemArmorApiarist.wearsItems(player, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems(player, getUID(), true);
// Full set, no damage/effect
if (count > 3) {
continue;
@@ -12,6 +12,7 @@ package forestry.apiculture.genetics;
import java.util.List;
import forestry.api.apiculture.BeeManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
@@ -49,7 +50,7 @@ public class AlleleEffectIgnition extends AlleleEffectThrottled {
// Players are not attacked if they wear a full set of apiarist's armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3) {
continue;
@@ -12,6 +12,7 @@ package forestry.apiculture.genetics;
import java.util.List;
import forestry.api.apiculture.BeeManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
@@ -44,7 +45,7 @@ public class AlleleEffectMisanthrope extends AlleleEffectThrottled {
// Players are not attacked if they wear a full set of apiarist's
// armor.
int count = ItemArmorApiarist.wearsItems(player, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems(player, getUID(), true);
// Full set, no damage/effect
if (count > 3) {
continue;
@@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import forestry.api.apiculture.BeeManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
@@ -74,7 +75,7 @@ public class AlleleEffectPotion extends AlleleEffectThrottled {
int dur = this.duration;
if (isBadEffect) {
// Players are not attacked if they wear a full set of apiarist's armor.
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems((EntityPlayer) entity, getUID(), true);
if (count >= 4) {
continue; // Full set, no damage/effect
} else if (count == 3) {
@@ -13,6 +13,7 @@ package forestry.apiculture.genetics;
import java.util.List;
import java.util.Random;
import forestry.api.apiculture.BeeManager;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -64,7 +65,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
// Players are not attacked if they wear a full set of apiarist's
// armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
int count = BeeManager.armorApiaristHelper.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3) {
continue;
@@ -13,7 +13,6 @@ package forestry.apiculture.items;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
@@ -83,29 +82,4 @@ public class ItemArmorApiarist extends ItemArmor implements IArmorApiarist, IArm
return armorType == 0;
}
private static boolean isArmorApiarist(ItemStack itemStack, EntityPlayer player, String cause, boolean protect) {
if (itemStack == null) {
return false;
}
Item item = itemStack.getItem();
if (!(item instanceof IArmorApiarist)) {
return false;
}
return ((IArmorApiarist) item).protectPlayer(player, itemStack, cause, protect);
}
public static int wearsItems(EntityPlayer player, String cause, boolean protect) {
int count = 0;
for (ItemStack armorItem : player.inventory.armorInventory) {
if (isArmorApiarist(armorItem, player, cause, protect)) {
count++;
}
}
return count;
}
}
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import forestry.apiculture.ArmorApiaristHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
@@ -190,6 +191,7 @@ public class PluginApiculture extends ForestryPlugin {
BeeManager.beeFactory = new BeeFactory();
BeeManager.beeMutationFactory = new BeeMutationFactory();
BeeManager.jubilanceFactory = new JubilanceFactory();
BeeManager.armorApiaristHelper = new ArmorApiaristHelper();
// Init bee interface
BeeManager.beeRoot = new BeeHelper();