From 3af191de5ceabc91ae1d8dd386c77cfc63ac7bd4 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 25 Sep 2024 13:35:08 -0400 Subject: [PATCH 1/5] cleaned up throwable try catches --- src/main/java/bartworks/util/BWUtil.java | 321 +++++------ src/main/java/gregtech/GTMod.java | 22 +- .../java/gregtech/api/items/MetaBaseItem.java | 9 +- .../metatileentity/BaseMetaPipeEntity.java | 151 +++-- .../MTEBasicMachineBronze.java | 28 +- .../implementations/MTEFluid.java | 53 +- .../gregtech/api/threads/RunnableSound.java | 3 +- src/main/java/gregtech/api/util/GTConfig.java | 6 +- .../gregtech/api/util/GTForestryCompat.java | 80 ++- .../java/gregtech/api/util/GTModHandler.java | 539 ++++++++---------- .../java/gregtech/api/util/GTUtility.java | 39 +- src/main/java/gregtech/common/GTProxy.java | 61 +- .../gregtech/common/blocks/ItemMachines.java | 2 + .../common/items/ItemIntegratedCircuit.java | 9 +- .../items/behaviors/BehaviourWrench.java | 5 +- .../tileentities/boilers/MTEBoiler.java | 7 +- .../machines/basic/MTEScanner.java | 40 +- .../core/block/machine/BlockPooCollector.java | 24 - .../core/handler/CompatHandler.java | 43 +- .../gtPlusPlus/core/material/Material.java | 2 +- .../loaders/RecipeGenDustGeneration.java | 72 +-- .../gregtech/loaders/RecipeGenRecycling.java | 50 +- src/main/java/tectech/loader/MainLoader.java | 6 +- 23 files changed, 694 insertions(+), 878 deletions(-) diff --git a/src/main/java/bartworks/util/BWUtil.java b/src/main/java/bartworks/util/BWUtil.java index ad75eb275e8..92251c9163c 100644 --- a/src/main/java/bartworks/util/BWUtil.java +++ b/src/main/java/bartworks/util/BWUtil.java @@ -410,181 +410,176 @@ public static ShapedOreRecipe createGTCraftingRecipe(ItemStack aResult, Enchantm } } - try { - StringBuilder shape = new StringBuilder(E); - int idx = 0; - if (aRecipe[idx] instanceof Boolean) { - throw new IllegalArgumentException(); - } + StringBuilder shape = new StringBuilder(E); + int idx = 0; + if (aRecipe[idx] instanceof Boolean) { + throw new IllegalArgumentException(); + } - ArrayList tRecipeList = new ArrayList<>(Arrays.asList(aRecipe)); - - while (aRecipe[idx] instanceof String string) { - StringBuilder s = new StringBuilder(string); - idx++; - shape.append(s); - while (s.length() < 3) s.append(" "); - if (s.length() > 3) throw new IllegalArgumentException(); - - for (char c : s.toString() - .toCharArray()) { - switch (c) { - case 'b': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolBlade.name()); - break; - case 'c': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolCrowbar.name()); - break; - case 'd': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolScrewdriver.name()); - break; - case 'f': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolFile.name()); - break; - case 'h': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolHardHammer.name()); - break; - case 'i': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSolderingIron.name()); - break; - case 'j': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSolderingMetal.name()); - break; - case 'k': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolKnife.name()); - break; - case 'm': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolMortar.name()); - break; - case 'p': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolDrawplate.name()); - break; - case 'r': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSoftHammer.name()); - break; - case 's': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSaw.name()); - break; - case 'w': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolWrench.name()); - break; - case 'x': - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolWireCutter.name()); - break; - } + ArrayList tRecipeList = new ArrayList<>(Arrays.asList(aRecipe)); + + while (aRecipe[idx] instanceof String string) { + StringBuilder s = new StringBuilder(string); + idx++; + shape.append(s); + while (s.length() < 3) s.append(" "); + if (s.length() > 3) throw new IllegalArgumentException(); + + for (char c : s.toString() + .toCharArray()) { + switch (c) { + case 'b': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolBlade.name()); + break; + case 'c': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolCrowbar.name()); + break; + case 'd': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolScrewdriver.name()); + break; + case 'f': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolFile.name()); + break; + case 'h': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolHardHammer.name()); + break; + case 'i': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSolderingIron.name()); + break; + case 'j': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSolderingMetal.name()); + break; + case 'k': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolKnife.name()); + break; + case 'm': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolMortar.name()); + break; + case 'p': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolDrawplate.name()); + break; + case 'r': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSoftHammer.name()); + break; + case 's': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSaw.name()); + break; + case 'w': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolWrench.name()); + break; + case 'x': + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolWireCutter.name()); + break; } } + } - aRecipe = tRecipeList.toArray(); + aRecipe = tRecipeList.toArray(); - if (aRecipe[idx] instanceof Boolean) { - idx++; - } - Map tItemStackMap = new HashMap<>(); - Map tItemDataMap = new HashMap<>(); - tItemStackMap.put(' ', null); - - boolean tRemoveRecipe = true; - - for (; idx < aRecipe.length; idx += 2) { - if (aRecipe[idx] == null || aRecipe[idx + 1] == null) { - if (D1) { - GTLog.err.println( - "WARNING: Missing Item for shaped Recipe: " - + (aResult == null ? "null" : aResult.getDisplayName())); - for (Object tContent : aRecipe) GTLog.err.println(tContent); - } - return null; + if (aRecipe[idx] instanceof Boolean) { + idx++; + } + Map tItemStackMap = new HashMap<>(); + Map tItemDataMap = new HashMap<>(); + tItemStackMap.put(' ', null); + + boolean tRemoveRecipe = true; + + for (; idx < aRecipe.length; idx += 2) { + if (aRecipe[idx] == null || aRecipe[idx + 1] == null) { + if (D1) { + GTLog.err.println( + "WARNING: Missing Item for shaped Recipe: " + + (aResult == null ? "null" : aResult.getDisplayName())); + for (Object tContent : aRecipe) GTLog.err.println(tContent); } - Character chr = (Character) aRecipe[idx]; - Object in = aRecipe[idx + 1]; - if (in instanceof ItemStack) { - tItemStackMap.put(chr, GTUtility.copy(in)); - tItemDataMap.put(chr, GTOreDictUnificator.getItemData((ItemStack) in)); - } else if (in instanceof ItemData) { - String tString = in.toString(); - switch (tString) { - case "plankWood": - tItemDataMap.put(chr, new ItemData(Materials.Wood, M)); - break; - case "stoneNetherrack": - tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M)); - break; - case "stoneObsidian": - tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M)); - break; - case "stoneEndstone": - tItemDataMap.put(chr, new ItemData(Materials.Endstone, M)); - break; - default: - tItemDataMap.put(chr, (ItemData) in); - break; - } - ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); - if (tStack == null) tRemoveRecipe = false; - else tItemStackMap.put(chr, tStack); - aRecipe[idx + 1] = in.toString(); - } else if (in instanceof String) { - if (in.equals(OreDictNames.craftingChest.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8)); - else if (in.equals(OreDictNames.craftingBook.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3)); - else if (in.equals(OreDictNames.craftingPiston.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3)); - else if (in.equals(OreDictNames.craftingFurnace.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8)); - else if (in.equals(OreDictNames.craftingIndustrialDiamond.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Diamond, M)); - else if (in.equals(OreDictNames.craftingAnvil.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10)); - ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); - if (tStack == null) tRemoveRecipe = false; - else tItemStackMap.put(chr, tStack); - } else { - throw new IllegalArgumentException(); + return null; + } + Character chr = (Character) aRecipe[idx]; + Object in = aRecipe[idx + 1]; + if (in instanceof ItemStack) { + tItemStackMap.put(chr, GTUtility.copy(in)); + tItemDataMap.put(chr, GTOreDictUnificator.getItemData((ItemStack) in)); + } else if (in instanceof ItemData) { + String tString = in.toString(); + switch (tString) { + case "plankWood": + tItemDataMap.put(chr, new ItemData(Materials.Wood, M)); + break; + case "stoneNetherrack": + tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M)); + break; + case "stoneObsidian": + tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M)); + break; + case "stoneEndstone": + tItemDataMap.put(chr, new ItemData(Materials.Endstone, M)); + break; + default: + tItemDataMap.put(chr, (ItemData) in); + break; } + ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = false; + else tItemStackMap.put(chr, tStack); + aRecipe[idx + 1] = in.toString(); + } else if (in instanceof String) { + if (in.equals(OreDictNames.craftingChest.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8)); + else if (in.equals(OreDictNames.craftingBook.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3)); + else if (in.equals(OreDictNames.craftingPiston.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3)); + else if (in.equals(OreDictNames.craftingFurnace.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8)); + else if (in.equals(OreDictNames.craftingIndustrialDiamond.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Diamond, M)); + else if (in.equals(OreDictNames.craftingAnvil.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10)); + ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = false; + else tItemStackMap.put(chr, tStack); + } else { + throw new IllegalArgumentException(); } + } - if (aReversible && aResult != null) { - ItemData[] tData = new ItemData[9]; - int x = -1; - for (char chr : shape.toString() - .toCharArray()) { - x++; - tData[x] = tItemDataMap.get(chr); - } - if (GTUtility.arrayContainsNonNull(tData)) - GTOreDictUnificator.addItemData(aResult, new ItemData(tData)); + if (aReversible && aResult != null) { + ItemData[] tData = new ItemData[9]; + int x = -1; + for (char chr : shape.toString() + .toCharArray()) { + x++; + tData[x] = tItemDataMap.get(chr); } + if (GTUtility.arrayContainsNonNull(tData)) GTOreDictUnificator.addItemData(aResult, new ItemData(tData)); + } - if (aCheckForCollisions && tRemoveRecipe) { - ItemStack[] tRecipe = new ItemStack[9]; - int x = -1; - for (char chr : shape.toString() - .toCharArray()) { - x++; - tRecipe[x] = tItemStackMap.get(chr); - if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W) - Items.feather.setDamage(tRecipe[x], 0); - } - tThereWasARecipe = GTModHandler.removeRecipe(tRecipe) != null; + if (aCheckForCollisions && tRemoveRecipe) { + ItemStack[] tRecipe = new ItemStack[9]; + int x = -1; + for (char chr : shape.toString() + .toCharArray()) { + x++; + tRecipe[x] = tItemStackMap.get(chr); + if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W) + Items.feather.setDamage(tRecipe[x], 0); } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); + tThereWasARecipe = GTModHandler.removeRecipe(tRecipe) != null; } if (aResult == null || aResult.stackSize <= 0) return null; diff --git a/src/main/java/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index 9861d35fcfb..2a67bb4a6c0 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -260,7 +260,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPreload", e); } } @@ -321,7 +321,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPreload", e); } } @@ -340,7 +340,7 @@ public void onLoad(FMLInitializationEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTLoad", e); } } @@ -392,7 +392,7 @@ public boolean test(ItemStack stack) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sAfterGTLoad", e); } } } @@ -408,7 +408,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPostload", e); } } @@ -563,7 +563,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPostload", e); } } GTPostLoad.addFakeRecipes(); @@ -600,7 +600,7 @@ public void onLoadComplete(FMLLoadCompleteEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sGTCompleteLoad", e); } } GregTechAPI.sGTCompleteLoad = null; @@ -624,7 +624,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstart", e); } } @@ -759,7 +759,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstart", e); } } @@ -817,7 +817,7 @@ public void onServerStopping(FMLServerStoppingEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstop", e); } } @@ -827,7 +827,7 @@ public void onServerStopping(FMLServerStoppingEvent aEvent) { try { tRunnable.run(); } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstop", e); } } // Interrupt IDLE Threads to close down cleanly diff --git a/src/main/java/gregtech/api/items/MetaBaseItem.java b/src/main/java/gregtech/api/items/MetaBaseItem.java index fa47043fcc3..74c8847612c 100644 --- a/src/main/java/gregtech/api/items/MetaBaseItem.java +++ b/src/main/java/gregtech/api/items/MetaBaseItem.java @@ -26,6 +26,7 @@ import com.gtnewhorizons.modularui.api.KeyboardUtil; +import gregtech.GTMod; import gregtech.api.enums.SubTag; import gregtech.api.interfaces.IItemBehaviour; import gregtech.api.util.GTLanguageManager; @@ -145,7 +146,7 @@ public boolean onLeftClickEntity(ItemStack aStack, EntityPlayer aPlayer, Entity return false; } } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + GTMod.GT_FML_LOGGER.error("Error left clicking entity", e); } return false; } @@ -167,7 +168,7 @@ public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, i return false; } } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + GTMod.GT_FML_LOGGER.error("Error using item", e); } return false; } @@ -199,7 +200,7 @@ public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWor return false; } } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + GTMod.GT_FML_LOGGER.error("Error using item", e); } return false; } @@ -213,7 +214,7 @@ public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer a if (tList != null) for (IItemBehaviour tBehavior : tList) aStack = tBehavior.onItemRightClick(this, aStack, aWorld, aPlayer); } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + GTMod.GT_FML_LOGGER.error("Error right clicking item", e); } return aStack; } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 30a1561f203..1e5a1842118 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -41,7 +41,6 @@ import gregtech.api.net.GTPacketTileEntity; import gregtech.api.objects.GTItemStack; import gregtech.api.util.CoverBehaviorBase; -import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; @@ -175,96 +174,92 @@ public void updateEntity() { } else { tTime = 0; } - try { - if (hasValidMetaTileEntity()) { - if (mTickTimer++ == 0) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - if (isServerSide()) checkDropCover(); - else { - requestCoverDataIfNeeded(); - } - worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); - mMetaTileEntity.onFirstTick(this); - if (!hasValidMetaTileEntity()) return; + + if (hasValidMetaTileEntity()) { + if (mTickTimer++ == 0) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + if (isServerSide()) checkDropCover(); + else { + requestCoverDataIfNeeded(); } + worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); + mMetaTileEntity.onFirstTick(this); + if (!hasValidMetaTileEntity()) return; + } - if (isClientSide()) { - if (mColor != oColor) { - mMetaTileEntity.onColorChangeClient(oColor = mColor); - issueTextureUpdate(); - } + if (isClientSide()) { + if (mColor != oColor) { + mMetaTileEntity.onColorChangeClient(oColor = mColor); + issueTextureUpdate(); + } - if (mNeedsUpdate) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - mNeedsUpdate = false; - } + if (mNeedsUpdate) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + mNeedsUpdate = false; } - if (isServerSide() && mTickTimer > 10) { - if (!doCoverThings()) return; - - final byte oldConnections = mConnections; - // Mask-out connection direction bits to keep only Foam related connections - mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); - // If foam not hardened, tries roll chance to harden - if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM - && getRandomNumber(1000) == 0) { - mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) - | IConnectable.HAS_HARDENEDFOAM); - } - if (mTickTimer > 12 && oldConnections != mConnections) - GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord); + } + if (isServerSide() && mTickTimer > 10) { + if (!doCoverThings()) return; + + final byte oldConnections = mConnections; + // Mask-out connection direction bits to keep only Foam related connections + mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); + // If foam not hardened, tries roll chance to harden + if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM + && getRandomNumber(1000) == 0) { + mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) + | IConnectable.HAS_HARDENEDFOAM); + } + if (mTickTimer > 12 && oldConnections != mConnections) + GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord); + } + mMetaTileEntity.onPreTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + if (isServerSide()) { + if (mTickTimer == 10) { + updateCoverBehavior(); + issueBlockUpdate(); + joinEnet(); } - mMetaTileEntity.onPreTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - if (isServerSide()) { - if (mTickTimer == 10) { - updateCoverBehavior(); - issueBlockUpdate(); - joinEnet(); - } - if (xCoord != oX || yCoord != oY || zCoord != oZ) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - issueClientUpdate(); - clearTileEntityBuffer(); - } + if (xCoord != oX || yCoord != oY || zCoord != oZ) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + issueClientUpdate(); + clearTileEntityBuffer(); } + } - mMetaTileEntity.onPostTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; + mMetaTileEntity.onPostTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; - if (isServerSide()) { - if (mTickTimer % 10 == 0) { - sendClientData(); - } + if (isServerSide()) { + if (mTickTimer % 10 == 0) { + sendClientData(); + } - if (mTickTimer > 10) { - if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); - byte tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); - if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); - tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) - | ((mSidedRedstone[2] > 0) ? 4 : 0) - | ((mSidedRedstone[3] > 0) ? 8 : 0) - | ((mSidedRedstone[4] > 0) ? 16 : 0) - | ((mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); - } + if (mTickTimer > 10) { + if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); + byte tData = mMetaTileEntity.getUpdateData(); + if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); + if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); + tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) + | ((mSidedRedstone[2] > 0) ? 4 : 0) + | ((mSidedRedstone[3] > 0) ? 8 : 0) + | ((mSidedRedstone[4] > 0) ? 16 : 0) + | ((mSidedRedstone[5] > 0) ? 32 : 0)); + if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); + } - if (mNeedsBlockUpdate) { - updateNeighbours(mStrongRedstone, oStrongRedstone); - oStrongRedstone = mStrongRedstone; - mNeedsBlockUpdate = false; - } + if (mNeedsBlockUpdate) { + updateNeighbours(mStrongRedstone, oStrongRedstone); + oStrongRedstone = mStrongRedstone; + mNeedsBlockUpdate = false; } } - } catch (Throwable e) { - e.printStackTrace(); - e.printStackTrace(GTLog.err); } if (isServerSide() && hasTimeStatisticsStarted && hasValidMetaTileEntity()) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEBasicMachineBronze.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEBasicMachineBronze.java index 2ede5545d12..a14a273d62a 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEBasicMachineBronze.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEBasicMachineBronze.java @@ -1,6 +1,5 @@ package gregtech.api.metatileentity.implementations; -import static gregtech.api.enums.GTValues.D1; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP; @@ -38,7 +37,6 @@ import gregtech.api.objects.overclockdescriber.OverclockDescriber; import gregtech.api.objects.overclockdescriber.SteamOverclockDescriber; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTLog; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; @@ -167,21 +165,17 @@ && getBaseMetaTileEntity().getCoverIDAtSide(getBaseMetaTileEntity().getFrontFaci getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1))) { sendSound((byte) 9); mNeedsSteamVenting = false; - try { - for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1), - getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1), - getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1), - getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 1, - getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 1, - getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 1))) { - GTUtility.applyHeatDamage(tLiving, getSteamDamage()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1), + getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1), + getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1), + getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 1, + getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 1, + getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 1))) { + GTUtility.applyHeatDamage(tLiving, getSteamDamage()); } } return !mNeedsSteamVenting; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEFluid.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEFluid.java index 2613aa23c01..e84d1e7c797 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEFluid.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEFluid.java @@ -1,7 +1,6 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GTValues.ALL_VALID_SIDES; -import static gregtech.api.enums.GTValues.D1; import static gregtech.api.enums.Mods.TinkerConstruct; import static gregtech.api.enums.Mods.Translocator; import static gregtech.api.metatileentity.implementations.MTEFluid.Border.BOTTOM; @@ -358,38 +357,30 @@ private boolean checkEnvironment(int index, IGregTechTileEntity aBaseMetaTileEnt tFluid.amount -= 5; sendSound((byte) 9); if (tTemperature > 320) { - try { - for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getXCoord() - 2, - getBaseMetaTileEntity().getYCoord() - 2, - getBaseMetaTileEntity().getZCoord() - 2, - getBaseMetaTileEntity().getXCoord() + 3, - getBaseMetaTileEntity().getYCoord() + 3, - getBaseMetaTileEntity().getZCoord() + 3))) { - GTUtility.applyHeatDamage(tLiving, (tTemperature - 300) / 25.0F); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getXCoord() - 2, + getBaseMetaTileEntity().getYCoord() - 2, + getBaseMetaTileEntity().getZCoord() - 2, + getBaseMetaTileEntity().getXCoord() + 3, + getBaseMetaTileEntity().getYCoord() + 3, + getBaseMetaTileEntity().getZCoord() + 3))) { + GTUtility.applyHeatDamage(tLiving, (tTemperature - 300) / 25.0F); } } else if (tTemperature < 260) { - try { - for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getXCoord() - 2, - getBaseMetaTileEntity().getYCoord() - 2, - getBaseMetaTileEntity().getZCoord() - 2, - getBaseMetaTileEntity().getXCoord() + 3, - getBaseMetaTileEntity().getYCoord() + 3, - getBaseMetaTileEntity().getZCoord() + 3))) { - GTUtility.applyFrostDamage(tLiving, (270 - tTemperature) / 12.5F); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getXCoord() - 2, + getBaseMetaTileEntity().getYCoord() - 2, + getBaseMetaTileEntity().getZCoord() - 2, + getBaseMetaTileEntity().getXCoord() + 3, + getBaseMetaTileEntity().getYCoord() + 3, + getBaseMetaTileEntity().getZCoord() + 3))) { + GTUtility.applyFrostDamage(tLiving, (270 - tTemperature) / 12.5F); } } } diff --git a/src/main/java/gregtech/api/threads/RunnableSound.java b/src/main/java/gregtech/api/threads/RunnableSound.java index 30704f2a974..e51490321ee 100644 --- a/src/main/java/gregtech/api/threads/RunnableSound.java +++ b/src/main/java/gregtech/api/threads/RunnableSound.java @@ -3,6 +3,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import gregtech.GTMod; import gregtech.api.util.GTPlayedSound; import gregtech.api.util.GTUtility; @@ -35,7 +36,7 @@ public void run() { mWorld.playSound(mX, mY, mZ, mSoundResourceLocation.toString(), mSoundStrength, mSoundModulation, false); GTUtility.sPlayedSoundMap.put(tSound, mTimeUntilNextSound); } catch (Throwable e) { - /**/ + GTMod.GT_FML_LOGGER.error("Could not play RunnableSound", e); } } } diff --git a/src/main/java/gregtech/api/util/GTConfig.java b/src/main/java/gregtech/api/util/GTConfig.java index 68ff810414c..a2e2969b51e 100644 --- a/src/main/java/gregtech/api/util/GTConfig.java +++ b/src/main/java/gregtech/api/util/GTConfig.java @@ -48,11 +48,7 @@ public static String getStackConfigName(ItemStack aStack) { if (GTUtility.isStackInvalid(aStack)) return E; Object rName = GTOreDictUnificator.getAssociation(aStack); if (rName != null) return rName.toString(); - try { - if (GTUtility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString(); - } catch (Throwable e) { - /* Do nothing */ - } + if (GTUtility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString(); String sName = aStack.getItem() .toString(); String[] tmp = sName.split("@"); diff --git a/src/main/java/gregtech/api/util/GTForestryCompat.java b/src/main/java/gregtech/api/util/GTForestryCompat.java index ca61c955c7e..7cec9ede4e9 100644 --- a/src/main/java/gregtech/api/util/GTForestryCompat.java +++ b/src/main/java/gregtech/api/util/GTForestryCompat.java @@ -134,59 +134,47 @@ public static void populateFakeNeiRecipes() { public static void transferCentrifugeRecipes() { ItemStack irradiatedComb = GTModHandler.getModItem(Mods.Forestry.ID, "beeCombs", 1, 9); - try { - for (ICentrifugeRecipe tRecipe : RecipeManagers.centrifugeManager.recipes()) { - ItemStack input = tRecipe.getInput(); + for (ICentrifugeRecipe tRecipe : RecipeManagers.centrifugeManager.recipes()) { + ItemStack input = tRecipe.getInput(); - // Don't transfer GT recipes to centrifuge, those recipes are made already by ItemComb - if (input.getUnlocalizedName() - .contains("gt.comb")) continue; - if (irradiatedComb != null && input.isItemEqual(irradiatedComb)) continue; - Map outputs = tRecipe.getAllProducts(); - ItemStack[] tOutputs = new ItemStack[outputs.size()]; - int[] tChances = new int[outputs.size()]; - int i = 0; - for (Map.Entry entry : outputs.entrySet()) { - tChances[i] = (int) (entry.getValue() * 10000); - tOutputs[i] = entry.getKey() - .copy(); - i++; - } - GTValues.RA.stdBuilder() - .itemInputs(tRecipe.getInput()) - .itemOutputs(tOutputs) - .outputChances(tChances) - .duration(6 * SECONDS + 8 * TICKS) - .eut(5) - .addTo(centrifugeRecipes); - } - } catch (Throwable e) { - if (GTValues.D1) { - e.printStackTrace(GTLog.err); + // Don't transfer GT recipes to centrifuge, those recipes are made already by ItemComb + if (input.getUnlocalizedName() + .contains("gt.comb")) continue; + if (irradiatedComb != null && input.isItemEqual(irradiatedComb)) continue; + Map outputs = tRecipe.getAllProducts(); + ItemStack[] tOutputs = new ItemStack[outputs.size()]; + int[] tChances = new int[outputs.size()]; + int i = 0; + for (Map.Entry entry : outputs.entrySet()) { + tChances[i] = (int) (entry.getValue() * 10000); + tOutputs[i] = entry.getKey() + .copy(); + i++; } + GTValues.RA.stdBuilder() + .itemInputs(tRecipe.getInput()) + .itemOutputs(tOutputs) + .outputChances(tChances) + .duration(6 * SECONDS + 8 * TICKS) + .eut(5) + .addTo(centrifugeRecipes); } } public static void transferSqueezerRecipes() { - try { - for (ISqueezerRecipe tRecipe : RecipeManagers.squeezerManager.recipes()) { - if ((tRecipe.getResources().length == 1) && (tRecipe.getFluidOutput() != null) - && (tRecipe.getResources()[0] != null)) { - GTRecipeBuilder recipeBuilder = GTValues.RA.stdBuilder(); - recipeBuilder.itemInputs(tRecipe.getResources()[0]); - if (tRecipe.getRemnants() != null) { - recipeBuilder.itemOutputs(tRecipe.getRemnants()) - .outputChances((int) (tRecipe.getRemnantsChance() * 10000)); - } - recipeBuilder.fluidOutputs(tRecipe.getFluidOutput()) - .duration(1 * SECONDS + 12 * TICKS) - .eut(8) - .addTo(RecipeMaps.fluidExtractionRecipes); + for (ISqueezerRecipe tRecipe : RecipeManagers.squeezerManager.recipes()) { + if ((tRecipe.getResources().length == 1) && (tRecipe.getFluidOutput() != null) + && (tRecipe.getResources()[0] != null)) { + GTRecipeBuilder recipeBuilder = GTValues.RA.stdBuilder(); + recipeBuilder.itemInputs(tRecipe.getResources()[0]); + if (tRecipe.getRemnants() != null) { + recipeBuilder.itemOutputs(tRecipe.getRemnants()) + .outputChances((int) (tRecipe.getRemnantsChance() * 10000)); } - } - } catch (Throwable e) { - if (GTValues.D1) { - e.printStackTrace(GTLog.err); + recipeBuilder.fluidOutputs(tRecipe.getFluidOutput()) + .duration(1 * SECONDS + 12 * TICKS) + .eut(8) + .addTo(RecipeMaps.fluidExtractionRecipes); } } } diff --git a/src/main/java/gregtech/api/util/GTModHandler.java b/src/main/java/gregtech/api/util/GTModHandler.java index 009cde64760..8879f058d97 100644 --- a/src/main/java/gregtech/api/util/GTModHandler.java +++ b/src/main/java/gregtech/api/util/GTModHandler.java @@ -336,12 +336,10 @@ public static int getFuelValue(ItemStack aStack) { public static ItemStack getIC2Item(String aItem, long aAmount, ItemStack aReplacement) { if (GTUtility.isStringInvalid(aItem) || !GregTechAPI.sPreloadStarted) return null; // if (D1) GTLog.out.println("Requested the Item '" + aItem + "' from the IC2-API"); - if (!sIC2ItemMap.containsKey(aItem)) try { + if (!sIC2ItemMap.containsKey(aItem)) { ItemStack tStack = IC2Items.getItem(aItem); sIC2ItemMap.put(aItem, tStack); if (tStack == null && D1) GTLog.err.println(aItem + " is not found in the IC2 Items!"); - } catch (Throwable e) { - /* Do nothing */ } return GTUtility.copyAmount(aAmount, sIC2ItemMap.get(aItem), aReplacement); } @@ -1053,167 +1051,162 @@ else if (!(aRecipe[i] == null || aRecipe[i] instanceof ItemStack || aRecipe[i] instanceof Character)) aRecipe[i] = aRecipe[i].toString(); } - try { - StringBuilder shape = new StringBuilder(E); - int idx = 0; - if (aRecipe[idx] instanceof Boolean) { - throw new IllegalArgumentException(); - } + StringBuilder shape = new StringBuilder(E); + int idx = 0; + if (aRecipe[idx] instanceof Boolean) { + throw new IllegalArgumentException(); + } - ArrayList tRecipeList = new ArrayList<>(Arrays.asList(aRecipe)); + ArrayList tRecipeList = new ArrayList<>(Arrays.asList(aRecipe)); - while (aRecipe[idx] instanceof String) { - StringBuilder s = new StringBuilder((String) aRecipe[idx++]); - shape.append(s); - while (s.length() < 3) s.append(" "); - if (s.length() > 3) throw new IllegalArgumentException(); + while (aRecipe[idx] instanceof String) { + StringBuilder s = new StringBuilder((String) aRecipe[idx++]); + shape.append(s); + while (s.length() < 3) s.append(" "); + if (s.length() > 3) throw new IllegalArgumentException(); - for (char c : s.toString() - .toCharArray()) { - switch (c) { - case 'b' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolBlade.name()); - } - case 'c' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolCrowbar.name()); - } - case 'd' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolScrewdriver.name()); - } - case 'f' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolFile.name()); - } - case 'h' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolHardHammer.name()); - } - case 'i' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSolderingIron.name()); - } - case 'j' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSolderingMetal.name()); - } - case 'k' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolKnife.name()); - } - case 'm' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolMortar.name()); - } - case 'p' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolDrawplate.name()); - } - case 'r' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSoftHammer.name()); - } - case 's' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolSaw.name()); - } - case 'w' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolWrench.name()); - } - case 'x' -> { - tRecipeList.add(c); - tRecipeList.add(ToolDictNames.craftingToolWireCutter.name()); - } + for (char c : s.toString() + .toCharArray()) { + switch (c) { + case 'b' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolBlade.name()); + } + case 'c' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolCrowbar.name()); + } + case 'd' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolScrewdriver.name()); + } + case 'f' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolFile.name()); + } + case 'h' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolHardHammer.name()); + } + case 'i' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSolderingIron.name()); + } + case 'j' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSolderingMetal.name()); + } + case 'k' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolKnife.name()); + } + case 'm' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolMortar.name()); + } + case 'p' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolDrawplate.name()); + } + case 'r' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSoftHammer.name()); + } + case 's' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolSaw.name()); + } + case 'w' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolWrench.name()); + } + case 'x' -> { + tRecipeList.add(c); + tRecipeList.add(ToolDictNames.craftingToolWireCutter.name()); } } } + } - aRecipe = tRecipeList.toArray(); + aRecipe = tRecipeList.toArray(); - if (aRecipe[idx] instanceof Boolean) { - idx++; - } - Map tItemStackMap = new HashMap<>(); - Map tItemDataMap = new HashMap<>(); - tItemStackMap.put(' ', null); - - boolean tRemoveRecipe = true; - - for (; idx < aRecipe.length; idx += 2) { - if (aRecipe[idx] == null || aRecipe[idx + 1] == null) { - if (D1) { - GTLog.err.println( - "WARNING: Missing Item for shaped Recipe: " - + (aResult == null ? "null" : aResult.getDisplayName())); - for (Object tContent : aRecipe) GTLog.err.println(tContent); - } - return false; + if (aRecipe[idx] instanceof Boolean) { + idx++; + } + Map tItemStackMap = new HashMap<>(); + Map tItemDataMap = new HashMap<>(); + tItemStackMap.put(' ', null); + + boolean tRemoveRecipe = true; + + for (; idx < aRecipe.length; idx += 2) { + if (aRecipe[idx] == null || aRecipe[idx + 1] == null) { + if (D1) { + GTLog.err.println( + "WARNING: Missing Item for shaped Recipe: " + + (aResult == null ? "null" : aResult.getDisplayName())); + for (Object tContent : aRecipe) GTLog.err.println(tContent); } - Character chr = (Character) aRecipe[idx]; - Object in = aRecipe[idx + 1]; - if (in instanceof ItemStack is) { - tItemStackMap.put(chr, GTUtility.copyOrNull(is)); - tItemDataMap.put(chr, GTOreDictUnificator.getItemData(is)); - } else if (in instanceof ItemData) { - String tString = in.toString(); - switch (tString) { - case "plankWood" -> tItemDataMap.put(chr, new ItemData(Materials.Wood, M)); - case "stoneNetherrack" -> tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M)); - case "stoneObsidian" -> tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M)); - case "stoneEndstone" -> tItemDataMap.put(chr, new ItemData(Materials.Endstone, M)); - default -> tItemDataMap.put(chr, (ItemData) in); - } - ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); - if (tStack == null) tRemoveRecipe = false; - else tItemStackMap.put(chr, tStack); - in = aRecipe[idx + 1] = in.toString(); - } else if (in instanceof String) { - if (in.equals(OreDictNames.craftingChest.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8)); - else if (in.equals(OreDictNames.craftingBook.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3)); - else if (in.equals(OreDictNames.craftingPiston.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3)); - else if (in.equals(OreDictNames.craftingFurnace.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8)); - else if (in.equals(OreDictNames.craftingIndustrialDiamond.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Diamond, M)); - else if (in.equals(OreDictNames.craftingAnvil.toString())) - tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10)); - ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); - if (tStack == null) tRemoveRecipe = false; - else tItemStackMap.put(chr, tStack); - } else { - throw new IllegalArgumentException(); + return false; + } + Character chr = (Character) aRecipe[idx]; + Object in = aRecipe[idx + 1]; + if (in instanceof ItemStack is) { + tItemStackMap.put(chr, GTUtility.copyOrNull(is)); + tItemDataMap.put(chr, GTOreDictUnificator.getItemData(is)); + } else if (in instanceof ItemData) { + String tString = in.toString(); + switch (tString) { + case "plankWood" -> tItemDataMap.put(chr, new ItemData(Materials.Wood, M)); + case "stoneNetherrack" -> tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M)); + case "stoneObsidian" -> tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M)); + case "stoneEndstone" -> tItemDataMap.put(chr, new ItemData(Materials.Endstone, M)); + default -> tItemDataMap.put(chr, (ItemData) in); } + ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = false; + else tItemStackMap.put(chr, tStack); + in = aRecipe[idx + 1] = in.toString(); + } else if (in instanceof String) { + if (in.equals(OreDictNames.craftingChest.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8)); + else if (in.equals(OreDictNames.craftingBook.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3)); + else if (in.equals(OreDictNames.craftingPiston.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3)); + else if (in.equals(OreDictNames.craftingFurnace.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8)); + else if (in.equals(OreDictNames.craftingIndustrialDiamond.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Diamond, M)); + else if (in.equals(OreDictNames.craftingAnvil.toString())) + tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10)); + ItemStack tStack = GTOreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = false; + else tItemStackMap.put(chr, tStack); + } else { + throw new IllegalArgumentException(); } + } - if (aReversible && aResult != null) { - ItemData[] tData = new ItemData[9]; - int x = -1; - for (char chr : shape.toString() - .toCharArray()) tData[++x] = tItemDataMap.get(chr); - if (GTUtility.arrayContainsNonNull(tData)) - GTOreDictUnificator.addItemData(aResult, new ItemData(tData)); - } + if (aReversible && aResult != null) { + ItemData[] tData = new ItemData[9]; + int x = -1; + for (char chr : shape.toString() + .toCharArray()) tData[++x] = tItemDataMap.get(chr); + if (GTUtility.arrayContainsNonNull(tData)) GTOreDictUnificator.addItemData(aResult, new ItemData(tData)); + } - if (aCheckForCollisions && tRemoveRecipe) { - ItemStack[] tRecipe = new ItemStack[9]; - int x = -1; - for (char chr : shape.toString() - .toCharArray()) { - tRecipe[++x] = tItemStackMap.get(chr); - if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W) - Items.feather.setDamage(tRecipe[x], 0); - } - if (tDoWeCareIfThereWasARecipe || !aBuffered) tThereWasARecipe = removeRecipe(tRecipe) != null; - else removeRecipeDelayed(tRecipe); + if (aCheckForCollisions && tRemoveRecipe) { + ItemStack[] tRecipe = new ItemStack[9]; + int x = -1; + for (char chr : shape.toString() + .toCharArray()) { + tRecipe[++x] = tItemStackMap.get(chr); + if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W) + Items.feather.setDamage(tRecipe[x], 0); } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); + if (tDoWeCareIfThereWasARecipe || !aBuffered) tThereWasARecipe = removeRecipe(tRecipe) != null; + else removeRecipeDelayed(tRecipe); } if (aResult == null || aResult.stackSize <= 0) return false; @@ -1333,30 +1326,27 @@ else if (!(aRecipe[i] == null || aRecipe[i] instanceof ItemStack || aRecipe[i] instanceof String || aRecipe[i] instanceof Character)) aRecipe[i] = aRecipe[i].toString(); } - try { - ItemStack[] tRecipe = new ItemStack[9]; - int i = 0; - for (Object tObject : aRecipe) { - if (tObject == null) { - if (D1) GTLog.err.println( - "WARNING: Missing Item for shapeless Recipe: " - + (aResult == null ? "null" : aResult.getDisplayName())); - for (Object tContent : aRecipe) GTLog.err.println(tContent); - return false; - } - if (tObject instanceof ItemStack) { - tRecipe[i] = (ItemStack) tObject; - } else if (tObject instanceof String) { - tRecipe[i] = GTOreDictUnificator.getFirstOre(tObject, 1); - if (tRecipe[i] == null) break; - } - i++; + + ItemStack[] tRecipe = new ItemStack[9]; + int i = 0; + for (Object tObject : aRecipe) { + if (tObject == null) { + if (D1) GTLog.err.println( + "WARNING: Missing Item for shapeless Recipe: " + + (aResult == null ? "null" : aResult.getDisplayName())); + for (Object tContent : aRecipe) GTLog.err.println(tContent); + return false; + } + if (tObject instanceof ItemStack) { + tRecipe[i] = (ItemStack) tObject; + } else if (tObject instanceof String) { + tRecipe[i] = GTOreDictUnificator.getFirstOre(tObject, 1); + if (tRecipe[i] == null) break; } - if (sBufferCraftingRecipes && aBuffered) removeRecipeDelayed(tRecipe); - else removeRecipe(tRecipe); - } catch (Throwable e) { - e.printStackTrace(GTLog.err); + i++; } + if (sBufferCraftingRecipes && aBuffered) removeRecipeDelayed(tRecipe); + else removeRecipe(tRecipe); if (aResult == null || aResult.stackSize <= 0) return false; @@ -1442,21 +1432,17 @@ public boolean canInteractWith(EntityPlayer player) { ArrayList tList = (ArrayList) CraftingManager.getInstance() .getRecipeList(); int tList_sS = tList.size(); - try { - for (int i = 0; i < tList_sS; i++) { - for (; i < tList_sS; i++) { - if ((!(tList.get(i) instanceof IGTCraftingRecipe) - || ((IGTCraftingRecipe) tList.get(i)).isRemovable()) && tList.get(i) - .matches(aCrafting, DW)) { - rReturn = tList.get(i) - .getCraftingResult(aCrafting); - if (rReturn != null) tList.remove(i--); - tList_sS = tList.size(); - } + for (int i = 0; i < tList_sS; i++) { + for (; i < tList_sS; i++) { + if ((!(tList.get(i) instanceof IGTCraftingRecipe) || ((IGTCraftingRecipe) tList.get(i)).isRemovable()) + && tList.get(i) + .matches(aCrafting, DW)) { + rReturn = tList.get(i) + .getCraftingResult(aCrafting); + if (rReturn != null) tList.remove(i--); + tList_sS = tList.size(); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } return rReturn; } @@ -1691,12 +1677,7 @@ public boolean canInteractWith(EntityPlayer player) { found = false; if (!allowOreDict && iRecipe instanceof ShapedOreRecipe) continue; - try { - found = iRecipe.matches(aCrafting, DW); - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - if (found) { + if (iRecipe.matches(aCrafting, DW)) { ItemStack tOutput = aUncopiedStack ? iRecipe.getRecipeOutput() : iRecipe.getCraftingResult(aCrafting); if (tOutput == null || tOutput.stackSize <= 0) { // Seriously, who would ever do that shit? @@ -1834,12 +1815,7 @@ public boolean canInteractWith(EntityPlayer player) { .filter(tRecipe -> { if (tRecipe instanceof ShapelessRecipes || tRecipe instanceof ShapelessOreRecipe || tRecipe instanceof IGTCraftingRecipe) return false; - try { - return tRecipe.matches(aCrafting, DW); - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - return false; - } + return tRecipe.matches(aCrafting, DW); }) .forEach(tRecipe -> stacks.add(tRecipe.getCraftingResult(aCrafting))); rList = stacks.stream() @@ -1848,14 +1824,8 @@ public boolean canInteractWith(EntityPlayer player) { .collect(Collectors.toList()); } else for (Iterator iterator = aList.iterator(); iterator.hasNext();) { IRecipe tRecipe = iterator.next(); - boolean matched = false; - try { - matched = tRecipe.matches(aCrafting, DW); - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - if (matched) { + if (tRecipe.matches(aCrafting, DW)) { ItemStack tOutput = tRecipe.getCraftingResult(aCrafting); if (tOutput == null || tOutput.stackSize <= 0) { @@ -1903,37 +1873,33 @@ public static ItemStack[] getMachineOutput(ItemStack aInput, Map tEntry : aRecipeList.entrySet()) { + for (Entry tEntry : aRecipeList.entrySet()) { + if (tEntry.getKey() + .matches(aInput)) { if (tEntry.getKey() - .matches(aInput)) { - if (tEntry.getKey() - .getAmount() <= aInput.stackSize) { - ItemStack[] tList = tEntry.getValue().items.toArray(new ItemStack[0]); - if (tList.length == 0) break; - ItemStack[] rList = new ItemStack[aOutputSlots.length]; - rRecipeMetaData.setTag("return", tEntry.getValue().metadata); - for (byte i = 0; i < aOutputSlots.length && i < tList.length; i++) { - if (tList[i] != null) { - if (aOutputSlots[i] == null || (GTUtility.areStacksEqual(tList[i], aOutputSlots[i]) - && tList[i].stackSize + aOutputSlots[i].stackSize - <= aOutputSlots[i].getMaxStackSize())) { - rList[i] = GTUtility.copyOrNull(tList[i]); - } else { - return new ItemStack[aOutputSlots.length]; - } + .getAmount() <= aInput.stackSize) { + ItemStack[] tList = tEntry.getValue().items.toArray(new ItemStack[0]); + if (tList.length == 0) break; + ItemStack[] rList = new ItemStack[aOutputSlots.length]; + rRecipeMetaData.setTag("return", tEntry.getValue().metadata); + for (byte i = 0; i < aOutputSlots.length && i < tList.length; i++) { + if (tList[i] != null) { + if (aOutputSlots[i] == null || (GTUtility.areStacksEqual(tList[i], aOutputSlots[i]) + && tList[i].stackSize + aOutputSlots[i].stackSize + <= aOutputSlots[i].getMaxStackSize())) { + rList[i] = GTUtility.copyOrNull(tList[i]); + } else { + return new ItemStack[aOutputSlots.length]; } } - - if (aRemoveInput) aInput.stackSize -= tEntry.getKey() - .getAmount(); - return rList; } - break; + + if (aRemoveInput) aInput.stackSize -= tEntry.getKey() + .getAmount(); + return rList; } + break; } - } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); } return new ItemStack[aOutputSlots.length]; } @@ -2005,22 +1971,17 @@ public static ItemStack getRandomScrapboxDrop() { */ public static int chargeElectricItem(ItemStack aStack, int aCharge, int aTier, boolean aIgnoreLimit, boolean aSimulate) { - try { - if (isElectricItem(aStack)) { - int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack); - if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) { - if (!aIgnoreLimit && tTier >= 0) - aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))]); - if (aCharge > 0) { - int rCharge = (int) Math.max( - 0.0, - ic2.api.item.ElectricItem.manager.charge(aStack, aCharge, tTier, true, aSimulate)); - return rCharge + (rCharge * 4 > aTier ? aTier : 0); - } + if (isElectricItem(aStack)) { + int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack); + if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) { + if (!aIgnoreLimit && tTier >= 0) + aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))]); + if (aCharge > 0) { + int rCharge = (int) Math + .max(0.0, ic2.api.item.ElectricItem.manager.charge(aStack, aCharge, tTier, true, aSimulate)); + return rCharge + (rCharge * 4 > aTier ? aTier : 0); } } - } catch (Throwable e) { - /* Do nothing */ } return 0; } @@ -2034,31 +1995,25 @@ public static int chargeElectricItem(ItemStack aStack, int aCharge, int aTier, b */ public static int dischargeElectricItem(ItemStack aStack, int aCharge, int aTier, boolean aIgnoreLimit, boolean aSimulate, boolean aIgnoreDischargability) { - try { - // if (isElectricItem(aStack) && (aIgnoreDischargability || - // ((ic2.api.item.IElectricItem)aStack.getItem()).canProvideEnergy(aStack))) { - if (isElectricItem(aStack)) { - int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack); - if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) { - if (!aIgnoreLimit && tTier >= 0) aCharge = (int) Math.min( - aCharge, - V[Math.max(0, Math.min(V.length - 1, tTier))] + B[Math.max(0, Math.min(V.length - 1, tTier))]); - if (aCharge > 0) { - int rCharge = (int) Math.max( - 0, - ic2.api.item.ElectricItem.manager.discharge( - aStack, - aCharge + (aCharge * 4 > aTier ? aTier : 0), - tTier, - true, - !aIgnoreDischargability, - aSimulate)); - return rCharge - (rCharge * 4 > aTier ? aTier : 0); - } + if (isElectricItem(aStack)) { + int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack); + if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) { + if (!aIgnoreLimit && tTier >= 0) aCharge = (int) Math.min( + aCharge, + V[Math.max(0, Math.min(V.length - 1, tTier))] + B[Math.max(0, Math.min(V.length - 1, tTier))]); + if (aCharge > 0) { + int rCharge = (int) Math.max( + 0, + ic2.api.item.ElectricItem.manager.discharge( + aStack, + aCharge + (aCharge * 4 > aTier ? aTier : 0), + tTier, + true, + !aIgnoreDischargability, + aSimulate)); + return rCharge - (rCharge * 4 > aTier ? aTier : 0); } } - } catch (Throwable e) { - /* Do nothing */ } return 0; } @@ -2069,12 +2024,8 @@ public static int dischargeElectricItem(ItemStack aStack, int aCharge, int aTier * @return if the action was successful */ public static boolean canUseElectricItem(ItemStack aStack, int aCharge) { - try { - if (isElectricItem(aStack)) { - return ic2.api.item.ElectricItem.manager.canUse(aStack, aCharge); - } - } catch (Throwable e) { - /* Do nothing */ + if (isElectricItem(aStack)) { + return ic2.api.item.ElectricItem.manager.canUse(aStack, aCharge); } return false; } @@ -2085,15 +2036,11 @@ public static boolean canUseElectricItem(ItemStack aStack, int aCharge) { * @return if the action was successful */ public static boolean useElectricItem(ItemStack aStack, int aCharge, EntityPlayer aPlayer) { - try { - if (isElectricItem(aStack)) { - ic2.api.item.ElectricItem.manager.use(aStack, 0, aPlayer); - if (ic2.api.item.ElectricItem.manager.canUse(aStack, aCharge)) { - return ic2.api.item.ElectricItem.manager.use(aStack, aCharge, aPlayer); - } + if (isElectricItem(aStack)) { + ic2.api.item.ElectricItem.manager.use(aStack, 0, aPlayer); + if (ic2.api.item.ElectricItem.manager.canUse(aStack, aCharge)) { + return ic2.api.item.ElectricItem.manager.use(aStack, aCharge, aPlayer); } - } catch (Throwable e) { - /* Do nothing */ } return false; } @@ -2225,12 +2172,8 @@ public static boolean consumeSolderingMaterial(IInventory aInventory) { * Is this an electric Item, which can charge other Items? */ public static boolean isChargerItem(ItemStack aStack) { - try { - if (isElectricItem(aStack)) { - return ((ic2.api.item.IElectricItem) aStack.getItem()).canProvideEnergy(aStack); - } - } catch (Throwable e) { - /* Do nothing */ + if (isElectricItem(aStack)) { + return ((ic2.api.item.IElectricItem) aStack.getItem()).canProvideEnergy(aStack); } return false; } @@ -2239,23 +2182,13 @@ public static boolean isChargerItem(ItemStack aStack) { * Is this an electric Item? */ public static boolean isElectricItem(ItemStack aStack) { - try { - return aStack != null && aStack.getItem() instanceof ic2.api.item.IElectricItem - && ((IElectricItem) aStack.getItem()).getTier(aStack) < Integer.MAX_VALUE; - } catch (Throwable e) { - /* Do nothing */ - } - return false; + return aStack != null && aStack.getItem() instanceof ic2.api.item.IElectricItem + && ((IElectricItem) aStack.getItem()).getTier(aStack) < Integer.MAX_VALUE; } public static boolean isElectricItem(ItemStack aStack, byte aTier) { - try { - return aStack != null && aStack.getItem() instanceof ic2.api.item.IElectricItem - && ((IElectricItem) aStack.getItem()).getTier(aStack) == aTier; - } catch (Throwable e) { - /* Do nothing */ - } - return false; + return aStack != null && aStack.getItem() instanceof ic2.api.item.IElectricItem + && ((IElectricItem) aStack.getItem()).getTier(aStack) == aTier; } /** @@ -2292,11 +2225,7 @@ public static Optional getElectricItemCharge(ItemStack aStack) { */ public static void registerBoxableItemToToolBox(ItemStack aStack) { if (aStack != null) { - try { - ic2.api.item.ItemWrapper.registerBoxable(aStack.getItem(), (IBoxable) sBoxableWrapper); - } catch (Throwable ignored) { - /* Do nothing */ - } + ic2.api.item.ItemWrapper.registerBoxable(aStack.getItem(), (IBoxable) sBoxableWrapper); sBoxableItems.add(new GTItemStack(aStack)); } } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 3294b0523d8..d4ee0a81c04 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -129,6 +129,7 @@ import cofh.api.transport.IItemDuct; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.damagesources.GTDamageSources; import gregtech.api.damagesources.GTDamageSources.DamageSourceHotItem; @@ -241,7 +242,7 @@ public static Field getPublicField(Object aObject, String aField) { rField = aObject.getClass() .getDeclaredField(aField); } catch (Throwable e) { - /* Do nothing */ + if (D1) e.printStackTrace(GTLog.err); } return rField; } @@ -253,7 +254,7 @@ public static Field getField(Object aObject, String aField) { .getDeclaredField(aField); rField.setAccessible(true); } catch (Throwable e) { - /* Do nothing */ + if (D1) e.printStackTrace(GTLog.err); } return rField; } @@ -264,7 +265,7 @@ public static Field getField(Class aObject, String aField) { rField = aObject.getDeclaredField(aField); rField.setAccessible(true); } catch (Throwable e) { - /* Do nothing */ + if (D1) e.printStackTrace(GTLog.err); } return rField; } @@ -275,7 +276,7 @@ public static Method getMethod(Class aObject, String aMethod, Class... aPa rMethod = aObject.getMethod(aMethod, aParameterTypes); rMethod.setAccessible(true); } catch (Throwable e) { - /* Do nothing */ + if (D1) e.printStackTrace(GTLog.err); } return rMethod; } @@ -287,7 +288,7 @@ public static Method getMethod(Object aObject, String aMethod, Class... aPara .getMethod(aMethod, aParameterTypes); rMethod.setAccessible(true); } catch (Throwable e) { - /* Do nothing */ + if (D1) e.printStackTrace(GTLog.err); } return rMethod; } @@ -370,7 +371,9 @@ public static Object callConstructor(Class aClass, int aConstructorIndex, Obj for (Constructor tConstructor : aClass.getConstructors()) { try { return tConstructor.newInstance(aParameters); - } catch (Throwable ignored) {} + } catch (Throwable e) { + if (D1) e.printStackTrace(GTLog.err); + } } } catch (Throwable e) { if (aLogErrors) e.printStackTrace(GTLog.err); @@ -507,21 +510,21 @@ public static void checkAvailabilities() { tClass.getCanonicalName(); TE_CHECK = true; } catch (Throwable e) { - /**/ + if (D1) e.printStackTrace(GTLog.err); } try { Class tClass = buildcraft.api.transport.IPipeTile.class; tClass.getCanonicalName(); BC_CHECK = true; } catch (Throwable e) { - /**/ + if (D1) e.printStackTrace(GTLog.err); } try { Class tClass = cofh.api.energy.IEnergyReceiver.class; tClass.getCanonicalName(); RF_CHECK = true; } catch (Throwable e) { - /**/ + if (D1) e.printStackTrace(GTLog.err); } CHECK_ALL = false; } @@ -2725,7 +2728,11 @@ public static boolean applyHeatDamageFromItem(EntityLivingBase entity, float dam private static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage, DamageSource source) { if (aDamage > 0 && aEntity != null && !isWearingFullHeatHazmat(aEntity)) { - return aEntity.attackEntityFrom(source, aDamage); + try { + return aEntity.attackEntityFrom(source, aDamage); + } catch (Throwable t) { + GTMod.GT_FML_LOGGER.error("Error damaging entity", t); + } } return false; } @@ -3251,14 +3258,10 @@ public static int getCoordinateScan(ArrayList aList, EntityPlayer aPlaye if (tTileEntity != null) { rEUAmount += addFluidHandlerInfo(side, tList, tTileEntity); - try { - if (tTileEntity instanceof ic2.api.reactor.IReactorChamber chamber) { - rEUAmount += 500; - // Redirect the rest of the scans to the reactor itself - tTileEntity = (TileEntity) chamber.getReactor(); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GTLog.err); + if (tTileEntity instanceof ic2.api.reactor.IReactorChamber chamber) { + rEUAmount += 500; + // Redirect the rest of the scans to the reactor itself + tTileEntity = (TileEntity) chamber.getReactor(); } rEUAmount += addReactorInfo(tList, tTileEntity); rEUAmount += addAlignmentInfo(tList, tTileEntity); diff --git a/src/main/java/gregtech/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index 659c626e2f2..b57e53697fe 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -802,16 +802,15 @@ public GTProxy() { .getRegisteredFluidContainerData()) { onFluidContainerRegistration(new FluidContainerRegistry.FluidContainerRegisterEvent(tData)); } - try { - for (String tOreName : OreDictionary.getOreNames()) { - ItemStack tOreStack; - for (Iterator i$ = OreDictionary.getOres(tOreName) - .iterator(); i$.hasNext(); registerOre(new OreDictionary.OreRegisterEvent(tOreName, tOreStack))) { - tOreStack = i$.next(); + for (String tOreName : OreDictionary.getOreNames()) { + for (ItemStack ore : OreDictionary.getOres(tOreName)) { + try { + registerOre(new OreDictionary.OreRegisterEvent(tOreName, ore)); + } catch (Throwable e) { + GT_FML_LOGGER + .error("Error registering ore (oredict name=" + tOreName + ", item stack=" + ore + ")", e); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } } @@ -1245,14 +1244,14 @@ public void onPostLoad() { } } GTLog.out.println("GTMod: Adding Configs specific for MetaTileEntities"); - try { - for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { - if (GregTechAPI.METATILEENTITIES[i] != null) { + for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { + if (GregTechAPI.METATILEENTITIES[i] != null) { + try { GregTechAPI.METATILEENTITIES[i].onConfigLoad(); + } catch (Throwable e) { + GT_FML_LOGGER.error("Could not load config for MTE " + GregTechAPI.METATILEENTITIES[i], e); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } GTLog.out.println("GTMod: Adding Tool Usage Crafting Recipes for OreDict Items."); for (Materials aMaterial : Materials.values()) { @@ -1341,14 +1340,14 @@ public void onServerStarting() { break; } } - try { - for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { - if (GregTechAPI.METATILEENTITIES[i] != null) { + for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { + if (GregTechAPI.METATILEENTITIES[i] != null) { + try { GregTechAPI.METATILEENTITIES[i].onServerStart(); + } catch (Throwable e) { + GT_FML_LOGGER.error("Could not call onServerStart MTE " + GregTechAPI.METATILEENTITIES[i], e); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } } @@ -1384,19 +1383,17 @@ public void onServerStopping() { File tSaveDirectory = getSaveDirectory(); GregTechAPI.sWirelessRedstone.clear(); if (tSaveDirectory != null) { - try { - for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { - if (GregTechAPI.METATILEENTITIES[i] != null) { + for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { + if (GregTechAPI.METATILEENTITIES[i] != null) { + try { GregTechAPI.METATILEENTITIES[i].onWorldSave(tSaveDirectory); + } catch (Throwable e) { + GT_FML_LOGGER.error("Could call onWorldSave for MTE " + GregTechAPI.METATILEENTITIES[i], e); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } } this.mUniverse = null; - // GT_ChunkAssociatedData.saveAll(); todo: figure out if this is needed - } @SubscribeEvent @@ -2104,7 +2101,8 @@ public void registerOre(OreDictionary.OreRegisterEvent aEvent) { registerRecipes(tOre); } } catch (Throwable e) { - e.printStackTrace(GTLog.err); + GT_FML_LOGGER + .error("Could not register ore (oredict name=" + aEvent.Name + ", item stack=" + aEvent.Ore + ")", e); } } @@ -2182,14 +2180,15 @@ public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) { File tSaveDiretory = getSaveDirectory(); if (tSaveDiretory != null) { this.isFirstServerWorldTick = false; - try { - for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { - if (GregTechAPI.METATILEENTITIES[i] != null) { + for (int i = 1; i < GregTechAPI.METATILEENTITIES.length; i++) { + if (GregTechAPI.METATILEENTITIES[i] != null) { + try { GregTechAPI.METATILEENTITIES[i].onWorldLoad(tSaveDiretory); + } catch (Throwable e) { + GT_FML_LOGGER + .error("Could call onWorldLoad for MTE " + GregTechAPI.METATILEENTITIES[i], e); } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } } } diff --git a/src/main/java/gregtech/common/blocks/ItemMachines.java b/src/main/java/gregtech/common/blocks/ItemMachines.java index f6816f468a1..fff1294790a 100644 --- a/src/main/java/gregtech/common/blocks/ItemMachines.java +++ b/src/main/java/gregtech/common/blocks/ItemMachines.java @@ -153,6 +153,8 @@ public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List } } } catch (Throwable e) { + aList.add(String.format("§cAn exception was thrown while getting this item's info.§r")); + aList.add(e.getLocalizedMessage()); GT_FML_LOGGER.error("addInformation", e); } } diff --git a/src/main/java/gregtech/common/items/ItemIntegratedCircuit.java b/src/main/java/gregtech/common/items/ItemIntegratedCircuit.java index b6dfa079a20..e1feee2e18c 100644 --- a/src/main/java/gregtech/common/items/ItemIntegratedCircuit.java +++ b/src/main/java/gregtech/common/items/ItemIntegratedCircuit.java @@ -30,6 +30,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.ItemList; @@ -222,12 +223,12 @@ public void registerIcons(IIconRegister aIconRegister) { GTLog.out.println("GTMod: Starting Item Icon Load Phase"); GT_FML_LOGGER.info("GTMod: Starting Item Icon Load Phase"); GregTechAPI.sItemIcons = aIconRegister; - try { - for (Runnable tRunnable : GregTechAPI.sGTItemIconload) { + for (Runnable tRunnable : GregTechAPI.sGTItemIconload) { + try { tRunnable.run(); + } catch (Throwable e) { + GTMod.GT_FML_LOGGER.error("Error registering icons", e); } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } GTLog.out.println("GTMod: Finished Item Icon Load Phase"); GT_FML_LOGGER.info("GTMod: Finished Item Icon Load Phase"); diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourWrench.java b/src/main/java/gregtech/common/items/behaviors/BehaviourWrench.java index 6155a6c7395..8404bd33390 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourWrench.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourWrench.java @@ -16,6 +16,7 @@ import appeng.api.parts.IPartHost; import appeng.api.util.IOrientable; import appeng.tile.misc.TileInterface; +import gregtech.GTMod; import gregtech.api.enums.SoundResource; import gregtech.api.items.MetaBaseItem; import gregtech.api.items.MetaGeneratedTool; @@ -61,7 +62,9 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer try { return handler.handle() && !aWorld.isRemote; - } catch (Throwable ignored) {} + } catch (Throwable e) { + GTMod.GT_FML_LOGGER.error("Error wrenching", e); + } return false; } diff --git a/src/main/java/gregtech/common/tileentities/boilers/MTEBoiler.java b/src/main/java/gregtech/common/tileentities/boilers/MTEBoiler.java index b49da44e979..b0040d13f1b 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/MTEBoiler.java +++ b/src/main/java/gregtech/common/tileentities/boilers/MTEBoiler.java @@ -199,12 +199,9 @@ public void saveNBTData(NBTTagCompound aNBT) { aNBT.setInteger("mTemperature", this.mTemperature); aNBT.setInteger("mProcessingEnergy", this.mProcessingEnergy); aNBT.setInteger("mExcessWater", this.mExcessWater); - if (this.mSteam == null) { - return; - } - try { + if (mSteam != null) { aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound())); - } catch (Throwable ignored) {} + } } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java b/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java index 742a6a0e842..f2c0213a845 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java @@ -1,6 +1,5 @@ package gregtech.common.tileentities.machines.basic; -import static gregtech.api.enums.GTValues.D1; import static gregtech.api.enums.Mods.GalacticraftCore; import static gregtech.api.enums.Mods.GalacticraftMars; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_SCANNER; @@ -45,7 +44,6 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.render.TextureFactory; import gregtech.api.util.AssemblyLineUtils; -import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; @@ -130,32 +128,26 @@ public int checkRecipe() { this.mOutputBlocked += 1; } else if ((GTUtility.isStackValid(aStack)) && (aStack.stackSize > 0)) { if ((getFillableStack() != null) && (getFillableStack().containsFluid(Materials.Honey.getFluid(100L)))) { - try { - IIndividual tIndividual = AlleleManager.alleleRegistry.getIndividual(aStack); - if (tIndividual != null) { - if (tIndividual.analyze()) { - getFillableStack().amount -= 100; - this.mOutputItems[0] = GTUtility.copyOrNull(aStack); - aStack.stackSize = 0; - NBTTagCompound tNBT = new NBTTagCompound(); - tIndividual.writeToNBT(tNBT); - this.mOutputItems[0].setTagCompound(tNBT); - calculateOverclockedNess(2, 500); - // In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - return 2; - } + IIndividual tIndividual = AlleleManager.alleleRegistry.getIndividual(aStack); + if (tIndividual != null) { + if (tIndividual.analyze()) { + getFillableStack().amount -= 100; this.mOutputItems[0] = GTUtility.copyOrNull(aStack); aStack.stackSize = 0; - this.mMaxProgresstime = 1; - this.mEUt = 1; + NBTTagCompound tNBT = new NBTTagCompound(); + tIndividual.writeToNBT(tNBT); + this.mOutputItems[0].setTagCompound(tNBT); + calculateOverclockedNess(2, 500); + // In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; } - } catch (Throwable e) { - if (D1) { - e.printStackTrace(GTLog.err); - } + this.mOutputItems[0] = GTUtility.copyOrNull(aStack); + aStack.stackSize = 0; + this.mMaxProgresstime = 1; + this.mEUt = 1; + return 2; } } if (ItemList.IC2_Crop_Seeds.isStackEqual(aStack, true, true)) { diff --git a/src/main/java/gtPlusPlus/core/block/machine/BlockPooCollector.java b/src/main/java/gtPlusPlus/core/block/machine/BlockPooCollector.java index 6a371a3284c..19cc847ba06 100644 --- a/src/main/java/gtPlusPlus/core/block/machine/BlockPooCollector.java +++ b/src/main/java/gtPlusPlus/core/block/machine/BlockPooCollector.java @@ -85,30 +85,6 @@ public boolean onBlockActivated(final World world, final int x, final int y, fin } else { TileEntityBaseFluidCollector tank = (TileEntityBaseFluidCollector) world.getTileEntity(x, y, z); if (tank != null) { - Item handItem; - try { - handItem = player.getHeldItem() - .getItem(); - } catch (Throwable t) { - handItem = null; - } - - // Fluid container code - /* - * if (handItem != null && (handItem instanceof IFluidContainerItem || handItem instanceof - * ItemFluidContainer || FluidContainerRegistry.isFilledContainer(player.getHeldItem()))) { if - * (tank.tank.getFluid() == null) { try { if - * (!FluidContainerRegistry.isFilledContainer(player.getHeldItem())) { ItemStack handItemStack = - * player.getHeldItem(); IFluidContainerItem container = (IFluidContainerItem) handItem; FluidStack - * containerFluid = container.getFluid(handItemStack); container.drain(handItemStack, - * container.getFluid(handItemStack).amount, true); tank.tank.setFluid(containerFluid); } else { - * ItemStack handItemStack = player.getHeldItem(); - * FluidContainerRegistry.drainFluidContainer(handItemStack); FluidStack containerFluid = - * FluidContainerRegistry.getFluidForFilledItem(handItemStack); ItemStack emptyContainer = - * FluidContainerRegistry.drainFluidContainer(handItemStack); player.setItemInUse(emptyContainer, 0); - * tank.tank.setFluid(containerFluid); } } catch (Throwable t) { t.printStackTrace(); } } } - */ - if (!tank.mInventory.isEmpty()) { PlayerUtils.messagePlayer(player, "Inventory contains:"); PlayerUtils.messagePlayer(player, ItemUtils.getArrayStackNames(tank.mInventory.getRealInventory())); diff --git a/src/main/java/gtPlusPlus/core/handler/CompatHandler.java b/src/main/java/gtPlusPlus/core/handler/CompatHandler.java index 1c442163441..43ab7b7bec4 100644 --- a/src/main/java/gtPlusPlus/core/handler/CompatHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/CompatHandler.java @@ -234,17 +234,10 @@ public static void startLoadingGregAPIBasedRecipes() { // Add autogenerated Recipes from Item Components for (Set> m : MaterialGenerator.mRecipeMapsToGenerate) { for (RunnableWithInfo r : m) { - try { - r.run(); - Logger.INFO( - "[FIND] " + r.getInfoData() - .getLocalizedName() + " recipes generated."); - } catch (Throwable t) { - t.printStackTrace(); - Logger.INFO( - "[ERROR] " + r.getInfoData() - .getLocalizedName() + " recipes failed to generated."); - } + r.run(); + Logger.INFO( + "[FIND] " + r.getInfoData() + .getLocalizedName() + " recipes generated."); } } RecipeGenRecycling.executeGenerators(); @@ -267,31 +260,16 @@ public static void onLoadComplete(FMLLoadCompleteEvent event) { public static void runQueuedRecipes() { // Add autogenerated Recipes from Item Components for (RunnableWithInfo m : mRecipesToGenerate) { - try { - m.run(); - } catch (Throwable t) { - t.printStackTrace(); - Logger.INFO("[ERROR] " + m.getInfoData() + " recipe failed to generated."); - } + m.run(); } for (RunnableWithInfo m : mGtRecipesToGenerate) { - try { - m.run(); - } catch (Throwable t) { - t.printStackTrace(); - Logger.INFO("[ERROR] " + m.getInfoData() + " recipe failed to generated."); - } + m.run(); } } public static void runQueuedMisc() { for (RunnableWithInfo m : mObjectsToRunInPostInit) { - try { - m.run(); - } catch (Throwable t) { - t.printStackTrace(); - Logger.INFO("[ERROR] " + m.getInfoData()); - } + m.run(); } } @@ -300,12 +278,7 @@ public static void runQueuedMisc() { */ public static void runQueuedOnLoadComplete(FMLLoadCompleteEvent event) { for (ItemPackage m : mObjectsToRunInOnLoadComplete) { - try { - m.onLoadComplete(event); - } catch (Throwable t) { - t.printStackTrace(); - Logger.INFO("[ERROR] " + m.getInfoData()); - } + m.onLoadComplete(event); } } } diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 3dab9bde39d..d164fe6596f 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -1148,7 +1148,7 @@ public final Block getOreBlock(final int stacksize) { return x; } } catch (Throwable t) { - // t.printStackTrace(); + t.printStackTrace(); } // Logger.MATERIALS("Failed getting the Ore Block for "+this.getLocalizedName()+"."); return Blocks.stone; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenDustGeneration.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenDustGeneration.java index 2c380e6eba1..e5b61f049d6 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenDustGeneration.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenDustGeneration.java @@ -330,29 +330,25 @@ public static boolean addMixerRecipe_Standalone(final Material material) { } // Add mixer Recipe - try { - if (oxygen == null) { - GTValues.RA.stdBuilder() - .itemInputs(input1, input2, input3, input4) - .itemOutputs(outputStacks) - .duration((int) Math.max(material.getMass() * 2L * 1, 1)) - .eut(material.vVoltageMultiplier) - .addTo(mixerRecipes); - } else { - GTValues.RA.stdBuilder() - .itemInputs(input1, input2, input3, input4) - .itemOutputs(outputStacks) - .fluidInputs(oxygen) - .duration((int) Math.max(material.getMass() * 2L * 1, 1)) - .eut(material.vVoltageMultiplier) - .addTo(mixerRecipes); - } + if (oxygen == null) { + GTValues.RA.stdBuilder() + .itemInputs(input1, input2, input3, input4) + .itemOutputs(outputStacks) + .duration((int) Math.max(material.getMass() * 2L * 1, 1)) + .eut(material.vVoltageMultiplier) + .addTo(mixerRecipes); + } else { + GTValues.RA.stdBuilder() + .itemInputs(input1, input2, input3, input4) + .itemOutputs(outputStacks) + .fluidInputs(oxygen) + .duration((int) Math.max(material.getMass() * 2L * 1, 1)) + .eut(material.vVoltageMultiplier) + .addTo(mixerRecipes); + } - Logger.WARNING("Dust Mixer Recipe: " + material.getLocalizedName() + " - Success"); + Logger.WARNING("Dust Mixer Recipe: " + material.getLocalizedName() + " - Success"); - } catch (Throwable t) { - t.printStackTrace(); - } return true; } @@ -378,32 +374,26 @@ public static boolean generatePackagerRecipes(Material aMatInfo) { private void addFurnaceRecipe(Material aMatInfo) { ItemStack aDust = aMatInfo.getDust(1); - ItemStack aOutput; - try { - if (aMatInfo.requiresBlastFurnace()) { - aOutput = aMatInfo.getHotIngot(1); - if (ItemUtils.checkForInvalidItems(aOutput)) { - if (addBlastFurnaceRecipe(aMatInfo, aDust, aOutput, aMatInfo.getMeltingPointK())) { - Logger - .MATERIALS("Successfully added a blast furnace recipe for " + aMatInfo.getLocalizedName()); - } else { - Logger.MATERIALS("Failed to add a blast furnace recipe for " + aMatInfo.getLocalizedName()); - } + if (aMatInfo.requiresBlastFurnace()) { + ItemStack aOutput = aMatInfo.getHotIngot(1); + if (ItemUtils.checkForInvalidItems(aOutput)) { + if (addBlastFurnaceRecipe(aMatInfo, aDust, aOutput, aMatInfo.getMeltingPointK())) { + Logger.MATERIALS("Successfully added a blast furnace recipe for " + aMatInfo.getLocalizedName()); } else { Logger.MATERIALS("Failed to add a blast furnace recipe for " + aMatInfo.getLocalizedName()); } } else { - aOutput = aMatInfo.getIngot(1); - if (ItemUtils.checkForInvalidItems(aOutput)) { - if (GTModHandler.addSmeltingAndAlloySmeltingRecipe(aDust, aOutput, false)) { - Logger.MATERIALS("Successfully added a furnace recipe for " + aMatInfo.getLocalizedName()); - } else { - Logger.MATERIALS("Failed to add a furnace recipe for " + aMatInfo.getLocalizedName()); - } + Logger.MATERIALS("Failed to add a blast furnace recipe for " + aMatInfo.getLocalizedName()); + } + } else { + ItemStack aOutput = aMatInfo.getIngot(1); + if (ItemUtils.checkForInvalidItems(aOutput)) { + if (GTModHandler.addSmeltingAndAlloySmeltingRecipe(aDust, aOutput, false)) { + Logger.MATERIALS("Successfully added a furnace recipe for " + aMatInfo.getLocalizedName()); + } else { + Logger.MATERIALS("Failed to add a furnace recipe for " + aMatInfo.getLocalizedName()); } } - } catch (Throwable t) { - t.printStackTrace(); } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java index 63812e2e6e8..35a4b9d3f4d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java @@ -284,39 +284,33 @@ public static ArrayList getOres(final Object aOreName) { } public static ItemStack getItemStackOfAmountFromOreDictNoBroken(String oredictName, final int amount) { + if (oredictName.contains("-") || oredictName.contains("_")) { + oredictName = Utils.sanitizeString(oredictName, new char[] { '-', '_' }); + } else { + oredictName = Utils.sanitizeString(oredictName); + } - try { - - if (oredictName.contains("-") || oredictName.contains("_")) { - oredictName = Utils.sanitizeString(oredictName, new char[] { '-', '_' }); - } else { - oredictName = Utils.sanitizeString(oredictName); - } - - // Adds a check to grab dusts using GT methodology if possible. - ItemStack returnValue = null; - if (oredictName.toLowerCase() - .contains("dust")) { - final String MaterialName = oredictName.toLowerCase() - .replace("dust", ""); - final Materials m = Materials.get(MaterialName); - if (m != null && m != Materials._NULL) { - returnValue = ItemUtils.getGregtechDust(m, amount); - if (ItemUtils.checkForInvalidItems(returnValue)) { - return returnValue; - } - } - } - if (returnValue == null) { - returnValue = getItemStackOfAmountFromOreDict(oredictName, amount); + // Adds a check to grab dusts using GT methodology if possible. + ItemStack returnValue = null; + if (oredictName.toLowerCase() + .contains("dust")) { + final String MaterialName = oredictName.toLowerCase() + .replace("dust", ""); + final Materials m = Materials.get(MaterialName); + if (m != null && m != Materials._NULL) { + returnValue = ItemUtils.getGregtechDust(m, amount); if (ItemUtils.checkForInvalidItems(returnValue)) { - return returnValue.copy(); + return returnValue; } } - return null; - } catch (final Throwable t) { - return null; } + if (returnValue == null) { + returnValue = getItemStackOfAmountFromOreDict(oredictName, amount); + if (ItemUtils.checkForInvalidItems(returnValue)) { + return returnValue.copy(); + } + } + return null; } public static ItemStack getItemStackOfAmountFromOreDict(String oredictName, final int amount) { diff --git a/src/main/java/tectech/loader/MainLoader.java b/src/main/java/tectech/loader/MainLoader.java index ab687fbbf9c..d98429dfd69 100644 --- a/src/main/java/tectech/loader/MainLoader.java +++ b/src/main/java/tectech/loader/MainLoader.java @@ -30,11 +30,7 @@ public static void preLoad() { creativeTabTecTech = new CreativeTabTecTech("TecTech"); // set expanded texture arrays for tiers - try { - Textures.run(); - } catch (Throwable t) { - LOGGER.error("Loading textures...", t); - } + Textures.run(); } public static void load() { From da0b27f2e733b04f20f8c5a0a0732006243ff103 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 19 Dec 2024 16:26:26 -0500 Subject: [PATCH 2/5] spotless --- src/main/java/gregtech/api/util/GTForestryCompat.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/util/GTForestryCompat.java b/src/main/java/gregtech/api/util/GTForestryCompat.java index d8e28759e42..bc05f8db363 100644 --- a/src/main/java/gregtech/api/util/GTForestryCompat.java +++ b/src/main/java/gregtech/api/util/GTForestryCompat.java @@ -172,8 +172,7 @@ public static void transferSqueezerRecipes() { ItemStack[] resources = tRecipe.getResources(); if ((resources.length == 1) && (tRecipe.getFluidOutput() != null) && (resources[0] != null)) { Item input = resources[0].getItem(); - if (input == Items.pumpkin_seeds || input == Items.melon_seeds || input == Items.wheat_seeds) - continue; + if (input == Items.pumpkin_seeds || input == Items.melon_seeds || input == Items.wheat_seeds) continue; GTRecipeBuilder recipeBuilder = GTValues.RA.stdBuilder(); recipeBuilder.itemInputs(resources[0]); if (tRecipe.getRemnants() != null) { From 4e798e7e6623154ac1f8beb8261e86b4167741e8 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 19 Dec 2024 16:37:28 -0500 Subject: [PATCH 3/5] remove more try catches --- src/main/java/gregtech/GTMod.java | 80 +++++++------------------------ 1 file changed, 16 insertions(+), 64 deletions(-) diff --git a/src/main/java/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index 69db262d589..ff28eb8085d 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -258,11 +258,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) { } for (Runnable tRunnable : GregTechAPI.sBeforeGTPreload) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPreload", e); - } + tRunnable.run(); } GTPreLoad.getConfiguration(aEvent.getModConfigurationDirectory()); @@ -319,11 +315,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) { GTUIInfos.init(); for (Runnable tRunnable : GregTechAPI.sAfterGTPreload) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPreload", e); - } + tRunnable.run(); } if (FMLCommonHandler.instance() @@ -343,11 +335,7 @@ public void onLoad(FMLInitializationEvent aEvent) { } for (Runnable tRunnable : GregTechAPI.sBeforeGTLoad) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTLoad", e); - } + tRunnable.run(); } if (Forestry.isModLoaded()) @@ -395,11 +383,7 @@ public boolean test(ItemStack stack) { GTLog.ore.println("GTMod: Load-Phase finished!"); for (Runnable tRunnable : GregTechAPI.sAfterGTLoad) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sAfterGTLoad", e); - } + tRunnable.run(); } } @@ -411,11 +395,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { // Seems only used by GGFab so far for (Runnable tRunnable : GregTechAPI.sBeforeGTPostload) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPostload", e); - } + tRunnable.run(); } gregtechproxy.onPostLoad(); @@ -566,11 +546,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { GTLog.out.println("GTMod: PostLoad-Phase finished!"); GTLog.ore.println("GTMod: PostLoad-Phase finished!"); for (Runnable tRunnable : GregTechAPI.sAfterGTPostload) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPostload", e); - } + tRunnable.run(); } GTPostLoad.addFakeRecipes(); @@ -601,11 +577,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { public void onLoadComplete(FMLLoadCompleteEvent aEvent) { gregtechproxy.onLoadComplete(); for (Runnable tRunnable : GregTechAPI.sGTCompleteLoad) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sGTCompleteLoad", e); - } + tRunnable.run(); } GregTechAPI.sGTCompleteLoad = null; GregTechAPI.sFullLoadFinished = true; @@ -625,11 +597,7 @@ public void onServerAboutToStart(FMLServerAboutToStartEvent aEvent) { public void onServerStarting(FMLServerStartingEvent aEvent) { for (Runnable tRunnable : GregTechAPI.sBeforeGTServerstart) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstart", e); - } + tRunnable.run(); } gregtechproxy.onServerStarting(); @@ -760,11 +728,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) { GTLog.ore.println("GTMod: ServerStarting-Phase finished!"); for (Runnable tRunnable : GregTechAPI.sAfterGTServerstart) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstart", e); - } + tRunnable.run(); } aEvent.registerServerCommand(new GTCommand()); @@ -803,36 +767,24 @@ public void doSonictronSound(ItemStack aStack, World aWorld, double aX, double a public void onIDChangingEvent(FMLModIdMappingEvent aEvent) { GTUtility.reInit(); GTRecipe.reInit(); - try { - for (Map gt_itemStackMap : GregTechAPI.sItemStackMappings) { - GTUtility.reMap(gt_itemStackMap); - } - for (SetMultimap gt_itemStackMap : GregTechAPI.itemStackMultiMaps) { - GTUtility.reMap(gt_itemStackMap); - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); + for (Map gt_itemStackMap : GregTechAPI.sItemStackMappings) { + GTUtility.reMap(gt_itemStackMap); + } + for (SetMultimap gt_itemStackMap : GregTechAPI.itemStackMultiMaps) { + GTUtility.reMap(gt_itemStackMap); } } @Mod.EventHandler public void onServerStopping(FMLServerStoppingEvent aEvent) { for (Runnable tRunnable : GregTechAPI.sBeforeGTServerstop) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstop", e); - } + tRunnable.run(); } gregtechproxy.onServerStopping(); for (Runnable tRunnable : GregTechAPI.sAfterGTServerstop) { - try { - tRunnable.run(); - } catch (Throwable e) { - GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstop", e); - } + tRunnable.run(); } // Interrupt IDLE Threads to close down cleanly RunnableMachineUpdate.shutdownExecutorService(); From 5edc0405d5d65390d99a4be1537d542d8e8c82c2 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 20 Dec 2024 16:20:00 -0500 Subject: [PATCH 4/5] minor changes --- src/main/java/gregtech/common/GTProxy.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index 63b23d926d6..1ea08f723a1 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -1336,7 +1336,9 @@ public void onServerStarting() { try { GregTechAPI.METATILEENTITIES[i].onServerStart(); } catch (Throwable e) { - GT_FML_LOGGER.error("Could not call onServerStart MTE " + GregTechAPI.METATILEENTITIES[i], e); + throw new RuntimeException( + "Could not call onServerStart MTE " + GregTechAPI.METATILEENTITIES[i], + e); } } } @@ -1379,7 +1381,9 @@ public void onServerStopping() { try { GregTechAPI.METATILEENTITIES[i].onWorldSave(tSaveDirectory); } catch (Throwable e) { - GT_FML_LOGGER.error("Could call onWorldSave for MTE " + GregTechAPI.METATILEENTITIES[i], e); + throw new RuntimeException( + "Could not call onWorldSave for MTE " + GregTechAPI.METATILEENTITIES[i], + e); } } } @@ -2130,8 +2134,9 @@ public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) { try { GregTechAPI.METATILEENTITIES[i].onWorldLoad(tSaveDiretory); } catch (Throwable e) { - GT_FML_LOGGER - .error("Could call onWorldLoad for MTE " + GregTechAPI.METATILEENTITIES[i], e); + throw new RuntimeException( + "Could not call onWorldLoad for MTE " + GregTechAPI.METATILEENTITIES[i], + e); } } } From 4d239419422300480e4211c2d694198b2b59f6fe Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 14 Jan 2025 04:36:05 -0500 Subject: [PATCH 5/5] reverted bad try-catch removal --- .../metatileentity/BaseMetaPipeEntity.java | 151 +++++++++--------- .../machines/basic/MTEScanner.java | 40 +++-- 2 files changed, 102 insertions(+), 89 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index b6041126e29..d2d9f429b72 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -43,6 +43,7 @@ import gregtech.api.net.GTPacketTileEntity; import gregtech.api.objects.GTItemStack; import gregtech.api.util.CoverBehaviorBase; +import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; @@ -176,92 +177,96 @@ public void updateEntity() { } else { tTime = 0; } - - if (hasValidMetaTileEntity()) { - if (mTickTimer++ == 0) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - if (isServerSide()) checkDropCover(); - else { - requestCoverDataIfNeeded(); + try { + if (hasValidMetaTileEntity()) { + if (mTickTimer++ == 0) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + if (isServerSide()) checkDropCover(); + else { + requestCoverDataIfNeeded(); + } + worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); + mMetaTileEntity.onFirstTick(this); + if (!hasValidMetaTileEntity()) return; } - worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); - mMetaTileEntity.onFirstTick(this); - if (!hasValidMetaTileEntity()) return; - } - if (isClientSide()) { - if (mColor != oColor) { - mMetaTileEntity.onColorChangeClient(oColor = mColor); - issueTextureUpdate(); - } + if (isClientSide()) { + if (mColor != oColor) { + mMetaTileEntity.onColorChangeClient(oColor = mColor); + issueTextureUpdate(); + } - if (mNeedsUpdate) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - mNeedsUpdate = false; - } - } - if (isServerSide() && mTickTimer > 10) { - if (!doCoverThings()) return; - - final byte oldConnections = mConnections; - // Mask-out connection direction bits to keep only Foam related connections - mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); - // If foam not hardened, tries roll chance to harden - if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM - && getRandomNumber(1000) == 0) { - mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) - | IConnectable.HAS_HARDENEDFOAM); + if (mNeedsUpdate) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + mNeedsUpdate = false; + } } - if (mTickTimer > 12 && oldConnections != mConnections) - GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord); - } - mMetaTileEntity.onPreTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - if (isServerSide()) { - if (mTickTimer == 10) { - updateCoverBehavior(); - issueBlockUpdate(); - joinEnet(); + if (isServerSide() && mTickTimer > 10) { + if (!doCoverThings()) return; + + final byte oldConnections = mConnections; + // Mask-out connection direction bits to keep only Foam related connections + mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); + // If foam not hardened, tries roll chance to harden + if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM + && getRandomNumber(1000) == 0) { + mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) + | IConnectable.HAS_HARDENEDFOAM); + } + if (mTickTimer > 12 && oldConnections != mConnections) + GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord); } + mMetaTileEntity.onPreTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + if (isServerSide()) { + if (mTickTimer == 10) { + updateCoverBehavior(); + issueBlockUpdate(); + joinEnet(); + } - if (xCoord != oX || yCoord != oY || zCoord != oZ) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - issueClientUpdate(); - clearTileEntityBuffer(); + if (xCoord != oX || yCoord != oY || zCoord != oZ) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + issueClientUpdate(); + clearTileEntityBuffer(); + } } - } - mMetaTileEntity.onPostTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; + mMetaTileEntity.onPostTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; - if (isServerSide()) { - if (mTickTimer % 10 == 0) { - sendClientData(); - } + if (isServerSide()) { + if (mTickTimer % 10 == 0) { + sendClientData(); + } - if (mTickTimer > 10) { - if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); - byte tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); - if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); - tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) - | ((mSidedRedstone[2] > 0) ? 4 : 0) - | ((mSidedRedstone[3] > 0) ? 8 : 0) - | ((mSidedRedstone[4] > 0) ? 16 : 0) - | ((mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); - } + if (mTickTimer > 10) { + if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); + byte tData = mMetaTileEntity.getUpdateData(); + if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); + if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); + tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) + | ((mSidedRedstone[2] > 0) ? 4 : 0) + | ((mSidedRedstone[3] > 0) ? 8 : 0) + | ((mSidedRedstone[4] > 0) ? 16 : 0) + | ((mSidedRedstone[5] > 0) ? 32 : 0)); + if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); + } - if (mNeedsBlockUpdate) { - updateNeighbours(mStrongRedstone, oStrongRedstone); - oStrongRedstone = mStrongRedstone; - mNeedsBlockUpdate = false; + if (mNeedsBlockUpdate) { + updateNeighbours(mStrongRedstone, oStrongRedstone); + oStrongRedstone = mStrongRedstone; + mNeedsBlockUpdate = false; + } } } + } catch (Throwable e) { + e.printStackTrace(); + e.printStackTrace(GTLog.err); } if (isServerSide() && hasTimeStatisticsStarted && hasValidMetaTileEntity()) { diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java b/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java index 2999dbc02e1..fba31c0fa0c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEScanner.java @@ -1,5 +1,6 @@ package gregtech.common.tileentities.machines.basic; +import static gregtech.api.enums.GTValues.D1; import static gregtech.api.enums.Mods.GalacticraftCore; import static gregtech.api.enums.Mods.GalacticraftMars; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_SCANNER; @@ -44,6 +45,7 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.render.TextureFactory; import gregtech.api.util.AssemblyLineUtils; +import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; @@ -128,26 +130,32 @@ public int checkRecipe() { this.mOutputBlocked += 1; } else if ((GTUtility.isStackValid(aStack)) && (aStack.stackSize > 0)) { if ((getFillableStack() != null) && (getFillableStack().containsFluid(Materials.Honey.getFluid(100L)))) { - IIndividual tIndividual = AlleleManager.alleleRegistry.getIndividual(aStack); - if (tIndividual != null) { - if (tIndividual.analyze()) { - getFillableStack().amount -= 100; + try { + IIndividual tIndividual = AlleleManager.alleleRegistry.getIndividual(aStack); + if (tIndividual != null) { + if (tIndividual.analyze()) { + getFillableStack().amount -= 100; + this.mOutputItems[0] = GTUtility.copyOrNull(aStack); + aStack.stackSize = 0; + NBTTagCompound tNBT = new NBTTagCompound(); + tIndividual.writeToNBT(tNBT); + this.mOutputItems[0].setTagCompound(tNBT); + calculateOverclockedNess(2, 500); + // In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + return 2; + } this.mOutputItems[0] = GTUtility.copyOrNull(aStack); aStack.stackSize = 0; - NBTTagCompound tNBT = new NBTTagCompound(); - tIndividual.writeToNBT(tNBT); - this.mOutputItems[0].setTagCompound(tNBT); - calculateOverclockedNess(2, 500); - // In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + this.mMaxProgresstime = 1; + this.mEUt = 1; return 2; } - this.mOutputItems[0] = GTUtility.copyOrNull(aStack); - aStack.stackSize = 0; - this.mMaxProgresstime = 1; - this.mEUt = 1; - return 2; + } catch (Throwable e) { + if (D1) { + e.printStackTrace(GTLog.err); + } } } if (ItemList.IC2_Crop_Seeds.isStackEqual(aStack, true, true)) {