diff options
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_Utility.java')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 98 |
1 files changed, 56 insertions, 42 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 7f423e0c19..dee22c9283 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -26,7 +26,22 @@ import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.util.*; +import java.util.AbstractCollection; +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.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.Supplier; @@ -67,7 +82,12 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; @@ -108,7 +128,14 @@ import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; import gregtech.api.enchants.Enchantment_Hazmat; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.*; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.Textures; +import gregtech.api.enums.ToolDictNames; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IBlockContainer; import gregtech.api.interfaces.IDebugableBlock; @@ -164,7 +191,6 @@ public class GT_Utility { private static final Map<OrePrefixes, Supplier<ItemStack>> sOreToCobble = new HashMap<>(); private static final Map<Integer, Boolean> sOreTable = new HashMap<>(); - public static volatile int VERSION = 509; public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new /* Concurrent */ HashMap<>(); private static int sBookCount = 0; @@ -589,8 +615,6 @@ public class GT_Utility { 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); fromInventory.decrStackSize(aGrabSlot, tMovedItemCount); fromInventory.markDirty(); return tMovedItemCount; @@ -1394,8 +1418,7 @@ public class GT_Utility { public static byte moveOneItemStackIntoSlot(Object fromTileEntity, Object toTileEntity, ForgeDirection fromSide, int putSlot, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (fromTileEntity == null || !(fromTileEntity instanceof IInventory fromInv) - || aMaxTargetStackSize <= 0 + if (!(fromTileEntity instanceof IInventory fromInv) || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize @@ -1695,7 +1718,7 @@ public class GT_Utility { /** * Treat both null list, or both null item stack at same list position as equal. - * + * <p> * Since ItemStack doesn't override equals and hashCode, you cannot just use Objects.equals */ public static boolean areStackListsEqual(List<ItemStack> lhs, List<ItemStack> rhs, boolean ignoreStackSize, @@ -1926,7 +1949,7 @@ public class GT_Utility { .hasContainerItem(aStack)) return aStack.getItem() .getContainerItem(aStack); - /** + /* * These are all special Cases, in which it is intended to have only GT Blocks outputting those Container Items */ if (ItemList.Cell_Empty.isStackEqual(aStack, false, true)) return null; @@ -2075,7 +2098,7 @@ public class GT_Utility { if (isStringInvalid(aMapping)) return null; ItemStack rStack = GregTech_API.sBookList.get(aMapping); if (rStack != null) return copyAmount(1, rStack); - if (isStringInvalid(aTitle) || isStringInvalid(aAuthor) || aPages.length <= 0) return null; + if (isStringInvalid(aTitle) || isStringInvalid(aAuthor) || aPages.length == 0) return null; sBookCount++; rStack = new ItemStack(Items.written_book, 1); NBTTagCompound tNBT = new NBTTagCompound(); @@ -2378,8 +2401,7 @@ public class GT_Utility { } public static boolean isStackInvalid(Object aStack) { - return aStack == null || !(aStack instanceof ItemStack) - || ((ItemStack) aStack).getItem() == null + return !(aStack instanceof ItemStack) || ((ItemStack) aStack).getItem() == null || ((ItemStack) aStack).stackSize < 0; } @@ -2454,7 +2476,7 @@ public class GT_Utility { /** * Initializes new empty texture page for casings page 0 is old CASING_BLOCKS - * + * <p> * Then casings should be registered like this: for (byte i = MIN_USED_META; i < MAX_USED_META; i = (byte) (i + 1)) * { Textures.BlockIcons.casingTexturePages[PAGE][i+START_INDEX] = new GT_CopiedBlockTexture(this, 6, i); } * @@ -3069,8 +3091,7 @@ public class GT_Utility { if (!interDimensional) return false; startWorld.updateEntityWithOptionalForce(entity, false); // added - if ((entity instanceof EntityPlayerMP) && interDimensional) { - EntityPlayerMP player = (EntityPlayerMP) entity; + if (entity instanceof EntityPlayerMP player) { player.closeScreen(); // added player.dimension = aDimension; player.playerNetServerHandler.sendPacket( @@ -3102,40 +3123,34 @@ public class GT_Utility { destinationWorld.theChunkProviderServer.loadChunk((int) aX >> 4, (int) aZ >> 4); destinationWorld.theProfiler.startSection("placing"); - if (interDimensional) { - if (!(entity instanceof EntityPlayer)) { - NBTTagCompound entityNBT = new NBTTagCompound(); - entity.isDead = false; - entityNBT.setString("id", EntityList.getEntityString(entity)); - entity.writeToNBT(entityNBT); - entity.isDead = true; - entity = EntityList.createEntityFromNBT(entityNBT, destinationWorld); - if (entity == null) { - return false; - } - entity.dimension = destinationWorld.provider.dimensionId; + if (!(entity instanceof EntityPlayer)) { + NBTTagCompound entityNBT = new NBTTagCompound(); + entity.isDead = false; + entityNBT.setString("id", EntityList.getEntityString(entity)); + entity.writeToNBT(entityNBT); + entity.isDead = true; + entity = EntityList.createEntityFromNBT(entityNBT, destinationWorld); + if (entity == null) { + return false; } - destinationWorld.spawnEntityInWorld(entity); - entity.setWorld(destinationWorld); + entity.dimension = destinationWorld.provider.dimensionId; } + destinationWorld.spawnEntityInWorld(entity); + entity.setWorld(destinationWorld); entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); destinationWorld.updateEntityWithOptionalForce(entity, false); entity.setLocationAndAngles(aX, aY, aZ, entity.rotationYaw, entity.rotationPitch); - if ((entity instanceof EntityPlayerMP)) { - EntityPlayerMP player = (EntityPlayerMP) entity; - if (interDimensional) { - player.mcServer.getConfigurationManager() - .func_72375_a(player, destinationWorld); - } + if ((entity instanceof EntityPlayerMP player)) { + player.mcServer.getConfigurationManager() + .func_72375_a(player, destinationWorld); player.playerNetServerHandler.setPlayerLocation(aX, aY, aZ, player.rotationYaw, player.rotationPitch); } destinationWorld.updateEntityWithOptionalForce(entity, false); - if (((entity instanceof EntityPlayerMP)) && interDimensional) { - EntityPlayerMP player = (EntityPlayerMP) entity; + if (entity instanceof EntityPlayerMP player) { player.theItemInWorldManager.setWorld(destinationWorld); player.mcServer.getConfigurationManager() .updateTimeAndWeatherForPlayer(player, destinationWorld); @@ -3667,6 +3682,7 @@ public class GT_Utility { * @return an Array containing the X and the Y Coordinate of the clicked Point, with the top left Corner as Origin, * like on the Texture Sheet. return values should always be between [0.0F and 0.99F]. */ + // TODO: use clamp() public static float[] getClickedFacingCoords(ForgeDirection side, float aX, float aY, float aZ) { return switch (side) { case DOWN -> new float[] { Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, aZ)) }; @@ -4194,10 +4210,7 @@ public class GT_Utility { } 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]; + for (ItemStack itemstack : aStacks) { applyBullshit(aBullshitModifier, itemstack); } } @@ -4634,6 +4647,7 @@ public class GT_Utility { size = sum; } + @Nonnull @Override public Iterator<E> iterator() { return colls.stream() |