From 7568a1d454feab63d15ef1098fdfc53591742e6a Mon Sep 17 00:00:00 2001 From: Dragon2488 Date: Wed, 24 May 2017 00:29:55 +0700 Subject: [PATCH] some GT_Utility polishing. unfinished. --- .../metatileentity/BaseMetaTileEntity.java | 7 +- .../gregtech/api/net/GT_Packet_Sound.java | 25 +- .../java/gregtech/api/util/GT_Utility.java | 720 ++++++------------ 3 files changed, 257 insertions(+), 495 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index e78da346..060e6a60 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -816,7 +816,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getStrongestRedstone() { - return (byte) Math.max(getInternalInputRedstoneSignal((byte) 0), Math.max(getInternalInputRedstoneSignal((byte) 1), Math.max(getInternalInputRedstoneSignal((byte) 2), Math.max(getInternalInputRedstoneSignal((byte) 3), Math.max(getInternalInputRedstoneSignal((byte) 4), getInternalInputRedstoneSignal((byte) 5)))))); + byte strongest = 0; + for(EnumFacing side : EnumFacing.VALUES) { + byte signal = getInternalInputRedstoneSignal(side); + if(signal > strongest) strongest = signal; + } + return strongest; } @Override diff --git a/src/main/java/gregtech/api/net/GT_Packet_Sound.java b/src/main/java/gregtech/api/net/GT_Packet_Sound.java index 44692aab..4d48879d 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_Sound.java +++ b/src/main/java/gregtech/api/net/GT_Packet_Sound.java @@ -2,25 +2,24 @@ package gregtech.api.net; import gregtech.api.util.GT_Utility; import io.netty.buffer.ByteBuf; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.ByteBufUtils; public class GT_Packet_Sound extends GT_Packet { - private int mX, mZ, mY; + private Vec3d mPosition; private String mSoundName; private float mSoundStrength, mSoundPitch; public GT_Packet_Sound() {} - public GT_Packet_Sound(String aSoundName, float aSoundStrength, float aSoundPitch, int aX, short aY, int aZ) { - mX = aX; - mY = aY; - mZ = aZ; - mSoundName = aSoundName; - mSoundStrength = aSoundStrength; - mSoundPitch = aSoundPitch; + public GT_Packet_Sound(String soundName, float soundStrength, float soundPitch, Vec3d soundPosition) { + this.mPosition = soundPosition; + this.mSoundName = soundName; + this.mSoundStrength = soundStrength; + this.mSoundPitch = soundPitch; } @Override @@ -28,9 +27,9 @@ public class GT_Packet_Sound extends GT_Packet { ByteBufUtils.writeUTF8String(buf, mSoundName); buf.writeFloat(mSoundStrength); buf.writeFloat(mSoundPitch); - buf.writeInt(mX); - buf.writeShort(mY); - buf.writeInt(mZ); + buf.writeDouble(mPosition.xCoord); + buf.writeDouble(mPosition.yCoord); + buf.writeDouble(mPosition.zCoord); } @Override @@ -38,9 +37,7 @@ public class GT_Packet_Sound extends GT_Packet { mSoundName = ByteBufUtils.readUTF8String(buf); mSoundStrength = buf.readFloat(); mSoundPitch = buf.readFloat(); - mX = buf.readInt(); - mY = buf.readShort(); - mZ = buf.readInt(); + mPosition = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()); } @Override diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 52e14ff7..086fd4ea 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -233,6 +233,7 @@ public class GT_Utility { public static TextureAtlasSprite getTexture(String location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location); } + @SideOnly(Side.CLIENT) public static TextureAtlasSprite getTexture(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); @@ -240,12 +241,12 @@ public class GT_Utility { public static int fillFluidTank(World world, BlockPos blockPos, EnumFacing side, FluidStack fill) { TileEntity tileEntity = world.getTileEntity(blockPos.offset(side)); - if(tileEntity != null && fill != null) { - if(tileEntity instanceof IFluidHandler) { + if (tileEntity != null && fill != null) { + if (tileEntity instanceof IFluidHandler) { IFluidHandler fluidHandler = (IFluidHandler) tileEntity; return fluidHandler.fill(side.getOpposite(), fill, true); } - if(tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())) { + if (tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())) { net.minecraftforge.fluids.capability.IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); return fluidHandler.fill(fill, true); } @@ -391,11 +392,11 @@ public class GT_Utility { return moveStackIntoPipe(aTileEntity1, aTileEntity2, aGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); } - /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. - * - * @return the Amount of moved Items - */ + /** + * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. + * + * @return the Amount of moved Items + */ public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, int aPutTo, List aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean dropItem) { if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; @@ -532,7 +533,7 @@ public class GT_Utility { } } } - if (tMovedItemCount > 0) return tMovedItemCount; + if (tMovedItemCount > 0) return tMovedItemCount; } if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) { @@ -756,9 +757,9 @@ public class GT_Utility { return aFluid.isFluidEqual(containerItem.getFluid(aStack)); } - if(aCheckIFluidContainerItems && aStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) { + if (aCheckIFluidContainerItems && aStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) { net.minecraftforge.fluids.capability.IFluidHandler fluidHandler = aStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); - if(fluidHandler.getTankProperties().length == 0) return false; + if (fluidHandler.getTankProperties().length == 0) return false; return aFluid.isFluidEqual(fluidHandler.getTankProperties()[0].getContents()); } FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack)); @@ -808,8 +809,9 @@ public class GT_Utility { return null; } - public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map aRecipeList, ItemStack aOutput){ - if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) return false; + public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map aRecipeList, ItemStack aOutput) { + if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) + return false; boolean rReturn = false; Iterator> tIterator = aRecipeList.entrySet().iterator(); aOutput = GT_OreDictUnificator.get(aOutput); @@ -858,10 +860,11 @@ public class GT_Utility { } } ItemStack[] tStack = GT_OreDictUnificator.getStackArray(true, aOutput); - if(tStack==null||(tStack.length>0&>_Utility.areStacksEqual(aInput, tStack[0])))return false; + if (tStack == null || (tStack.length > 0 && GT_Utility.areStacksEqual(aInput, tStack[0]))) return false; if (tOreName != null) { //Catch Fossils Archeology Revival crash - if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false; + if (tOreName.toString().equals("dustAsh") && tStack[0].getUnlocalizedName().equals("tile.volcanicAsh")) + return false; aRecipeList.addRecipe(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), aNBT, true, tStack); } else { aRecipeList.addRecipe(new RecipeInputItemStack(copy(aInput), aInput.stackSize), aNBT, true, tStack); @@ -911,109 +914,32 @@ public class GT_Utility { return copy(rStack); } - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) { - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, GT.getThePlayer()); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, Entity aEntity) { - if (aEntity == null) return false; - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, aEntity.posX, aEntity.posY, aEntity.posZ); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, double aX, double aY, double aZ) { - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, 1.01818028F, aX, aY, aZ); - } - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, BlockPos pos) { - return doSoundAtClient(aSoundName, aTimeUntilNextSound, aSoundStrength, 1.01818028F, pos.getX(), pos.getY(), pos.getZ()); - } - - - public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength, float aSoundModulation, double aX, double aY, double aZ) { - if (isStringInvalid(aSoundName) || !FMLCommonHandler.instance().getEffectiveSide().isClient() || GT.getThePlayer() == null || !GT.getThePlayer().worldObj.isRemote) - return false; - new GT_Runnable_Sound(GT.getThePlayer().worldObj, MathHelper.floor_double(aX), MathHelper.floor_double(aY), MathHelper.floor_double(aZ), aTimeUntilNextSound, aSoundName, aSoundStrength, aSoundModulation).run(); - return true; - } - public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) { - if (isStringInvalid(aSoundName) || aWorld == null || aWorld.isRemote) return false; + if (!isStringValid(aSoundName) || aWorld == null || aWorld.isRemote) return false; NW.sendToAllAround(aWorld, new GT_Packet_Sound(aSoundName, aSoundStrength, aSoundModulation, aX, (short) aY, aZ), aX, aY, aZ); return true; } + public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, BlockPos blockPos) { return sendSoundToPlayers(aWorld, aSoundName, aSoundStrength, aSoundModulation, blockPos.getX(), blockPos.getY(), blockPos.getZ()); } public static int stackToIntHash(ItemStack aStack) { - if (isStackInvalid(aStack)) return 0; + if (!isStackValid(aStack)) return 0; return Item.getIdFromItem(aStack.getItem()) | (Items.FEATHER.getDamage(aStack) << 16); } - public static boolean arrayContains(Object aObject, Object... aObjects) { - return listContains(aObject, Arrays.asList(aObjects)); + public static boolean isStringValid(String aString) { + return aString != null && !aString.isEmpty(); } - public static boolean listContains(Object aObject, Collection aObjects) { - if (aObjects == null) return false; - return aObjects.contains(aObject); - } - - public static boolean arrayContainsNonNull(T... aArray) { - if (aArray != null) for (Object tObject : aArray) if (tObject != null) return true; - return false; - } - - public static ArrayList getArrayListWithoutNulls(T... aArray) { - if (aArray == null) return new ArrayList(); - ArrayList rList = new ArrayList(Arrays.asList(aArray)); - for (int i = 0; i < rList.size(); i++) if (rList.get(i) == null) rList.remove(i--); - return rList; - } - - public static ArrayList getArrayListWithoutTrailingNulls(T... aArray) { - if (aArray == null) return new ArrayList(); - ArrayList rList = new ArrayList(Arrays.asList(aArray)); - for (int i = rList.size() - 1; i >= 0 && rList.get(i) == null; ) rList.remove(i--); - return rList; - } - - public static Block getBlock(Object aBlock) { - return (Block) aBlock; - } - - public static Block getBlockFromStack(Object aStack) { - if (isStackInvalid(aStack)) return null; - return Block.getBlockFromItem(((ItemStack) aStack).getItem()); - } - - public static boolean isBlockValid(Object aBlock) { - return aBlock instanceof Block; - } - - public static boolean isBlockInvalid(Object aBlock) { - return aBlock == null || !(aBlock instanceof Block); - } - - public static boolean isStringValid(Object aString) { - return aString != null && !aString.toString().isEmpty(); - } - - public static boolean isStringInvalid(Object aString) { - return aString == null || aString.toString().isEmpty(); - } - - public static boolean isStackValid(Object aStack) { - return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0; - } - - public static boolean isStackInvalid(Object aStack) { - return aStack == null || !(aStack instanceof ItemStack) || ((ItemStack) aStack).getItem() == null || ((ItemStack) aStack).stackSize < 0; + public static boolean isStackValid(ItemStack aStack) { + return aStack.getItem() != null && aStack.stackSize >= 0; } public static boolean isDebugItem(ItemStack aStack) { - return /*ItemList.Armor_Cheat.isStackEqual(aStack, T, T) || */areStacksEqual(GT_ModHandler.getIC2Item(ItemName.debug_item, 1), aStack, true); + return areStacksEqual(GT_ModHandler.getIC2Item(ItemName.debug_item, 1), aStack, true); } public static ItemStack updateItemStack(ItemStack aStack) { @@ -1090,49 +1016,6 @@ public class GT_Utility { return negative ? "-" + tString : tString; } - public static NBTTagCompound getNBTContainingBoolean(NBTTagCompound aNBT, Object aTag, boolean aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setBoolean(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingByte(NBTTagCompound aNBT, Object aTag, byte aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setByte(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingShort(NBTTagCompound aNBT, Object aTag, short aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setShort(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingInteger(NBTTagCompound aNBT, Object aTag, int aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setInteger(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingFloat(NBTTagCompound aNBT, Object aTag, float aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setFloat(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingDouble(NBTTagCompound aNBT, Object aTag, double aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - aNBT.setDouble(aTag.toString(), aValue); - return aNBT; - } - - public static NBTTagCompound getNBTContainingString(NBTTagCompound aNBT, Object aTag, Object aValue) { - if (aNBT == null) aNBT = new NBTTagCompound(); - if (aValue == null) return aNBT; - aNBT.setString(aTag.toString(), aValue.toString()); - return aNBT; - } - public static boolean isWearingFullFrostHazmat(EntityLivingBase aEntity) { for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) if (!isStackInList(aEntity.getItemStackFromSlot(i), GregTech_API.sFrostHazmatList)) return false; @@ -1145,6 +1028,7 @@ public class GT_Utility { return true; } + @SuppressWarnings("unused") public static boolean isWearingFullBioHazmat(EntityLivingBase aEntity) { for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) if (!isStackInList(aEntity.getItemStackFromSlot(i), GregTech_API.sBioHazmatList)) return false; @@ -1185,6 +1069,7 @@ public class GT_Utility { return EnchantmentHelper.getEnchantmentLevel(Enchantment_Radioactivity.INSTANCE, aStack); } + @SuppressWarnings("unused") public static boolean isImmuneToBreathingGasses(EntityLivingBase aEntity) { return isWearingFullGasHazmat(aEntity); } @@ -1226,13 +1111,14 @@ public class GT_Utility { return false; } - public static ItemStack setStack(Object aSetStack, Object aToStack) { - if (isStackInvalid(aSetStack) || isStackInvalid(aToStack)) return null; - ((ItemStack) aSetStack).setItem(((ItemStack) aToStack).getItem()); - ((ItemStack) aSetStack).stackSize = ((ItemStack) aToStack).stackSize; - Items.FEATHER.setDamage((ItemStack) aSetStack, Items.FEATHER.getDamage((ItemStack) aToStack)); - ((ItemStack) aSetStack).setTagCompound(((ItemStack) aToStack).getTagCompound()); - return (ItemStack) aSetStack; + @SuppressWarnings("deprecation") + public static ItemStack setStack(ItemStack aSetStack, ItemStack aToStack) { + if (!isStackValid(aSetStack) || !isStackValid(aToStack)) return null; + aSetStack.setItem(aToStack.getItem()); + aSetStack.stackSize = aToStack.stackSize; + Items.FEATHER.setDamage(aSetStack, Items.FEATHER.getDamage(aToStack)); + aSetStack.setTagCompound(aToStack.getTagCompound()); + return aSetStack; } public static FluidStack[] copyFluidArray(FluidStack... aStacks) { @@ -1241,21 +1127,15 @@ public class GT_Utility { return rStacks; } - public static ItemStack[] copyStackArray(Object... aStacks) { - ItemStack[] rStacks = new ItemStack[aStacks.length]; - for (int i = 0; i < aStacks.length; i++) rStacks[i] = copy(aStacks[i]); - return rStacks; - } - - public static ItemStack copy(Object... aStacks) { - for (Object tStack : aStacks) - if (isStackValid(tStack)) return ((ItemStack) tStack).copy(); + public static ItemStack copy(ItemStack... aStacks) { + for (ItemStack tStack : aStacks) + if (isStackValid(tStack)) return tStack.copy(); return null; } - public static ItemStack copyAmount(long aAmount, Object... aStacks) { + public static ItemStack copyAmount(long aAmount, ItemStack... aStacks) { ItemStack rStack = copy(aStacks); - if (isStackInvalid(rStack)) return null; + if (!isStackValid(rStack)) return null; if (aAmount > 64) aAmount = 64; else if (aAmount == -1) aAmount = 111; else if (aAmount < 0) aAmount = 0; @@ -1263,16 +1143,16 @@ public class GT_Utility { return rStack; } - public static ItemStack copyMetaData(long aMetaData, Object... aStacks) { + public static ItemStack copyMetaData(long aMetaData, ItemStack... aStacks) { ItemStack rStack = copy(aStacks); - if (isStackInvalid(rStack)) return null; + if (!isStackValid(rStack)) return null; Items.FEATHER.setDamage(rStack, (short) aMetaData); return rStack; } - public static ItemStack copyAmountAndMetaData(long aAmount, long aMetaData, Object... aStacks) { + public static ItemStack copyAmountAndMetaData(long aAmount, long aMetaData, ItemStack... aStacks) { ItemStack rStack = copyAmount(aAmount, aStacks); - if (isStackInvalid(rStack)) return null; + if (isStackValid(rStack)) return null; Items.FEATHER.setDamage(rStack, (short) aMetaData); return rStack; } @@ -1280,7 +1160,7 @@ public class GT_Utility { /** * returns a copy of an ItemStack with its Stacksize being multiplied by aMultiplier */ - public static ItemStack mul(long aMultiplier, Object... aStacks) { + public static ItemStack mul(long aMultiplier, ItemStack... aStacks) { ItemStack rStack = copy(aStacks); if (rStack == null) return null; rStack.stackSize *= aMultiplier; @@ -1294,10 +1174,6 @@ public class GT_Utility { return loadItem(aNBT.getCompoundTag(aTagName)); } - public static FluidStack loadFluid(NBTTagCompound aNBT, String aTagName) { - return loadFluid(aNBT.getCompoundTag(aTagName)); - } - /** * Loads an ItemStack properly. */ @@ -1307,14 +1183,6 @@ public class GT_Utility { return GT_OreDictUnificator.get(true, rStack); } - /** - * Loads an FluidStack properly. - */ - public static FluidStack loadFluid(NBTTagCompound aNBT) { - if (aNBT == null) return null; - return FluidStack.loadFluidStackFromNBT(aNBT); - } - public static E selectItemInList(int aIndex, E aReplacement, List aList) { if (aList == null || aList.isEmpty()) return aReplacement; if (aList.size() <= aIndex) return aList.get(aList.size() - 1); @@ -1322,13 +1190,6 @@ public class GT_Utility { return aList.get(aIndex); } - public static E selectItemInList(int aIndex, E aReplacement, E... aList) { - if (aList == null || aList.length == 0) return aReplacement; - if (aList.length <= aIndex) return aList[aList.length - 1]; - if (aIndex < 0) return aList[0]; - return aList[aIndex]; - } - public static boolean isStackInList(ItemStack aStack, Collection aList) { if (aStack == null) { return false; @@ -1344,7 +1205,7 @@ public class GT_Utility { * re-maps all Keys of a Map after the Keys were weakened. */ public static Map reMap(Map aMap) { - Map tMap = new HashMap(); + Map tMap = new HashMap<>(); tMap.putAll(aMap); aMap.clear(); aMap.putAll(tMap); @@ -1354,15 +1215,11 @@ public class GT_Utility { /** * Why the fuck do neither Java nor Guava have a Function to do this? */ + @SuppressWarnings("unchecked") public static LinkedHashMap sortMapByValuesAcending(Map aMap) { - List> tEntrySet = new LinkedList>(aMap.entrySet()); - Collections.sort(tEntrySet, new Comparator>() { - @Override - public int compare(Entry aValue1, Entry aValue2) { - return aValue1.getValue().compareTo(aValue2.getValue()); - } - }); - LinkedHashMap rMap = new LinkedHashMap(); + List> tEntrySet = new LinkedList<>(aMap.entrySet()); + tEntrySet.sort((aValue1, aValue2) -> aValue1.getValue().compareTo(aValue2.getValue())); + LinkedHashMap rMap = new LinkedHashMap<>(); for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); return rMap; } @@ -1370,15 +1227,11 @@ public class GT_Utility { /** * Why the fuck do neither Java nor Guava have a Function to do this? */ + @SuppressWarnings({"unchecked", "unused"}) public static LinkedHashMap sortMapByValuesDescending(Map aMap) { - List> tEntrySet = new LinkedList>(aMap.entrySet()); - Collections.sort(tEntrySet, new Comparator>() { - @Override - public int compare(Entry aValue1, Entry aValue2) { - return aValue2.getValue().compareTo(aValue1.getValue());//FB: RV - RV_NEGATING_RESULT_OF_COMPARETO - } - }); - LinkedHashMap rMap = new LinkedHashMap(); + List> tEntrySet = new LinkedList<>(aMap.entrySet()); + tEntrySet.sort((aValue1, aValue2) -> aValue2.getValue().compareTo(aValue1.getValue())); + LinkedHashMap rMap = new LinkedHashMap<>(); for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); return rMap; } @@ -1386,6 +1239,7 @@ public class GT_Utility { /** * Translates a Material Amount into an Amount of Fluid in Fluid Material Units. */ + @SuppressWarnings("unused") public static long translateMaterialToFluidAmount(long aMaterialAmount, boolean aRoundUp) { return translateMaterialToAmount(aMaterialAmount, L, aRoundUp); } @@ -1402,13 +1256,9 @@ public class GT_Utility { * Used for my Teleporter. */ public static boolean isRealDimension(int aDimensionID) { - try { - if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("com.xcompwiz.mystcraft")) - return true; - } catch (Throwable e) {/*Do nothing*/} - try { - if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("TwilightForest")) return true; - } catch (Throwable e) {/*Do nothing*/} + String clazzName = DimensionManager.getProvider(aDimensionID).getClass().getName().toLowerCase(); + if (clazzName.contains("mystcraft") || clazzName.contains("twilightforest") || clazzName.contains("rftools")) + return true; return GregTech_API.sDimensionalList.contains(aDimensionID); } @@ -1418,22 +1268,6 @@ public class GT_Utility { if (aEntity instanceof EntityPlayerMP) { EntityPlayerMP aPlayer = (EntityPlayerMP) aEntity; -// aPlayer.dimension = aDimension; -// aPlayer.connection.sendPacket(new SPacketRespawn(aPlayer.dimension, aPlayer.worldObj.getDifficulty(), aPlayer.worldObj.getWorldInfo().getTerrainType(), aPlayer.interactionManager.getGameType())); -// tOriginalWorld.removeEntityDangerously(aPlayer); -// aPlayer.isDead = false; -// aPlayer.setWorld(tTargetWorld); -// FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().preparePlayer(aPlayer, tOriginalWorld); -// aPlayer.connection.setPlayerLocation(aX + 0.5, aY + 0.5, aZ + 0.5, aPlayer.rotationYaw, aPlayer.rotationPitch); -// aPlayer.interactionManager.setWorld(tTargetWorld); -// FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().updateTimeAndWeatherForPlayer(aPlayer, tTargetWorld); -// FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().syncPlayerInventory(aPlayer); -// Iterator tIterator = aPlayer.getActivePotionEffects().iterator(); -// while (tIterator.hasNext()) { -// PotionEffect potioneffect = (PotionEffect) tIterator.next(); -// aPlayer.connection.sendPacket(new SPacketEntityEffect(aPlayer.getEntityId(), potioneffect)); -// } -// FMLCommonHandler.instance().firePlayerChangedDimensionEvent(aPlayer, tOriginalWorld.provider.getDimension(), aDimension); aPlayer.changeDimension(aDimension); aPlayer.connection.setPlayerLocation(aX + 0.5, aY + 0.5, aZ + 0.5, aPlayer.rotationYaw, aPlayer.rotationPitch); } else { @@ -1474,16 +1308,10 @@ public class GT_Utility { } public static FluidStack getUndergroundOil(World aWorld, int aX, int aZ) { - - Random tRandom = new Random((aWorld.getSeed() + (aX / 96) + (7 * (aZ / 96)))); - int oil = tRandom.nextInt(3); double amount = tRandom.nextInt(50) + tRandom.nextDouble(); - oil = tRandom.nextInt(4); -// System.out.println("Oil: "+(aX/96)+" "+(aZ/96)+" "+oil+" "+amount); -// amount = 40; - Fluid tFluid = null; - switch (oil) { + Fluid tFluid; + switch (tRandom.nextInt(4)) { case 0: tFluid = Materials.NatruralGas.mGas; break; @@ -1500,24 +1328,25 @@ public class GT_Utility { tFluid = Materials.Oil.mFluid; } int tAmount = (int) (Math.pow(amount, 5) / 100); - ChunkPos tPos = new ChunkPos(aX/16, aZ/16); + ChunkPos tPos = new ChunkPos(aX / 16, aZ / 16); int[] tInts = new int[2]; - if(GT_Proxy.chunkData.containsKey(tPos)){ - tInts = GT_Proxy.chunkData.get(tPos); - if(tInts.length>0){ - if(tInts[0]>0){tAmount = tInts[0];} - } - GT_Proxy.chunkData.remove(tPos); - } - tAmount = tAmount - 5; - tInts[0] = tAmount; - GT_Proxy.chunkData.put(tPos, tInts); + if (GT_Proxy.chunkData.containsKey(tPos)) { + tInts = GT_Proxy.chunkData.get(tPos); + if (tInts.length > 0) { + if (tInts[0] > 0) { + tAmount = tInts[0]; + } + } + GT_Proxy.chunkData.remove(tPos); + } + tAmount = tAmount - 5; + tInts[0] = tAmount; + GT_Proxy.chunkData.put(tPos, tInts); return new FluidStack(tFluid, tAmount); } + @SuppressWarnings("deprecation") public static int getCoordinateScan(ArrayList aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, BlockPos blockPos, EnumFacing aSide, float aClickX, float aClickY, float aClickZ) { - if (aList == null) return 0; - ArrayList tList = new ArrayList<>(); int rEUAmount = 0; @@ -1525,206 +1354,149 @@ public class GT_Utility { IBlockState tBlock = aWorld.getBlockState(blockPos); tList.add("----- X: " + blockPos.getX() + " Y: " + blockPos.getY() + " Z: " + blockPos.getZ() + " -----"); - try { - if (tTileEntity instanceof IInventory) - tList.add("Name: " + ((IInventory) tTileEntity).getName() + " MetaData: " + aWorld.getBlockState(blockPos)); - else - tList.add("Name: " + tBlock.getBlock().getUnlocalizedName() + " MetaData: " + tBlock.getBlock().getMetaFromState(tBlock)); - //tList.add("Hardness: " + tBlock.getBlockHardness(aWorld, blockPos) + " Blast Resistance: " + tBlock.getBlock().getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ)); - if (tBlock.getBlock().isBeaconBase(aWorld, blockPos, blockPos.add(0, 1, 0))) tList.add("Is valid Beacon Pyramid Material"); - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } + if (tTileEntity instanceof IInventory) + tList.add("Name: " + ((IInventory) tTileEntity).getName() + " MetaData: " + aWorld.getBlockState(blockPos)); + else + tList.add("Name: " + tBlock.getBlock().getUnlocalizedName() + " MetaData: " + tBlock.getBlock().getMetaFromState(tBlock)); + + tList.add("Hardness: " + tBlock.getBlockHardness(aWorld, blockPos) + " Blast Resistance: " + tBlock.getBlock().getExplosionResistance(aWorld, blockPos, aPlayer, null)); + if (tBlock.getBlock().isBeaconBase(aWorld, blockPos, blockPos.add(0, 1, 0))) + tList.add("Is valid Beacon Pyramid Material"); + if (tTileEntity != null) { - try { - if (tTileEntity instanceof IFluidHandler) { - rEUAmount += 500; - FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(aSide); - if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { - tList.add("Tank " + i + ": " + GT_Utility.formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + " / " + GT_Utility.formatNumbers(tTanks[i].capacity) + " " + getFluidName(tTanks[i].fluid, true)); - } + + if (tTileEntity instanceof IFluidHandler) { + rEUAmount += 500; + FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(aSide); + if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { + tList.add("Tank " + i + ": " + GT_Utility.formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + " / " + GT_Utility.formatNumbers(tTanks[i].capacity) + " " + getFluidName(tTanks[i].fluid, true)); } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactorChamber) { - rEUAmount += 500; - tTileEntity = (TileEntity) (((ic2.api.reactor.IReactorChamber) tTileEntity).getReactorInstance()); + + if (tTileEntity instanceof ic2.api.reactor.IReactorChamber) { + rEUAmount += 500; + tTileEntity = (TileEntity) (((ic2.api.reactor.IReactorChamber) tTileEntity).getReactorInstance()); + } + + + if (tTileEntity instanceof ic2.api.reactor.IReactor) { + rEUAmount += 500; + tList.add("Heat: " + ((ic2.api.reactor.IReactor) tTileEntity).getHeat() + "/" + ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat() + + " HEM: " + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() + " Base EU Output: "/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + } + + if (tTileEntity instanceof ic2.api.tile.IWrenchable) { + rEUAmount += 100; + tList.add("Facing: " + ((ic2.api.tile.IWrenchable) tTileEntity).getFacing(tTileEntity.getWorld(), blockPos)); + tList.add(((ic2.api.tile.IWrenchable) tTileEntity).wrenchCanRemove(tTileEntity.getWorld(), blockPos, aPlayer) ? "You can remove this with a Wrench" : "You can NOT remove this with a Wrench"); + } + + if (tTileEntity instanceof ic2.api.energy.tile.IEnergySink) { + rEUAmount += 400; + aList.add("Demanded Energy: " + ((ic2.api.energy.tile.IEnergySink) tTileEntity).getDemandedEnergy()); + tList.add("Max Safe Input Tier: " + getTier(((ic2.api.energy.tile.IEnergySink) tTileEntity).getSinkTier())); + } + + if (tTileEntity instanceof ic2.api.energy.tile.IEnergySource) { + rEUAmount += 400; + aList.add("Energy Output Tier: " + ((ic2.api.energy.tile.IEnergySource) tTileEntity).getSourceTier()); + } + + if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { + rEUAmount += 200; + tList.add("Conduction Loss: " + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()); + } + + if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { + rEUAmount += 200; + tList.add("Contained Energy: " + ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() + " of " + ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()); + aList.add(((ic2.api.tile.IEnergyStorage) tTileEntity).isTeleporterCompatible(EnumFacing.UP) ? "Teleporter Compatible" : "Not Teleporter Compatible"); + } + + if (tTileEntity instanceof IUpgradableMachine) { + rEUAmount += 500; + if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add("Has Muffler Upgrade"); + } + + if (tTileEntity instanceof IMachineProgress) { + rEUAmount += 400; + int tValue; + if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) + tList.add("Progress: " + GT_Utility.formatNumbers(tValue) + " / " + GT_Utility.formatNumbers(((IMachineProgress) tTileEntity).getProgress())); + } + + if (tTileEntity instanceof ICoverable) { + rEUAmount += 300; + String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSide(aSide).getDescription(aSide, ((ICoverable) tTileEntity).getCoverIDAtSide(aSide), ((ICoverable) tTileEntity).getCoverDataAtSide(aSide), (ICoverable) tTileEntity); + if (tString != null && !tString.equals(E)) tList.add(tString); + } + + if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { + tList.add("Max IN: " + ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " EU"); + tList.add("Max OUT: " + ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes"); + tList.add("Energy: " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + "EU"); + } + + if (tTileEntity instanceof IGregTechTileEntity) { + tList.add("Owned by: " + ((IGregTechTileEntity) tTileEntity).getOwnerId()); + } + + if (tTileEntity instanceof IGregTechDeviceInformation && ((IGregTechDeviceInformation) tTileEntity).isGivingInformation()) { + tList.addAll(Arrays.asList(((IGregTechDeviceInformation) tTileEntity).getInfoData())); + } + + if (tTileEntity instanceof ic2.api.crops.ICropTile) { + ICropTile cropTile = (ICropTile) tTileEntity; + if (cropTile.getScanLevel() < 4) { + rEUAmount += 10000; + cropTile.setScanLevel((byte) 4); } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactor) { - rEUAmount += 500; - tList.add("Heat: " + ((ic2.api.reactor.IReactor) tTileEntity).getHeat() + "/" + ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat() - + " HEM: " + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() + " Base EU Output: "/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + if (cropTile.getCrop() != null) { + rEUAmount += 1000; + CropProperties properties = cropTile.getCrop().getProperties(); + tList.add("Type -- Crop-Name: " + I18n.translateToLocal(cropTile.getCrop().getUnlocalizedName()) + + " Growth: " + cropTile.getCurrentSize() + + " Gain: " + cropTile.getCrop().getGain(cropTile) + + " Resistance: " + properties.getDefensive() + ); + tList.add("Plant -- Fertilizer: " + cropTile.getStorageNutrients() + + " Water: " + cropTile.getStorageWater() + + " Weed-Ex: " + cropTile.getStorageWeedEX() + + " Scan-Level: " + cropTile.getScanLevel() + ); + tList.add("Environment -- Nutrients: " + cropTile.getTerrainNutrients() + + " Humidity: " + cropTile.getTerrainHumidity() + + " Air-Quality: " + cropTile.getTerrainAirQuality() + ); + tList.add("Discovered by: " + cropTile.getCrop().getDiscoveredBy()); } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IWrenchable) { - rEUAmount += 100; - tList.add("Facing: " + ((ic2.api.tile.IWrenchable) tTileEntity).getFacing(tTileEntity.getWorld(), blockPos)); - tList.add(((ic2.api.tile.IWrenchable) tTileEntity).wrenchCanRemove(tTileEntity.getWorld(), blockPos, aPlayer) ? "You can remove this with a Wrench" : "You can NOT remove this with a Wrench"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergyTile) { - rEUAmount += 200; - //aList.add(((ic2.api.energy.tile.IEnergyTile)tTileEntity).isAddedToEnergyNet()?"Added to E-net":"Not added to E-net! Bug?"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergySink) { - rEUAmount += 400; - //aList.add("Demanded Energy: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).demandsEnergy()); - //tList.add("Max Safe Input: " + getTier(((ic2.api.energy.tile.IEnergySink)tTileEntity).getSinkTier())); - //tList.add("Max Safe Input: " + ((ic2.api.energy.tile.IEnergySink)tTileEntity).getMaxSafeInput()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergySource) { - rEUAmount += 400; - //aList.add("Max Energy Output: " + ((ic2.api.energy.tile.IEnergySource)tTileEntity).getMaxEnergyOutput()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { - rEUAmount += 200; - tList.add("Conduction Loss: " + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { - rEUAmount += 200; - tList.add("Contained Energy: " + ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() + " of " + ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()); - //aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IUpgradableMachine) { - rEUAmount += 500; - if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add("Has Muffler Upgrade"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IMachineProgress) { - rEUAmount += 400; - int tValue = 0; - if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) - tList.add("Progress: " + GT_Utility.formatNumbers(tValue) + " / " + GT_Utility.formatNumbers(((IMachineProgress) tTileEntity).getProgress())); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ICoverable) { - rEUAmount += 300; - String tString = ((ICoverable) tTileEntity).getCoverBehaviorAtSide((byte) aSide.getIndex()).getDescription((byte) aSide.getIndex(), ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide.getIndex()), ((ICoverable) tTileEntity).getCoverDataAtSide((byte) aSide.getIndex()), (ICoverable) tTileEntity); - if (tString != null && !tString.equals(E)) tList.add(tString); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add("Max IN: " + ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " EU"); - tList.add("Max OUT: " + ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes"); - tList.add("Energy: " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + "EU"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechTileEntity) { - tList.add("Owned by: " + ((IGregTechTileEntity) tTileEntity).getOwnerName()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechDeviceInformation && ((IGregTechDeviceInformation) tTileEntity).isGivingInformation()) { - tList.addAll(Arrays.asList(((IGregTechDeviceInformation) tTileEntity).getInfoData())); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.crops.ICropTile) { - ICropTile cropTile = (ICropTile) tTileEntity; - if (cropTile.getScanLevel() < 4) { - rEUAmount += 10000; - cropTile.setScanLevel((byte) 4); - } - if (cropTile.getCrop() != null) { - rEUAmount += 1000; - CropProperties properties = cropTile.getCrop().getProperties(); - tList.add("Type -- Crop-Name: " + I18n.translateToLocal(cropTile.getCrop().getUnlocalizedName()) - + " Growth: " + cropTile.getCurrentSize() - + " Gain: " + cropTile.getCrop().getGain(cropTile) - + " Resistance: " + properties.getDefensive() - ); - tList.add("Plant -- Fertilizer: " + cropTile.getStorageNutrients() - + " Water: " + cropTile.getStorageWater() - + " Weed-Ex: " + cropTile.getStorageWeedEX() - + " Scan-Level: " + cropTile.getScanLevel() - ); - tList.add("Environment -- Nutrients: " + cropTile.getTerrainNutrients() - + " Humidity: " + cropTile.getTerrainHumidity() - + " Air-Quality: " + cropTile.getTerrainAirQuality() - ); - tList.add("Discovered by: " + cropTile.getCrop().getDiscoveredBy()); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); } + } - if (aPlayer.capabilities.isCreativeMode&>_Values.D1) { + + if (aPlayer.capabilities.isCreativeMode) { FluidStack tFluid = getUndergroundOil(aWorld, blockPos.getX(), blockPos.getY()); tList.add("Oil in Chunk: " + tFluid.amount + " " + tFluid.getLocalizedName()); } - //if(aPlayer.capabilities.isCreativeMode){ - ChunkPos pos = new ChunkPos(blockPos.getX() / 16, blockPos.getZ() / 16); - if(GT_Proxy.chunkData.containsKey(pos)){ - int[] tPollution = GT_Proxy.chunkData.get(pos); - if(tPollution.length>1){ - tList.add("Pollution in Chunk: "+tPollution[1]); - }else{ - tList.add("No Pollution in Chunk"); - } - } - //} - try { - if (tBlock instanceof IDebugableBlock) { - rEUAmount += 500; - ArrayList temp = ((IDebugableBlock) tBlock).getDebugInfo(aPlayer, blockPos.getX(), blockPos.getY(), blockPos.getZ(), 3); - if (temp != null) tList.addAll(temp); + ChunkPos pos = new ChunkPos(blockPos.getX() / 16, blockPos.getZ() / 16); + if (GT_Proxy.chunkData.containsKey(pos)) { + int[] tPollution = GT_Proxy.chunkData.get(pos); + if (tPollution.length > 1) { + tList.add("Pollution in Chunk: " + tPollution[1]); + } else { + tList.add("No Pollution in Chunk"); } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); } - BlockScanningEvent tEvent = new BlockScanningEvent(aWorld, aPlayer, blockPos.getX(), blockPos.getY(), blockPos.getZ(), (byte) aSide.getIndex(), aScanLevel, tBlock.getBlock(), tTileEntity, tList, aClickX, aClickY, aClickZ); + if (tBlock instanceof IDebugableBlock) { + rEUAmount += 500; + ArrayList temp = ((IDebugableBlock) tBlock).getDebugInfo(aPlayer, blockPos, 3); + if (temp != null) tList.addAll(temp); + } + + BlockScanningEvent tEvent = new BlockScanningEvent(aWorld, aPlayer, blockPos, aSide, aScanLevel, tBlock, tTileEntity, tList, aClickX, aClickY, aClickZ); tEvent.mEUCost = rEUAmount; MinecraftForge.EVENT_BUS.post(tEvent); if (!tEvent.isCanceled()) aList.addAll(tList); @@ -1755,58 +1527,57 @@ public class GT_Utility { /** * This Function determines the direction a Block gets when being Wrenched. - * returns -1 if invalid. Even though that could never happen. */ - public static byte determineWrenchingSide(byte aSide, float aX, float aY, float aZ) { - byte tBack = getOppositeSide(aSide); + public static EnumFacing determineWrenchingSide(EnumFacing aSide, float aX, float aY, float aZ) { + EnumFacing tBack = aSide.getOpposite(); switch (aSide) { - case 0: - case 1: + case DOWN: + case UP: if (aX < 0.25) { if (aZ < 0.25) return tBack; if (aZ > 0.75) return tBack; - return 4; + return EnumFacing.WEST; } if (aX > 0.75) { if (aZ < 0.25) return tBack; if (aZ > 0.75) return tBack; - return 5; + return EnumFacing.EAST; } - if (aZ < 0.25) return 2; - if (aZ > 0.75) return 3; + if (aZ < 0.25) return EnumFacing.NORTH; + if (aZ > 0.75) return EnumFacing.SOUTH; return aSide; - case 2: - case 3: + case NORTH: + case SOUTH: if (aX < 0.25) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 4; + return EnumFacing.WEST; } if (aX > 0.75) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 5; + return EnumFacing.EAST; } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; + if (aY < 0.25) return EnumFacing.DOWN; + if (aY > 0.75) return EnumFacing.UP; return aSide; - case 4: - case 5: + case WEST: + case EAST: if (aZ < 0.25) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 2; + return EnumFacing.NORTH; } if (aZ > 0.75) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 3; + return EnumFacing.SOUTH; } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; + if (aY < 0.25) return EnumFacing.DOWN; + if (aY > 0.75) return EnumFacing.UP; return aSide; } - return -1; + throw new IllegalArgumentException(); } public static String formatNumbers(long aNumber) { @@ -1817,15 +1588,16 @@ public class GT_Utility { } public static class ItemNBT { + public static void setNBT(ItemStack aStack, NBTTagCompound aNBT) { if (aNBT == null) { aStack.setTagCompound(null); return; } - ArrayList tTagsToRemove = new ArrayList(); + ArrayList tTagsToRemove = new ArrayList<>(); for (Object tKey : aNBT.getKeySet()) { NBTBase tValue = aNBT.getTag((String) tKey); - if (tValue == null || (tValue instanceof NBTPrimitive && ((NBTPrimitive) tValue).getInt() == 0) || (tValue instanceof NBTTagString && isStringInvalid(((NBTTagString) tValue).getString()))) + if (tValue == null || (tValue instanceof NBTPrimitive && ((NBTPrimitive) tValue).getInt() == 0) || (tValue instanceof NBTTagString && !isStringValid(((NBTTagString) tValue).getString()))) tTagsToRemove.add((String) tKey); } for (Object tKey : tTagsToRemove) aNBT.removeTag((String) tKey); @@ -1837,6 +1609,7 @@ public class GT_Utility { return rNBT == null ? new NBTTagCompound() : rNBT; } + @SuppressWarnings("unused") public static void setPunchCardData(ItemStack aStack, String aPunchCardData) { NBTTagCompound tNBT = getNBT(aStack); tNBT.setString("GT.PunchCardData", aPunchCardData); @@ -1859,6 +1632,7 @@ public class GT_Utility { return tNBT.getLong("GT.LighterFuel"); } + @SuppressWarnings("unused") public static void setMapID(ItemStack aStack, short aMapID) { NBTTagCompound tNBT = getNBT(aStack); tNBT.setShort("map_id", aMapID); @@ -1882,6 +1656,7 @@ public class GT_Utility { return tNBT.getString("title"); } + @SuppressWarnings("unused") public static void setBookAuthor(ItemStack aStack, String aAuthor) { NBTTagCompound tNBT = getNBT(aStack); tNBT.setString("author", aAuthor); @@ -1893,13 +1668,13 @@ public class GT_Utility { return tNBT.getString("author"); } - public static void setProspectionData(ItemStack aStack, int aX, int aY, int aZ, int aDim, FluidStack aFluid, String[] aOres) { + public static void setProspectionData(ItemStack aStack, BlockPos pos, int aDim, FluidStack aFluid, String[] aOres) { NBTTagCompound tNBT = getNBT(aStack); - String tData = aX + "," + aY + "," + aZ + "," + aDim + "," + (aFluid.amount / 5000) + "," + aFluid.getLocalizedName() + ","; + StringBuilder tData = new StringBuilder(pos.getX() + "," + pos.getY() + "," + pos.getZ() + "," + aDim + "," + (aFluid.amount / 5000) + "," + aFluid.getLocalizedName() + ","); for (String tString : aOres) { - tData += tString + ","; + tData.append(tString).append(","); } - tNBT.setString("prospection", tData); + tNBT.setString("prospection", tData.toString()); setNBT(aStack, tNBT); } @@ -1910,9 +1685,9 @@ public class GT_Utility { if (tDataArray.length > 6) { tNBT.setString("author", "X: " + tDataArray[0] + " Y: " + tDataArray[1] + " Z: " + tDataArray[2] + " Dim: " + tDataArray[3]); NBTTagList tNBTList = new NBTTagList(); - String tOres = " Prospected Ores: "; + StringBuilder tOres = new StringBuilder(" Prospected Ores: "); for (int i = 6; tDataArray.length > i; i++) { - tOres += (tDataArray[i] + " "); + tOres.append(tDataArray[i]).append(" "); } tNBTList.appendTag(new NBTTagString("Prospection Data From: X" + tDataArray[0] + " Z:" + tDataArray[2] + " Dim:" + tDataArray[3] + " Produces " + tDataArray[4] + "L " + tDataArray[5] + " " + tOres)); tNBT.setTag("pages", tNBTList); @@ -1959,39 +1734,24 @@ public class GT_Utility { NBTTagList nbttaglist = aStack.getEnchantmentTagList(); if (nbttaglist != null) { for (int i = 0; i < nbttaglist.tagCount(); ++i) { - try { - short short1 = nbttaglist.getCompoundTagAt(i).getShort("id"); - short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl"); - if (Enchantment.getEnchantmentByID(short1) != null) - aBullshitModifier.calculateModifier(Enchantment.getEnchantmentByID(short1), short2); - } catch (Throwable e) { - // - } + short short1 = nbttaglist.getCompoundTagAt(i).getShort("id"); + short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl"); + if (Enchantment.getEnchantmentByID(short1) != null) + aBullshitModifier.calculateModifier(Enchantment.getEnchantmentByID(short1), short2); } } } } - private static void applyArrayOfBullshit(IBullshit aBullshitModifier, ItemStack[] aStacks) { - ItemStack[] aitemstack1 = aStacks; - int i = aStacks.length; - for (int j = 0; j < i; ++j) { - ItemStack itemstack = aitemstack1[j]; - applyBullshit(aBullshitModifier, itemstack); - } - } - public static void applyBullshitA(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { mBullshitIteratorA.mPlayer = aPlayer; mBullshitIteratorA.mEntity = aEntity; - //if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorA, aPlayer.getLastActiveItems()); if (aStack != null) applyBullshit(mBullshitIteratorA, aStack); } public static void applyBullshitB(EntityLivingBase aPlayer, Entity aEntity, ItemStack aStack) { mBullshitIteratorB.mPlayer = aPlayer; mBullshitIteratorB.mEntity = aEntity; - //if (aPlayer != null) applyArrayOfBullshit(mBullshitIteratorB, aPlayer.last); if (aStack != null) applyBullshit(mBullshitIteratorB, aStack); }