From e8e899fb8ec40fc2a8094e3a1f65527af23b11e4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 14:47:39 +1000 Subject: + Added some basis for new redstone things. --- .../core/util/minecraft/InventoryUtils.java | 82 +++++++++++----------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java index 0d4394d773..8f12d20494 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java @@ -7,54 +7,52 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class InventoryUtils { private final static Random mRandom = new Random(); - public static void dropInventoryItems(World world, int x, int y, int z, Block block){ - Object tileentity = world.getTileEntity(x, y, z); - - if (tileentity != null) - { - for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) - { - ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1); - - if (itemstack != null) - { - float f = mRandom.nextFloat() * 0.8F + 0.1F; - float f1 = mRandom.nextFloat() * 0.8F + 0.1F; - EntityItem entityitem; - - for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) - { - int j1 = mRandom.nextInt(21) + 10; - - if (j1 > itemstack.stackSize) - { - j1 = itemstack.stackSize; - } - - itemstack.stackSize -= j1; - entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); - float f3 = 0.05F; - entityitem.motionX = (float)mRandom.nextGaussian() * f3; - entityitem.motionY = (float)mRandom.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float)mRandom.nextGaussian() * f3; - - if (itemstack.hasTagCompound()) - { - entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); - } - } - } - } - - world.func_147453_f(x, y, z, block); - } - + public static void dropInventoryItems(World world, int x, int y, int z, Block block) { + TileEntity tileentity = world.getTileEntity(x, y, z); + + if (tileentity != null && tileentity instanceof IInventory + && ((IInventory) tileentity).getSizeInventory() > 0) { + for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) { + ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1); + + if (itemstack != null) { + float f = mRandom.nextFloat() * 0.8F + 0.1F; + float f1 = mRandom.nextFloat() * 0.8F + 0.1F; + EntityItem entityitem; + + for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { + int j1 = mRandom.nextInt(21) + 10; + + if (j1 > itemstack.stackSize) { + j1 = itemstack.stackSize; + } + + itemstack.stackSize -= j1; + entityitem = new EntityItem(world, x + f, y + f1, z + f2, + new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (float) mRandom.nextGaussian() * f3; + entityitem.motionY = (float) mRandom.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) mRandom.nextGaussian() * f3; + + if (itemstack.hasTagCompound()) { + entityitem.getEntityItem() + .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + } + } + } + + world.func_147453_f(x, y, z, block); + } + } } -- cgit From 70a0df8a68725c16f0c0b959639b8e82cbbcf3a0 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 17:44:13 +1000 Subject: % Work work --- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index d32ff4e160..e266ee02d4 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -13,6 +13,7 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.api.objects.minecraft.BlockPos; @@ -1113,5 +1114,65 @@ public class ItemUtils { } return aDisplay; } + + public static boolean isItemGregtechTool(ItemStack aStack) { + if (aStack == null) { + return false; + } + final Item mItem = aStack.getItem(); + if (mItem instanceof GT_MetaGenerated_Tool_01) { + return true; + } + return false; + } + + public static boolean isToolWrench(ItemStack aWrench) { + if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124)) { + return true; + } + return false; + } + + public static boolean isToolMallet(ItemStack aMallet) { + if (isItemGregtechTool(aMallet) && (aMallet.getItemDamage() == 14)) { + return true; + } + return false; + } + + public static boolean isToolScrewdriver(ItemStack aScrewdriver) { + if (isItemGregtechTool(aScrewdriver) && (aScrewdriver.getItemDamage() == 22 || aScrewdriver.getItemDamage() == 150)) { + return true; + } + return false; + } + + public static boolean isToolCrowbar(ItemStack aCrowbar) { + if (isItemGregtechTool(aCrowbar) && (aCrowbar.getItemDamage() == 20)) { + return true; + } + return false; + } + + public static boolean isToolWirecutters(ItemStack aWirecutters) { + if (isItemGregtechTool(aWirecutters) && (aWirecutters.getItemDamage() == 26)) { + return true; + } + return false; + } + + public static boolean isToolHammer(ItemStack aHammer) { + if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) { + return true; + } + return false; + } + + public static boolean isToolSolderingIron(ItemStack aSoldering) { + if (isItemGregtechTool(aSoldering) && (aSoldering.getItemDamage() == 160)) { + return true; + } + return false; + } } -- cgit From af61708010aef717ecc3537fa115547acb9aa9c7 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 18:20:28 +1000 Subject: $ More fixes. --- .../core/util/minecraft/EntityUtils.java | 35 +++++++++++++++++++++- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 10 ++++--- 2 files changed, 40 insertions(+), 5 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java index 839cb164cb..844bb0bcaf 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -1,10 +1,13 @@ package gtPlusPlus.core.util.minecraft; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; import cpw.mods.fml.common.registry.EntityRegistry; - +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.entity.*; import net.minecraft.entity.player.EntityPlayer; @@ -16,6 +19,7 @@ import net.minecraft.world.biome.BiomeGenBase; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import ic2.core.IC2Potion; import ic2.core.item.armor.ItemArmorHazmat; @@ -125,5 +129,34 @@ public class EntityUtils { public static void doDamage(Entity entity, DamageSource dmg, int i) { entity.attackEntityFrom(dmg, i); } + + public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) { + Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap"); + Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap"); + try { + Object o = aRegistry.get(null); + if (o != null) { + Map nameToClassMap = (Map) o; + if (!nameToClassMap.containsKey(aTileName)) { + o = aRegistry2.get(null); + if (o != null) { + Map classToNameMap = (Map) o; + if (!classToNameMap.containsKey(aTileClass)) { + return false; + } + else { + return true; + } + } + } + else { + return true; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index e266ee02d4..9617d12b66 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -30,6 +30,8 @@ import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration; import net.minecraft.block.Block; import net.minecraft.init.Items; @@ -1120,14 +1122,14 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01) { + if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { return true; - } + } return false; } public static boolean isToolWrench(ItemStack aWrench) { - if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124)) { + if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124 || aWrench.getItemDamage() == 7734)) { return true; } return false; @@ -1162,7 +1164,7 @@ public class ItemUtils { } public static boolean isToolHammer(ItemStack aHammer) { - if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) { + if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12 || aHammer.getItemDamage() == 7734)) { return true; } return false; -- cgit From 60b9e2b720abca8908a1ac2a7f5767af08bccaf9 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:12:52 +1000 Subject: % Allowed Skookum Choocher as a valid Wrench and Hard Hammer. $ Fixed infinite loop between TE and Block functions. --- src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 9617d12b66..ae799baa2b 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -1122,7 +1122,9 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { + final Item aSkookum = ItemUtils.getItemFromFQRN("miscutils:gt.plusplus.metatool.01"); + final Class aSkookClass = aSkookum.getClass(); + if (aSkookClass.isInstance(mItem) || mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool || mItem == aSkookum) { return true; } return false; -- cgit From f2a08747b22b51c6f051ca035abf38a6121ef320 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:30:42 +1000 Subject: + Added Hazmat utils. --- src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java new file mode 100644 index 0000000000..2f160c3cf6 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -0,0 +1,5 @@ +package gtPlusPlus.core.util.minecraft; + +public class HazmatUtils { + +} -- cgit From c0bea0f7df83c34cab115ec8f050f7e4ac8f2404 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:43:42 +1000 Subject: + Added ways to provide custom Hazmat armour. --- .../core/util/minecraft/HazmatUtils.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index 2f160c3cf6..f05b1ef393 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -1,5 +1,63 @@ package gtPlusPlus.core.util.minecraft; +import static gregtech.api.GregTech_API.sBioHazmatList; +import static gregtech.api.GregTech_API.sElectroHazmatList; +import static gregtech.api.GregTech_API.sFrostHazmatList; +import static gregtech.api.GregTech_API.sGasHazmatList; +import static gregtech.api.GregTech_API.sHeatHazmatList; +import static gregtech.api.GregTech_API.sRadioHazmatList; + +import gregtech.api.objects.GT_HashSet; +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.item.ItemStack; + public class HazmatUtils { + /** + * Registers the {@link ItemStack} to all types of protection. + * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * @param aStack - The Armour to provide protection. + * @return - Did we register this ItemStack properly? + */ + public boolean addProtection(ItemStack aStack) { + AutoMap aAdded = new AutoMap(); + aAdded.put(addProtection_Frost(aStack)); + aAdded.put(addProtection_Fire(aStack)); + aAdded.put(addProtection_Biohazard(aStack)); + aAdded.put(addProtection_Gas(aStack)); + aAdded.put(addProtection_Radiation(aStack)); + aAdded.put(addProtection_Electricty(aStack)); + for (boolean b : aAdded) { + if (!b) { + return false; + } + } + return true; + } + + public static boolean addProtection_Frost(ItemStack aStack) { + return addProtection_Generic(sFrostHazmatList, aStack); + } + public static boolean addProtection_Fire(ItemStack aStack) { + return addProtection_Generic(sHeatHazmatList, aStack); + } + public static boolean addProtection_Biohazard(ItemStack aStack) { + return addProtection_Generic(sBioHazmatList, aStack); + } + public static boolean addProtection_Gas(ItemStack aStack) { + return addProtection_Generic(sGasHazmatList, aStack); + } + public static boolean addProtection_Radiation(ItemStack aStack) { + return addProtection_Generic(sRadioHazmatList, aStack); + } + public static boolean addProtection_Electricty(ItemStack aStack) { + return addProtection_Generic(sElectroHazmatList, aStack); + } + + private static boolean addProtection_Generic(GT_HashSet aSet, ItemStack aStack) { + int aMapSize = aSet.size(); + aSet.add(aStack); + return aMapSize < aSet.size(); + } + } -- cgit From b6368490a3d910bcff1837b15f44bd78411d37bd Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:04:31 +1000 Subject: + Added Custom tooltips to Items with Hazmat bonuses granted by GT++. + Made AutoMap implement List. % More work on HazmatUtils.java. $ Fixed a bug with my GeneralTooltipEventHandler. --- .../core/util/minecraft/HazmatUtils.java | 190 ++++++++++++++++++++- 1 file changed, 187 insertions(+), 3 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index f05b1ef393..638e5dec10 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -7,50 +7,186 @@ import static gregtech.api.GregTech_API.sGasHazmatList; import static gregtech.api.GregTech_API.sHeatHazmatList; import static gregtech.api.GregTech_API.sRadioHazmatList; +import java.util.Collections; +import java.util.HashMap; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gregtech.api.objects.GT_HashSet; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.GTplusplus.INIT_PHASE; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.Utils; +import ic2.core.Ic2Items; +import ic2.core.item.armor.ItemArmorHazmat; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { + + + public static final GT_HashSet sHazmatList = new GT_HashSet(); + + private static final HashMap> mToolTips = new HashMap>(); + + + private static boolean mInit = false; + private static HazmatUtils mInstance; + + public static void init() { + if (mInit){ + return; + } + + mInstance = new HazmatUtils(); + + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatHelmet", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatChestplate", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatLeggings", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatBoots", 1L, 32767)); + //Make Nano a hazmat suit + addProtection(Ic2Items.nanoHelmet); + addProtection(Ic2Items.nanoBodyarmor); + addProtection(Ic2Items.nanoLeggings); + addProtection(Ic2Items.nanoBoots); + + //Make Quantum a hazmat suit + addProtection(Ic2Items.quantumHelmet); + addProtection(Ic2Items.quantumBodyarmor); + addProtection(Ic2Items.quantumLeggings); + addProtection(Ic2Items.quantumBoots); + + Utils.registerEvent(mInstance); + + } + + private final static String mToolTipText = "Provides protection from:"; + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event){ + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + return; + } + if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { + return; + } + else { + ItemStack aStack = event.itemStack; + String[] aTooltips = getTooltips(aStack); + if (aTooltips == null || aTooltips.length == 0) { + return; + } + else { + if (providesProtection(aStack)) { + event.toolTip.add("Provides full hazmat protection."); + } + else { + event.toolTip.add(mToolTipText); + for (String r : aTooltips) { + event.toolTip.add(" - "+r); + } + } + } + } + } + + + /** + * Static function to replace {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. + * Because IC2 doesn't let us register things ourself, anything registered via GT/GT++ will return true. + * @param living - Entity Wearing Armour + * @return - Does {@link EntityLivingBase} have a full hazmat suit on? + */ + public static boolean hasCompleteHazmat(EntityLivingBase living) { + //Entity is Null, cannot have Hazmat. + if (living == null || living.isDead) { + return false; + } + else { + + //Map All Player Armour slots + AutoMap aEquipment = new AutoMap(); + for (int i = 1; i < 5; ++i) { + ItemStack stack = living.getEquipmentInSlot(i); + + //Item is Null, cannot have full suit + if (stack == null) { + return false; + } + else { + aEquipment.put(stack); + } + } + + //Compare Equipment to all items mapped for full hazmat. + for (ItemStack aSlotStack : aEquipment) { + if (!isHazmatPiece(aSlotStack)) { + return false; + } + } + + //We are in some kind of full hazmat, huzzah! + return true; + } + } + + + + public static boolean isVanillaHazmatPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; + } + + public static boolean isHazmatPiece(ItemStack aStack) { + return isVanillaHazmatPiece(aStack) || providesProtection(aStack); + } + /** * Registers the {@link ItemStack} to all types of protection. * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public boolean addProtection(ItemStack aStack) { + public static boolean addProtection(ItemStack aStack) { AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); aAdded.put(addProtection_Fire(aStack)); aAdded.put(addProtection_Biohazard(aStack)); aAdded.put(addProtection_Gas(aStack)); aAdded.put(addProtection_Radiation(aStack)); - aAdded.put(addProtection_Electricty(aStack)); + aAdded.put(addProtection_Electricty(aStack)); for (boolean b : aAdded) { if (!b) { return false; } } + sHazmatList.add(aStack); return true; } - public static boolean addProtection_Frost(ItemStack aStack) { + registerTooltip(aStack, "Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } public static boolean addProtection_Fire(ItemStack aStack) { + registerTooltip(aStack, "Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } public static boolean addProtection_Biohazard(ItemStack aStack) { + registerTooltip(aStack, "Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } public static boolean addProtection_Gas(ItemStack aStack) { + registerTooltip(aStack, "Gas"); return addProtection_Generic(sGasHazmatList, aStack); } public static boolean addProtection_Radiation(ItemStack aStack) { + registerTooltip(aStack, "Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } public static boolean addProtection_Electricty(ItemStack aStack) { + registerTooltip(aStack, "Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } @@ -60,4 +196,52 @@ public class HazmatUtils { return aMapSize < aSet.size(); } + public static boolean providesProtection(ItemStack aStack) { + return providesProtetion_Generic(sHazmatList, aStack); + } + public static boolean providesProtetion_Frost(ItemStack aStack) { + return providesProtetion_Generic(sFrostHazmatList, aStack); + } + public static boolean providesProtetion_Fire(ItemStack aStack) { + return providesProtetion_Generic(sHeatHazmatList, aStack); + } + public static boolean providesProtetion_Biohazard(ItemStack aStack) { + return providesProtetion_Generic(sBioHazmatList, aStack); + } + public static boolean providesProtetion_Gas(ItemStack aStack) { + return providesProtetion_Generic(sGasHazmatList, aStack); + } + public static boolean providesProtetion_Radiation(ItemStack aStack) { + return providesProtetion_Generic(sRadioHazmatList, aStack); + } + public static boolean providesProtetion_Electricity(ItemStack aStack) { + return providesProtetion_Generic(sElectroHazmatList, aStack); + } + + private static boolean providesProtetion_Generic(GT_HashSet aSet, ItemStack aStack) { + if (isVanillaHazmatPiece(aStack)) { + return true; + } + return aSet.getMap().containsKey(aStack); + } + + private static String[] getTooltips(ItemStack aStack) { + AutoMap aTempTooltipData = mToolTips.get(aStack); + if (aTempTooltipData == null) { + return new String[] {}; + } + else { + Collections.sort(aTempTooltipData); + return aTempTooltipData.toArray(); + } + } + + private static void registerTooltip(ItemStack aStack, String aTooltip) { + AutoMap aTempTooltipData = mToolTips.get(aStack); + if (aTempTooltipData == null) { + aTempTooltipData = new AutoMap(); + } + aTempTooltipData.add(aTooltip); + } + } -- cgit From 08e93930faa225c4bcd91115160e91671aaa4884 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:41:11 +1000 Subject: $ Finished work on HazmatUtils.java. < Reverted the changes to GeneralTooltipEventHandler.java. --- .../core/util/minecraft/HazmatUtils.java | 81 ++++++++++++++++------ 1 file changed, 59 insertions(+), 22 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index 638e5dec10..ed5b2bcdf6 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -16,12 +16,14 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_ModHandler; import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { @@ -29,7 +31,7 @@ public class HazmatUtils { public static final GT_HashSet sHazmatList = new GT_HashSet(); - private static final HashMap> mToolTips = new HashMap>(); + private static final HashMap> mToolTips = new HashMap>(); private static boolean mInit = false; @@ -67,20 +69,27 @@ public class HazmatUtils { @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event){ - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + Logger.INFO("Ticking Hazmat handler"); + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + Logger.INFO("Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { + Logger.INFO("Invalid Itemstack or vanilla hazmat"); return; } else { - ItemStack aStack = event.itemStack; + Logger.INFO("Finding Tooltip Data"); + ItemStack aStackTemp = event.itemStack; + GT_ItemStack aStack = new GT_ItemStack(aStackTemp); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { + Logger.INFO("No Info!"); return; } - else { - if (providesProtection(aStack)) { + else { + Logger.INFO("Found Tooltips!"); + if (providesProtection(aStackTemp)) { event.toolTip.add("Provides full hazmat protection."); } else { @@ -134,11 +143,20 @@ public class HazmatUtils { } - + /** + * Is this item vanilla IC2 hazmat? + * @param aArmour - The Armour to provide protection. + * @return + */ public static boolean isVanillaHazmatPiece(ItemStack aArmour) { return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; } + /** + * Is this item a registered piece of full hazmat? (Provides all 6 protections) + * @param aStack - The Armour to provide protection. + * @return + */ public static boolean isHazmatPiece(ItemStack aStack) { return isVanillaHazmatPiece(aStack) || providesProtection(aStack); } @@ -149,7 +167,8 @@ public class HazmatUtils { * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public static boolean addProtection(ItemStack aStack) { + public static boolean addProtection(ItemStack aVanStack) { + GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); aAdded.put(addProtection_Fire(aStack)); @@ -165,37 +184,43 @@ public class HazmatUtils { sHazmatList.add(aStack); return true; } - public static boolean addProtection_Frost(ItemStack aStack) { - registerTooltip(aStack, "Frost"); + public static boolean addProtection_Frost(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.AQUA+"Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } - public static boolean addProtection_Fire(ItemStack aStack) { - registerTooltip(aStack, "Heat"); + public static boolean addProtection_Fire(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.DARK_RED+"Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } - public static boolean addProtection_Biohazard(ItemStack aStack) { - registerTooltip(aStack, "Biohazards"); + public static boolean addProtection_Biohazard(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.GREEN+"Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } - public static boolean addProtection_Gas(ItemStack aStack) { - registerTooltip(aStack, "Gas"); + public static boolean addProtection_Gas(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.WHITE+"Gas"); return addProtection_Generic(sGasHazmatList, aStack); } - public static boolean addProtection_Radiation(ItemStack aStack) { - registerTooltip(aStack, "Radiation"); + public static boolean addProtection_Radiation(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.DARK_GREEN+"Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } - public static boolean addProtection_Electricty(ItemStack aStack) { - registerTooltip(aStack, "Electricity"); + public static boolean addProtection_Electricty(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.YELLOW+"Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } - private static boolean addProtection_Generic(GT_HashSet aSet, ItemStack aStack) { + private static boolean addProtection_Generic(GT_HashSet aSet, GT_ItemStack aStack) { int aMapSize = aSet.size(); aSet.add(aStack); return aMapSize < aSet.size(); } + /** + * Does this item provide hazmat protection? (Protection against Frost, Heat, Bio, Gas, Rads, Elec) + * An item may return false even if it protects against all six damage types. This is because it's not actually registered as hazmat correct. + * @param aStack - The item to check for protection + * @return + */ public static boolean providesProtection(ItemStack aStack) { return providesProtetion_Generic(sHazmatList, aStack); } @@ -225,18 +250,22 @@ public class HazmatUtils { return aSet.getMap().containsKey(aStack); } - private static String[] getTooltips(ItemStack aStack) { + + private static String[] getTooltips(GT_ItemStack aStack) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { + Logger.INFO("Item was not mapped for TTs"); return new String[] {}; } else { + Logger.INFO("Item was mapped for TTs"); Collections.sort(aTempTooltipData); + Logger.INFO("Sorted TTs"); return aTempTooltipData.toArray(); } } - private static void registerTooltip(ItemStack aStack, String aTooltip) { + private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { aTempTooltipData = new AutoMap(); @@ -244,4 +273,12 @@ public class HazmatUtils { aTempTooltipData.add(aTooltip); } + public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { + return ItemUtils.simpleMetaStack(aGtStack.mItem, aGtStack.mMetaData, aGtStack.mStackSize); + } + + public static GT_ItemStack getGtStackFromVanilla(ItemStack aStack) { + return new GT_ItemStack(aStack); + } + } -- cgit From 75d417bfadc00fe14cfa3322a89dfc4b929919d4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 9 Apr 2019 14:28:22 +1000 Subject: + Added some new OSRS materials. % Logging tweaks to HazmatUtils.java. --- .../core/util/minecraft/HazmatUtils.java | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index ed5b2bcdf6..e6ffe1e89d 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -55,13 +55,18 @@ public class HazmatUtils { addProtection(Ic2Items.nanoLeggings); addProtection(Ic2Items.nanoBoots); + Logger.INFO("[Hazmat] Registered Nano as hazmat gear."); + //Make Quantum a hazmat suit addProtection(Ic2Items.quantumHelmet); addProtection(Ic2Items.quantumBodyarmor); addProtection(Ic2Items.quantumLeggings); - addProtection(Ic2Items.quantumBoots); + addProtection(Ic2Items.quantumBoots); + Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); - Utils.registerEvent(mInstance); + Utils.registerEvent(mInstance); + Logger.INFO("[Hazmat] Registered Tooltip handler for hazmat gear."); + mInit = true; } @@ -71,24 +76,24 @@ public class HazmatUtils { public void onItemTooltip(ItemTooltipEvent event){ Logger.INFO("Ticking Hazmat handler"); if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { - Logger.INFO("Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); + Logger.INFO("[Hazmat] Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { - Logger.INFO("Invalid Itemstack or vanilla hazmat"); + Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; } else { - Logger.INFO("Finding Tooltip Data"); + Logger.INFO("[Hazmat] Finding Tooltip Data"); ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("No Info!"); + Logger.INFO("[Hazmat] No Info!"); return; } else { - Logger.INFO("Found Tooltips!"); + Logger.INFO("[Hazmat] Found Tooltips!"); if (providesProtection(aStackTemp)) { event.toolTip.add("Provides full hazmat protection."); } @@ -168,6 +173,7 @@ public class HazmatUtils { * @return - Did we register this ItemStack properly? */ public static boolean addProtection(ItemStack aVanStack) { + Logger.INFO("[Hazmat] Registering "+aVanStack.getDisplayName() +" for full Hazmat protection."); GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); @@ -181,6 +187,7 @@ public class HazmatUtils { return false; } } + Logger.INFO("[Hazmat] Protection added for all 6 damage types, registering to master Hazmat list."); sHazmatList.add(aStack); return true; } @@ -254,23 +261,26 @@ public class HazmatUtils { private static String[] getTooltips(GT_ItemStack aStack) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { - Logger.INFO("Item was not mapped for TTs"); + Logger.INFO("[Hazmat] Item was not mapped for TTs"); return new String[] {}; } else { - Logger.INFO("Item was mapped for TTs"); + Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); - Logger.INFO("Sorted TTs"); + Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { + Logger.INFO("[Hazmat] Mapping "+aTooltip+" for "+getStackFromGtStack(aStack).getDisplayName()); AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { + Logger.INFO("No data mapped yet, creating."); aTempTooltipData = new AutoMap(); } aTempTooltipData.add(aTooltip); + mToolTips.put(aStack, aTempTooltipData); } public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { -- cgit From d087513a06066296455b1cdc00164398c0260da3 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 00:31:16 +1000 Subject: + Added some base classes for future content. + Made Teflon a refined version of PTFE. $ Fixed bad usage of PRASEODYMIUM. $ Fixed bug regrading null chemical symbols on Materials. $ Finally fixed Nano/Quantum handling for Hazmat. $ Fixed Worldgen in Everglades being too dense. --- .../core/util/minecraft/HazmatUtils.java | 268 +++++++++++++-------- 1 file changed, 162 insertions(+), 106 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index e6ffe1e89d..c37b1271d7 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -21,159 +21,184 @@ import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; +import ic2.core.item.armor.ItemArmorNanoSuit; +import ic2.core.item.armor.ItemArmorQuantumSuit; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { - - public static final GT_HashSet sHazmatList = new GT_HashSet(); - - private static final HashMap> mToolTips = new HashMap>(); - - + public static final GT_HashSet sHazmatList = new GT_HashSet(); + + private static final HashMap> mToolTips = new HashMap>(); + private static boolean mInit = false; private static HazmatUtils mInstance; - + public static void init() { - if (mInit){ + if (mInit) { return; } - + mInstance = new HazmatUtils(); - + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatHelmet", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatChestplate", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatLeggings", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatBoots", 1L, 32767)); - //Make Nano a hazmat suit - addProtection(Ic2Items.nanoHelmet); - addProtection(Ic2Items.nanoBodyarmor); - addProtection(Ic2Items.nanoLeggings); - addProtection(Ic2Items.nanoBoots); - + // Make Nano a hazmat suit + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoHelmet:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoChestplate:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoLegs:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoBoots:27", 1)); + Logger.INFO("[Hazmat] Registered Nano as hazmat gear."); - - //Make Quantum a hazmat suit - addProtection(Ic2Items.quantumHelmet); - addProtection(Ic2Items.quantumBodyarmor); - addProtection(Ic2Items.quantumLeggings); - addProtection(Ic2Items.quantumBoots); - Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); - - Utils.registerEvent(mInstance); + + // Make Quantum a hazmat suit + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumHelmet:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumChestplate:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumLegs:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumBoots:27", 1)); + Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); + + Utils.registerEvent(mInstance); Logger.INFO("[Hazmat] Registered Tooltip handler for hazmat gear."); mInit = true; - + } - + private final static String mToolTipText = "Provides protection from:"; - + @SubscribeEvent - public void onItemTooltip(ItemTooltipEvent event){ - Logger.INFO("Ticking Hazmat handler"); - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { - Logger.INFO("[Hazmat] Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); + public void onItemTooltip(ItemTooltipEvent event) { + //Logger.INFO("Ticking Hazmat handler"); + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED + && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + //Logger.INFO("[Hazmat] Bad Phase : " + GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; - } - else { - Logger.INFO("[Hazmat] Finding Tooltip Data"); + } else { ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); - String[] aTooltips = getTooltips(aStack); - if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("[Hazmat] No Info!"); - return; + if (isNanoArmourPiece(aStackTemp) || isQuantumArmourPiece(aStackTemp)) { + event.toolTip.add("Provides full hazmat protection."); } - else { - Logger.INFO("[Hazmat] Found Tooltips!"); - if (providesProtection(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); - } - else { - event.toolTip.add(mToolTipText); - for (String r : aTooltips) { - event.toolTip.add(" - "+r); - } - } - } - } + else { + Logger.INFO("[Hazmat] Finding Tooltip Data"); + String[] aTooltips = getTooltips(aStack); + if (aTooltips == null || aTooltips.length == 0) { + Logger.INFO("[Hazmat] No Info!"); + return; + } else { + Logger.INFO("[Hazmat] Found Tooltips!"); + if (providesProtection(aStackTemp)) { + event.toolTip.add("Provides full hazmat protection."); + } else { + event.toolTip.add(mToolTipText); + for (String r : aTooltips) { + event.toolTip.add(" - " + r); + } + } + } + } + } } - - + /** - * Static function to replace {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. - * Because IC2 doesn't let us register things ourself, anything registered via GT/GT++ will return true. + * Static function to replace + * {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. + * Because IC2 doesn't let us register things ourself, anything registered via + * GT/GT++ will return true. + * * @param living - Entity Wearing Armour * @return - Does {@link EntityLivingBase} have a full hazmat suit on? */ - public static boolean hasCompleteHazmat(EntityLivingBase living) { - //Entity is Null, cannot have Hazmat. + public static boolean hasCompleteHazmat(EntityLivingBase living) { + // Entity is Null, cannot have Hazmat. if (living == null || living.isDead) { return false; - } - else { - - //Map All Player Armour slots + } else { + + // Map All Player Armour slots AutoMap aEquipment = new AutoMap(); for (int i = 1; i < 5; ++i) { ItemStack stack = living.getEquipmentInSlot(i); - - //Item is Null, cannot have full suit + + // Item is Null, cannot have full suit if (stack == null) { return false; - } - else { + } else { aEquipment.put(stack); } } - - //Compare Equipment to all items mapped for full hazmat. + + // Compare Equipment to all items mapped for full hazmat. for (ItemStack aSlotStack : aEquipment) { if (!isHazmatPiece(aSlotStack)) { return false; } } - - //We are in some kind of full hazmat, huzzah! - return true; - } + + // We are in some kind of full hazmat, huzzah! + return true; + } } - - + /** * Is this item vanilla IC2 hazmat? + * * @param aArmour - The Armour to provide protection. * @return */ public static boolean isVanillaHazmatPiece(ItemStack aArmour) { - return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; - } + return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; + } + + /** + * Is this item vanilla IC2 Nanosuit? + * + * @param aArmour - The Armour to provide protection. + * @return + */ + public static boolean isNanoArmourPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorNanoSuit : false; + } + /** + * Is this item vanilla IC2 Quantum? + * + * @param aArmour - The Armour to provide protection. + * @return + */ + public static boolean isQuantumArmourPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorQuantumSuit : false; + } + /** * Is this item a registered piece of full hazmat? (Provides all 6 protections) + * * @param aStack - The Armour to provide protection. * @return */ public static boolean isHazmatPiece(ItemStack aStack) { return isVanillaHazmatPiece(aStack) || providesProtection(aStack); } - + /** - * Registers the {@link ItemStack} to all types of protection. - * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * Registers the {@link ItemStack} to all types of protection. Provides full + * hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public static boolean addProtection(ItemStack aVanStack) { - Logger.INFO("[Hazmat] Registering "+aVanStack.getDisplayName() +" for full Hazmat protection."); + public static boolean addProtection(ItemStack aVanStack) { + Logger.INFO("[Hazmat] Registering " + aVanStack.getDisplayName() + " for full Hazmat protection."); GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); @@ -181,7 +206,7 @@ public class HazmatUtils { aAdded.put(addProtection_Biohazard(aStack)); aAdded.put(addProtection_Gas(aStack)); aAdded.put(addProtection_Radiation(aStack)); - aAdded.put(addProtection_Electricty(aStack)); + aAdded.put(addProtection_Electricty(aStack)); for (boolean b : aAdded) { if (!b) { return false; @@ -189,63 +214,78 @@ public class HazmatUtils { } Logger.INFO("[Hazmat] Protection added for all 6 damage types, registering to master Hazmat list."); sHazmatList.add(aStack); - return true; + return true; } + public static boolean addProtection_Frost(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.AQUA+"Frost"); + registerTooltip(aStack, EnumChatFormatting.AQUA + "Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } + public static boolean addProtection_Fire(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_RED+"Heat"); + registerTooltip(aStack, EnumChatFormatting.DARK_RED + "Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } + public static boolean addProtection_Biohazard(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.GREEN+"Biohazards"); + registerTooltip(aStack, EnumChatFormatting.GREEN + "Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } + public static boolean addProtection_Gas(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.WHITE+"Gas"); + registerTooltip(aStack, EnumChatFormatting.WHITE + "Gas"); return addProtection_Generic(sGasHazmatList, aStack); } + public static boolean addProtection_Radiation(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_GREEN+"Radiation"); + registerTooltip(aStack, EnumChatFormatting.DARK_GREEN + "Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } + public static boolean addProtection_Electricty(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.YELLOW+"Electricity"); + registerTooltip(aStack, EnumChatFormatting.YELLOW + "Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } - + private static boolean addProtection_Generic(GT_HashSet aSet, GT_ItemStack aStack) { int aMapSize = aSet.size(); aSet.add(aStack); return aMapSize < aSet.size(); } - + /** - * Does this item provide hazmat protection? (Protection against Frost, Heat, Bio, Gas, Rads, Elec) - * An item may return false even if it protects against all six damage types. This is because it's not actually registered as hazmat correct. + * Does this item provide hazmat protection? (Protection against Frost, Heat, + * Bio, Gas, Rads, Elec) An item may return false even if it protects against + * all six damage types. This is because it's not actually registered as hazmat + * correct. + * * @param aStack - The item to check for protection * @return */ public static boolean providesProtection(ItemStack aStack) { return providesProtetion_Generic(sHazmatList, aStack); } + public static boolean providesProtetion_Frost(ItemStack aStack) { return providesProtetion_Generic(sFrostHazmatList, aStack); } + public static boolean providesProtetion_Fire(ItemStack aStack) { return providesProtetion_Generic(sHeatHazmatList, aStack); } + public static boolean providesProtetion_Biohazard(ItemStack aStack) { return providesProtetion_Generic(sBioHazmatList, aStack); } + public static boolean providesProtetion_Gas(ItemStack aStack) { return providesProtetion_Generic(sGasHazmatList, aStack); } + public static boolean providesProtetion_Radiation(ItemStack aStack) { return providesProtetion_Generic(sRadioHazmatList, aStack); } + public static boolean providesProtetion_Electricity(ItemStack aStack) { return providesProtetion_Generic(sElectroHazmatList, aStack); } @@ -256,39 +296,55 @@ public class HazmatUtils { } return aSet.getMap().containsKey(aStack); } - - - private static String[] getTooltips(GT_ItemStack aStack) { - AutoMap aTempTooltipData = mToolTips.get(aStack); + + private static String[] getTooltips(GT_ItemStack aStack) { + String aKey = convertGtItemstackToStringData(aStack); + AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { - Logger.INFO("[Hazmat] Item was not mapped for TTs"); + Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); return new String[] {}; - } - else { + } else { Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } - + private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { - Logger.INFO("[Hazmat] Mapping "+aTooltip+" for "+getStackFromGtStack(aStack).getDisplayName()); - AutoMap aTempTooltipData = mToolTips.get(aStack); + String aKey = convertGtItemstackToStringData(aStack); + Logger.INFO("[Hazmat] Mapping " + aTooltip + " for " + aKey); + AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { Logger.INFO("No data mapped yet, creating."); aTempTooltipData = new AutoMap(); } aTempTooltipData.add(aTooltip); - mToolTips.put(aStack, aTempTooltipData); + mToolTips.put(convertGtItemstackToStringData(aStack), aTempTooltipData); } - + public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { return ItemUtils.simpleMetaStack(aGtStack.mItem, aGtStack.mMetaData, aGtStack.mStackSize); } - + public static GT_ItemStack getGtStackFromVanilla(ItemStack aStack) { return new GT_ItemStack(aStack); } + + private static String convertGtItemstackToStringData(GT_ItemStack aStack) { + if (aStack == null) { + return "NULL"; + } else { + return aStack.mItem.getUnlocalizedName() + "." + aStack.mMetaData + "." + aStack.mStackSize; + } + } + private static String convertGtItemstackToStringDataIgnoreDamage(GT_ItemStack aStack) { + if (aStack == null) { + return "NULL"; + } else { + return aStack.mItem.getUnlocalizedName() + "." + aStack.mStackSize; + } + } + } -- cgit From 3b7cff8412af5afbf99bfd40fee1193a6cd8c400 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 02:59:02 +1000 Subject: + Added some new Monster Killer Baubles. Kill nearby mobs for power, power cost scales with HP total, left and other EntityLiving stats. + Added new constructors for AutoMaps. + Added a Wrapper (AABB) for AxisAlignedBB. $ Fixed Hot Titanium Ingot recipe. --- .../core/util/minecraft/EntityUtils.java | 48 +++++++++++++++++----- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java index 844bb0bcaf..8c5a9f6581 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -3,26 +3,28 @@ package gtPlusPlus.core.util.minecraft; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; +import java.util.List; import java.util.Map; import cpw.mods.fml.common.registry.EntityRegistry; -import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.AABB; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import ic2.core.IC2Potion; +import ic2.core.item.armor.ItemArmorHazmat; import net.minecraft.block.Block; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import gregtech.api.util.GT_Utility; - -import gtPlusPlus.api.objects.minecraft.BlockPos; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import ic2.core.IC2Potion; -import ic2.core.item.armor.ItemArmorHazmat; - public class EntityUtils { public static void setEntityOnFire(final Entity entity, final int length){ @@ -158,5 +160,31 @@ public class EntityUtils { } return false; } + + public static double getDistance(Entity p1, Entity p2) { + return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2)); + } + + public static AutoMap getEntitiesWithinBoundingBoxExcluding(Entity aExclusion, AABB aBoundingBox){ + + if (aExclusion == null) { + return new AutoMap(); + } + else { + List aEntities = aBoundingBox.world().getEntitiesWithinAABBExcludingEntity(aExclusion, aBoundingBox.get()); + return new AutoMap(aEntities); + } + } + + public static AutoMap getEntitiesWithinBoundingBox(Class aEntityType, AABB aBoundingBox){ + + if (aEntityType == null) { + return new AutoMap(); + } + else { + List aEntities = aBoundingBox.world().getEntitiesWithinAABB(aEntityType, aBoundingBox.get()); + return new AutoMap(aEntities); + } + } } -- cgit From be88e9009e66ef27d9bccd27cce7fd13ae3b06cd Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 04:14:27 +1000 Subject: + Added the ASM segment for IC2 Hazmat. - Disabled most Hazmat logging. % Mild adjustment to formatting for mob types in MK Baubles tooltips. --- .../gtPlusPlus/core/util/minecraft/HazmatUtils.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/minecraft') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index c37b1271d7..c529f60ba1 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -19,7 +19,6 @@ import gtPlusPlus.GTplusplus.INIT_PHASE; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; -import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; import ic2.core.item.armor.ItemArmorNanoSuit; import ic2.core.item.armor.ItemArmorQuantumSuit; @@ -81,24 +80,24 @@ public class HazmatUtils { return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { - Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); + //Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; } else { ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); if (isNanoArmourPiece(aStackTemp) || isQuantumArmourPiece(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); + event.toolTip.add(EnumChatFormatting.DARK_PURPLE+"Provides full hazmat protection."); } else { - Logger.INFO("[Hazmat] Finding Tooltip Data"); + //Logger.INFO("[Hazmat] Finding Tooltip Data"); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("[Hazmat] No Info!"); + //Logger.INFO("[Hazmat] No Info!"); return; } else { - Logger.INFO("[Hazmat] Found Tooltips!"); + //Logger.INFO("[Hazmat] Found Tooltips!"); if (providesProtection(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); + event.toolTip.add(EnumChatFormatting.LIGHT_PURPLE+"Provides full hazmat protection."); } else { event.toolTip.add(mToolTipText); for (String r : aTooltips) { @@ -301,12 +300,12 @@ public class HazmatUtils { String aKey = convertGtItemstackToStringData(aStack); AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { - Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); + //Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); return new String[] {}; } else { - Logger.INFO("[Hazmat] Item was mapped for TTs"); + //Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); - Logger.INFO("[Hazmat] Sorted TTs"); + //Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } -- cgit