Skip to content

Commit

Permalink
adding weapon whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
frodare committed Sep 23, 2018
1 parent 939b6a3 commit 7fa835d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/net/torocraft/torohud/gui/HealthBars.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -37,8 +38,8 @@
import net.torocraft.torohud.gui.HealthBars.Conf.Mode;
import net.torocraft.torohud.gui.HealthBars.Conf.NumberType;
import net.torocraft.torohud.util.EntityUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL11;
import scala.collection.parallel.ParIterableLike.Min;


@Mod.EventBusSubscriber(Side.CLIENT)
Expand Down Expand Up @@ -83,6 +84,10 @@ public enum NumberType {NONE, LAST, CUMULATIVE}
@Name("Damage Number Type")
public static NumberType numberType = NumberType.LAST;

@Name("Additional Weapons")
@Comment("When using WHEN_HOLDING_WEAPON to show entity bars, more items can be added here to be treated as weapons.")
public static String[] additionalWeaponItems = {};

}

@SubscribeEvent
Expand Down Expand Up @@ -151,9 +156,16 @@ public static void updateEquipment() {
}

private static boolean isWeapon(ItemStack item) {
return item.getItem() instanceof ItemSword || item.getItem() instanceof ItemBow || item.getItem() instanceof ItemPotion;
return item.getItem() instanceof ItemSword ||
item.getItem() instanceof ItemBow ||
item.getItem() instanceof ItemPotion ||
isInWeaponWhiteList(item);
}

private static boolean isInWeaponWhiteList(ItemStack item) {
String itemName = item.getItem().getUnlocalizedName();
return ArrayUtils.contains(Conf.additionalWeaponItems, itemName);
}

private static boolean stateExpired(World world, int id, State state) {
if (state == null) {
Expand Down

0 comments on commit 7fa835d

Please sign in to comment.