Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up Throwable try catches #3280

Merged
merged 14 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 158 additions & 163 deletions src/main/java/bartworks/util/BWUtil.java

Large diffs are not rendered by default.

80 changes: 16 additions & 64 deletions src/main/java/gregtech/GTMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
}

for (Runnable tRunnable : GregTechAPI.sBeforeGTPreload) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

GTPreLoad.getConfiguration(aEvent.getModConfigurationDirectory());
Expand Down Expand Up @@ -314,11 +310,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
GTUIInfos.init();

for (Runnable tRunnable : GregTechAPI.sAfterGTPreload) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

if (FMLCommonHandler.instance()
Expand All @@ -333,11 +325,7 @@ public void onLoad(FMLInitializationEvent aEvent) {
}

for (Runnable tRunnable : GregTechAPI.sBeforeGTLoad) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

if (Forestry.isModLoaded())
Expand Down Expand Up @@ -385,11 +373,7 @@ public boolean test(ItemStack stack) {
GTLog.ore.println("GTMod: Load-Phase finished!");

for (Runnable tRunnable : GregTechAPI.sAfterGTLoad) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}
}

Expand All @@ -401,11 +385,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {

// Seems only used by GGFab so far
for (Runnable tRunnable : GregTechAPI.sBeforeGTPostload) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

gregtechproxy.onPostLoad();
Expand Down Expand Up @@ -556,11 +536,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) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}
GTPostLoad.addFakeRecipes();

Expand Down Expand Up @@ -591,11 +567,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {
public void onLoadComplete(FMLLoadCompleteEvent aEvent) {
gregtechproxy.onLoadComplete();
for (Runnable tRunnable : GregTechAPI.sGTCompleteLoad) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}
GregTechAPI.sGTCompleteLoad = null;
GregTechAPI.sFullLoadFinished = true;
Expand All @@ -615,11 +587,7 @@ public void onServerAboutToStart(FMLServerAboutToStartEvent aEvent) {
public void onServerStarting(FMLServerStartingEvent aEvent) {

for (Runnable tRunnable : GregTechAPI.sBeforeGTServerstart) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

gregtechproxy.onServerStarting();
Expand Down Expand Up @@ -750,11 +718,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
GTLog.ore.println("GTMod: ServerStarting-Phase finished!");

for (Runnable tRunnable : GregTechAPI.sAfterGTServerstart) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

aEvent.registerServerCommand(new GTCommand());
Expand Down Expand Up @@ -793,36 +757,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<? extends ItemHolder, ?> 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<? extends ItemHolder, ?> 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) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}

gregtechproxy.onServerStopping();

for (Runnable tRunnable : GregTechAPI.sAfterGTServerstop) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
}
tRunnable.run();
}
// Interrupt IDLE Threads to close down cleanly
RunnableMachineUpdate.shutdownExecutorService();
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/gregtech/api/items/MetaBaseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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;
Expand Down Expand Up @@ -146,7 +147,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;
}
Expand All @@ -168,7 +169,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;
}
Expand Down Expand Up @@ -200,7 +201,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;
}
Expand All @@ -214,7 +215,7 @@ public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer a
if (tList != null) for (IItemBehaviour<MetaBaseItem> 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;
}
Expand Down
151 changes: 73 additions & 78 deletions src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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;
Expand Down Expand Up @@ -177,96 +176,92 @@ public void updateEntity() {
} else {
tTime = 0;
}
try {
RecursivePineapple marked this conversation as resolved.
Show resolved Hide resolved
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()) {
Expand Down
Loading
Loading