diff options
author | boubou_19 <miisterunknown@gmail.com> | 2021-08-16 20:32:53 +0200 |
---|---|---|
committer | boubou_19 <miisterunknown@gmail.com> | 2021-08-16 20:32:53 +0200 |
commit | 8f5dd5625e4632bbecda0771caad47bbbbd35d4c (patch) | |
tree | 15d544c783cd17606e6d71259eefc062ba4ea8e5 /src/main/java/gregtech/api/util/GT_Utility.java | |
parent | 99030ff940686562c7e4f133919fb1496b0575f4 (diff) | |
parent | c543724aa11d696fa049855e7b330364c1000a17 (diff) | |
download | GT5-Unofficial-8f5dd5625e4632bbecda0771caad47bbbbd35d4c.tar.gz GT5-Unofficial-8f5dd5625e4632bbecda0771caad47bbbbd35d4c.tar.bz2 GT5-Unofficial-8f5dd5625e4632bbecda0771caad47bbbbd35d4c.zip |
Merge remote-tracking branch 'upstream/experimental' into experimental
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_Utility.java')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 229 |
1 files changed, 131 insertions, 98 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8cbb44fe07..be5f978d6e 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -3,36 +3,30 @@ package gregtech.api.util; import cofh.api.transport.IItemDuct; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; +import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.SubTag; -import gregtech.api.enums.Textures; -import gregtech.api.enums.ToolDictNames; +import gregtech.api.enums.*; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IBlockContainer; import gregtech.api.interfaces.IDebugableBlock; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.interfaces.tileentity.IUpgradableMachine; +import gregtech.api.interfaces.tileentity.*; import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.net.GT_Packet_Sound; +import gregtech.api.objects.CollectorUtils; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; +import gregtech.api.util.extensions.ArrayExt; import gregtech.common.GT_Proxy; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; @@ -41,11 +35,7 @@ import ic2.api.recipe.RecipeOutput; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.EnumCreatureAttribute; +import net.minecraft.entity.*; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -67,10 +57,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MathHelper; +import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; @@ -81,47 +68,22 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; +import java.util.function.IntFunction; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.D1; -import static gregtech.api.enums.GT_Values.DW; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.GT; -import static gregtech.api.enums.GT_Values.L; -import static gregtech.api.enums.GT_Values.M; -import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.GT_Values.W; +import static gregtech.api.enums.GT_Values.*; import static gregtech.common.GT_Proxy.GTPOLLUTION; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; @@ -131,6 +93,9 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; * Just a few Utility Functions I use. */ public class GT_Utility { + /** Formats a number with group separator and at most 2 fraction digits. */ + private static final DecimalFormat decimalFormat = new DecimalFormat(); + /** * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. */ @@ -144,6 +109,11 @@ public class GT_Utility { public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); static { + DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols(); + symbols.setGroupingSeparator(' '); + decimalFormat.setDecimalFormatSymbols(symbols); + decimalFormat.setMaximumFractionDigits(2); + GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); } @@ -438,7 +408,7 @@ public class GT_Utility { if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot)); - ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack)); + ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyOrNull(tStack)); byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) { //((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F); @@ -458,7 +428,7 @@ public class GT_Utility { if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot)); - byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo)); + byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyOrNull(tStack), false, ForgeDirection.getOrientation(aPutTo)); if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) { tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo))); aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount); @@ -509,7 +479,7 @@ public class GT_Utility { ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null; if (tStack1 != null) { if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; - tStack3 = copy(tStack1); + tStack3 = copyOrNull(tStack1); aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit()))); tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce; @@ -518,7 +488,7 @@ public class GT_Utility { aTileEntity1.markDirty(); if (tStack3 != null) { if (tStack2 == null) { - aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3)); + aTileEntity2.setInventorySlotContents(aPutTo, copyOrNull(tStack3)); } else { tStack2.stackSize += tStack3.stackSize; } @@ -929,7 +899,7 @@ public class GT_Utility { } public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { - return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT); + return areStacksEqual(GT_OreDictUnificator.get_nocopy(aStack1), GT_OreDictUnificator.get_nocopy(aStack2), aIgnoreNBT); } public static String getFluidName(Fluid aFluid, boolean aLocalized) { @@ -999,6 +969,10 @@ public class GT_Utility { } public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) { + return getFluidDisplayStack(aFluid, aUseStackSize, false); + } + + public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize, boolean aHideStackSize) { if (aFluid == null || aFluid.getFluid() == null) return null; int tmp = 0; try { @@ -1011,6 +985,7 @@ public class GT_Utility { tNBT.setLong("mFluidDisplayAmount", aUseStackSize ? aFluid.amount : 0); tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid)); tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid)); + tNBT.setBoolean("mHideStackSize", aHideStackSize); rStack.setTagCompound(tNBT); return rStack; } @@ -1146,7 +1121,7 @@ public class GT_Utility { if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false; aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack)); } else { - aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); + aRecipeList.put(new RecipeInputItemStack(copyOrNull(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); } return true; } @@ -1190,7 +1165,7 @@ public class GT_Utility { rStack.setTagCompound(tNBT); GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'"); GregTech_API.sBookList.put(aMapping, rStack); - return copy(rStack); + return copyOrNull(rStack); } public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) { @@ -1269,6 +1244,9 @@ public class GT_Utility { return false; } + /** + * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result. + */ public static <T> ArrayList<T> getArrayListWithoutNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray)); @@ -1276,6 +1254,9 @@ public class GT_Utility { return rList; } + /** + * Note: use {@link ArrayExt#withoutTrailingNulls(Object[], IntFunction)} if you want an array as a result. + */ public static <T> ArrayList<T> getArrayListWithoutTrailingNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray)); @@ -1283,6 +1264,7 @@ public class GT_Utility { return rList; } + @Deprecated // why do you use Objects? public static Block getBlock(Object aBlock) { return (Block) aBlock; } @@ -1296,12 +1278,14 @@ public class GT_Utility { return Block.getBlockFromItem(item); } + @Deprecated // why do you use Objects? And if you want to check your block to be not null, check it directly! public static boolean isBlockValid(Object aBlock) { return (aBlock instanceof Block); } + @Deprecated // why do you use Objects? And if you want to check your block to be null, check it directly! public static boolean isBlockInvalid(Object aBlock) { - return aBlock == null || !(aBlock instanceof Block); + return !(aBlock instanceof Block); } public static boolean isStringValid(Object aString) { @@ -1586,9 +1570,17 @@ public class GT_Utility { return isWearingFullGasHazmat(aEntity); } - public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) { + public static boolean applyHeatDamage(EntityLivingBase entity, float damage) { + return applyHeatDamage(entity, damage, GT_DamageSources.getHeatDamage()); + } + + public static boolean applyHeatDamageFromItem(EntityLivingBase entity, float damage, ItemStack item) { + return applyHeatDamage(entity, damage, new DamageSourceHotItem(item)); + } + + private static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage, DamageSource source) { if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.fireResistance) == null && !isWearingFullHeatHazmat(aEntity)) { - aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage); + aEntity.attackEntityFrom(source, aDamage); return true; } return false; @@ -1651,6 +1643,12 @@ public class GT_Utility { return null; } + @Nullable + public static ItemStack copyOrNull(@Nullable ItemStack stack) { + if (isStackValid(stack)) return stack.copy(); + return null; + } + public static ItemStack copyAmount(long aAmount, Object... aStacks) { ItemStack rStack = copy(aStacks); if (isStackInvalid(rStack)) return null; @@ -1755,15 +1753,8 @@ public class GT_Utility { return aMap; } - /** - * Why the fuck do neither Java nor Guava have a Function to do this? - */ - public static <X, Y extends Comparable> LinkedHashMap<X, Y> sortMapByValuesAcending(Map<X, Y> aMap) { - List<Map.Entry<X, Y>> tEntrySet = new LinkedList<>(aMap.entrySet()); - tEntrySet.sort(Entry.comparingByValue()); - LinkedHashMap<X, Y> rMap = new LinkedHashMap<>(); - for (Map.Entry<X, Y> tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); - return rMap; + public static <X, Y extends Comparable<Y>> LinkedHashMap<X, Y> sortMapByValuesAcending(Map<X, Y> map) { + return map.entrySet().stream().sorted(Entry.comparingByValue()).collect(CollectorUtils.entriesToMap(LinkedHashMap::new)); } /** @@ -1921,15 +1912,25 @@ public class GT_Utility { Block tBlock = aWorld.getBlock(aX, aY, aZ); - tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); + tList.add( + "----- X: " + EnumChatFormatting.AQUA + formatNumbers(aX) + EnumChatFormatting.RESET + + " Y: " + EnumChatFormatting.AQUA + formatNumbers(aY) + EnumChatFormatting.RESET + + " Z: " + EnumChatFormatting.AQUA + formatNumbers(aZ) + EnumChatFormatting.RESET + + " D: " + EnumChatFormatting.AQUA + aWorld.provider.dimensionId + EnumChatFormatting.RESET + " -----"); try { - if (tTileEntity != null && tTileEntity instanceof IInventory) - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); + if (tTileEntity instanceof IInventory) + tList.add( + trans("162","Name: ") + EnumChatFormatting.BLUE + ((IInventory) tTileEntity).getInventoryName() + EnumChatFormatting.RESET + + trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET); else - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); - - tList.add(trans("164","Hardness: ") +EnumChatFormatting.YELLOW+ tBlock.getBlockHardness(aWorld, aX, aY, aZ) +EnumChatFormatting.RESET+ trans("165"," Blast Resistance: ") +EnumChatFormatting.YELLOW+ tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) +EnumChatFormatting.RESET); - if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD+ trans("166","Is valid Beacon Pyramid Material") +EnumChatFormatting.RESET); + tList.add( + trans("162","Name: ") + EnumChatFormatting.BLUE + tBlock.getUnlocalizedName() + EnumChatFormatting.RESET + + trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET); + + tList.add( + trans("164","Hardness: ") + EnumChatFormatting.YELLOW + tBlock.getBlockHardness(aWorld, aX, aY, aZ) + EnumChatFormatting.RESET + + trans("165"," Blast Resistance: ") + EnumChatFormatting.YELLOW + tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) + EnumChatFormatting.RESET); + if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD + trans("166","Is valid Beacon Pyramid Material") + EnumChatFormatting.RESET); } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } @@ -1939,7 +1940,10 @@ public class GT_Utility { rEUAmount += 500; FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(ForgeDirection.getOrientation(aSide)); if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { - tList.add(trans("167","Tank ") + i + ": " +EnumChatFormatting.GREEN+ formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) +EnumChatFormatting.RESET+ " L / " +EnumChatFormatting.YELLOW+ formatNumbers(tTanks[i].capacity) +EnumChatFormatting.RESET+ " L " +EnumChatFormatting.GOLD+ getFluidName(tTanks[i].fluid, true)+EnumChatFormatting.RESET); + tList.add( + trans("167","Tank ") + i + ": " + + EnumChatFormatting.GREEN + formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + EnumChatFormatting.RESET + " L / " + + EnumChatFormatting.YELLOW + formatNumbers(tTanks[i].capacity) + EnumChatFormatting.RESET + " L " + EnumChatFormatting.GOLD + getFluidName(tTanks[i].fluid, true) + EnumChatFormatting.RESET); } } } catch (Throwable e) { @@ -1956,8 +1960,23 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.reactor.IReactor) { rEUAmount += 500; - tList.add(trans("168","Heat: ") +EnumChatFormatting.GREEN+ ((ic2.api.reactor.IReactor) tTileEntity).getHeat() +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()+EnumChatFormatting.RESET); - tList.add(trans("169","HEM: ") +EnumChatFormatting.YELLOW+((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() +EnumChatFormatting.RESET/*+ trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + tList.add( + trans("168","Heat: ") + EnumChatFormatting.GREEN + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getHeat()) + EnumChatFormatting.RESET + " / " + + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()) + EnumChatFormatting.RESET); + tList.add( + trans("169","HEM: ") + EnumChatFormatting.YELLOW + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() + EnumChatFormatting.RESET + /* + trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { + if (tTileEntity instanceof IAlignmentProvider) { + IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment(); + if (tAlignment != null) { + rEUAmount += 100; + tList.add(trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + tAlignment.getExtendedFacing() + EnumChatFormatting.RESET); + } } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2000,7 +2019,7 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { rEUAmount += 200; - tList.add(trans("175","Conduction Loss: ") +EnumChatFormatting.YELLOW+ ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()+EnumChatFormatting.RESET); + tList.add(trans("175","Conduction Loss: ") + EnumChatFormatting.YELLOW + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss() + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2008,7 +2027,9 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { rEUAmount += 200; - tList.add(trans("176","Contained Energy: ") +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()+EnumChatFormatting.RESET+" EU"); + tList.add( + trans("176","Contained Energy: ") + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getStored()) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()) + EnumChatFormatting.RESET + " EU"); //aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible"); } } catch (Throwable e) { @@ -2017,7 +2038,7 @@ public class GT_Utility { try { if (tTileEntity instanceof IUpgradableMachine) { rEUAmount += 500; - if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN+ trans("177","Has Muffler Upgrade") +EnumChatFormatting.RESET); + if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN + trans("177","Has Muffler Upgrade") + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2025,7 +2046,7 @@ public class GT_Utility { try { if (tTileEntity instanceof IMachineProgress) { if (((IMachineProgress) tTileEntity).isAllowedToWork()) { - tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET); + tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET); } if (((IMachineProgress) tTileEntity).wasShutdown()) { tList.add("Shut down due to power loss." + EnumChatFormatting.RED + EnumChatFormatting.RESET); @@ -2033,7 +2054,8 @@ public class GT_Utility { rEUAmount += 400; int tValue = 0; if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) - tList.add(trans("178","Progress/Load: ") +EnumChatFormatting.GREEN+ formatNumbers(((IMachineProgress) tTileEntity).getProgress()) +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ formatNumbers(tValue) +EnumChatFormatting.RESET); + tList.add(trans("178","Progress/Load: ") + EnumChatFormatting.GREEN + formatNumbers(((IMachineProgress) tTileEntity).getProgress()) + EnumChatFormatting.RESET + " / " + + EnumChatFormatting.YELLOW + formatNumbers(tValue) + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2049,16 +2071,22 @@ public class GT_Utility { } try { if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add(trans("179","Max IN: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+((IBasicEnergyContainer)tTileEntity).getInputAmperage()+EnumChatFormatting.RESET+trans("183"," A")); - tList.add(trans("181","Max OUT: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() +EnumChatFormatting.RESET+ trans("183"," A")); - tList.add(trans("184","Energy: ") +EnumChatFormatting.GREEN+ formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) +EnumChatFormatting.RESET+ " EU"); + tList.add( + trans("179","Max IN: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getInputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " + EnumChatFormatting.RESET + + trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer)tTileEntity).getInputAmperage()) + EnumChatFormatting.RESET + trans("183"," A")); + tList.add( + trans("181","Max OUT: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " + EnumChatFormatting.RESET + + trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputAmperage()) + EnumChatFormatting.RESET + trans("183"," A")); + tList.add( + trans("184","Energy: ") + EnumChatFormatting.GREEN + formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + EnumChatFormatting.RESET + " EU"); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } try { if (tTileEntity instanceof IGregTechTileEntity) { - tList.add(trans("186","Owned by: ") +EnumChatFormatting.BLUE+ ((IGregTechTileEntity) tTileEntity).getOwnerName()+EnumChatFormatting.RESET); + tList.add(trans("186","Owned by: ") + EnumChatFormatting.BLUE + ((IGregTechTileEntity) tTileEntity).getOwnerName() + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2110,15 +2138,15 @@ public class GT_Utility { if (aPlayer.capabilities.isCreativeMode) { FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read if (tFluid!=null) - tList.add(EnumChatFormatting.GOLD+tFluid.getLocalizedName()+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ tFluid.amount +EnumChatFormatting.RESET+" L"); + tList.add(EnumChatFormatting.GOLD + tFluid.getLocalizedName() + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + formatNumbers(tFluid.amount) + EnumChatFormatting.RESET + " L"); else - tList.add(EnumChatFormatting.GOLD+trans("201","Nothing")+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ '0' +EnumChatFormatting.RESET+" L"); + tList.add(EnumChatFormatting.GOLD + trans("201","Nothing") + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + '0' + EnumChatFormatting.RESET + " L"); } // if(aPlayer.capabilities.isCreativeMode){ int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair()); - if(chunkData !=null){ + if(chunkData != null){ if(chunkData[GTPOLLUTION]>0){ - tList.add(trans("202","Pollution in Chunk: ")+EnumChatFormatting.RED+chunkData[GTPOLLUTION]+EnumChatFormatting.RESET+trans("203"," gibbl")); + tList.add(trans("202","Pollution in Chunk: ") + EnumChatFormatting.RED + formatNumbers(chunkData[GTPOLLUTION]) + EnumChatFormatting.RESET + trans("203"," gibbl")); }else{ tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); } @@ -2226,10 +2254,11 @@ public class GT_Utility { } public static String formatNumbers(long aNumber) { - DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); - DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); - symbols.setGroupingSeparator(' '); - return formatter.format(aNumber); + return decimalFormat.format(aNumber); + } + + public static String formatNumbers(double aNumber) { + return decimalFormat.format(aNumber); } /* @@ -2855,4 +2884,8 @@ public class GT_Utility { dropItem.delayBeforeCanPickup = 0; } } + + public static long getNonnullElementCount(Object[] tArray) { + return Arrays.stream(tArray).filter(Objects::nonNull).count(); + } } |