From 750a4070af4756e3708e2b2555b9874864bf3cfb Mon Sep 17 00:00:00 2001 From: David Lindström Date: Fri, 20 Jan 2023 09:27:42 +0100 Subject: Add Hazmat enchant to add Full Hazmat protection to an arbitrary armor item (#1663) --- src/main/java/gregtech/api/util/GT_Utility.java | 67 ++++++++++++++++++++----- 1 file changed, 55 insertions(+), 12 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 38e3ef0d8b..cfa261c321 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -24,6 +24,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; +import gregtech.api.enchants.Enchantment_Hazmat; import gregtech.api.enchants.Enchantment_Radioactivity; import gregtech.api.enums.*; import gregtech.api.events.BlockScanningEvent; @@ -2654,41 +2655,83 @@ public class GT_Utility { } public static boolean isWearingFullFrostHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sFrostHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sFrostHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } return true; } public static boolean isWearingFullHeatHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sHeatHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sHeatHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } + return true; } public static boolean isWearingFullBioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sBioHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sBioHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } return true; } public static boolean isWearingFullRadioHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sRadioHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sRadioHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } return true; } public static boolean isWearingFullElectroHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sElectroHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sElectroHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } return true; } public static boolean isWearingFullGasHazmat(EntityLivingBase aEntity) { - for (byte i = 1; i < 5; i++) - if (!isStackInList(aEntity.getEquipmentInSlot(i), GregTech_API.sGasHazmatList)) return false; + for (byte i = 1; i < 5; i++) { + ItemStack tStack = aEntity.getEquipmentInSlot(i); + + if (!isStackInList(tStack, GregTech_API.sGasHazmatList) && !hasHazmatEnchant(tStack)) { + return false; + } + } return true; } + public static boolean hasHazmatEnchant(ItemStack aStack) { + if (aStack == null) return false; + Map tEnchantments = EnchantmentHelper.getEnchantments(aStack); + Integer tLevel = tEnchantments.get(Enchantment_Hazmat.INSTANCE.effectId); + + if (tLevel != null && tLevel.intValue() >= 1) { + return true; + } + return false; + } + public static float getHeatDamageFromItem(ItemStack aStack) { ItemData tData = GT_OreDictUnificator.getItemData(aStack); return tData == null -- cgit