aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSphyix <masifede2@gmail.com>2021-11-21 21:12:27 +0100
committerSphyix <masifede2@gmail.com>2021-11-21 21:12:27 +0100
commit46218deff159fc88d2a746dd93d4d827b2dee765 (patch)
treeef0d47037ba0b5d71ca90bda58b6bd0155c18f08
parent656c9cdc5aa57c66ebe3e4cf5f09e0a8466531d7 (diff)
downloadGT5-Unofficial-46218deff159fc88d2a746dd93d4d827b2dee765.tar.gz
GT5-Unofficial-46218deff159fc88d2a746dd93d4d827b2dee765.tar.bz2
GT5-Unofficial-46218deff159fc88d2a746dd93d4d827b2dee765.zip
rewrite, more readable
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
index 2b8d1d9e03..4990c49709 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
@@ -47,9 +47,9 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
public static TreeGenerator mTreeData;
private int mCasing;
private IStructureDefinition<GregtechMetaTileEntityTreeFarm> STRUCTURE_DEFINITION = null;
-
+
static {
- mTreeData = new TreeGenerator();
+ mTreeData = new TreeGenerator();
}
public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) {
@@ -58,12 +58,11 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15);
}
-/*
+ /*
* Static thread for Fake World Handling
*/
-
private static ScheduledExecutorService executor;
private static ThreadFakeWorldGenerator aThread;
@@ -72,24 +71,24 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15);
mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15);
-if (executor == null || mTreeData == null) {
+ if (executor == null || mTreeData == null) {
if (executor == null) {
executor = Executors.newScheduledThreadPool(10);
}
- if (executor != null) {
+ if (executor != null) {
if (aThread == null) {
- aThread = new ThreadFakeWorldGenerator();
+ aThread = new ThreadFakeWorldGenerator();
executor.scheduleAtFixedRate(aThread, 0, 1, TimeUnit.SECONDS);
while (aThread.mGenerator == null) {
if (aThread.mGenerator != null) {
break;
}
- }
+ }
if (aThread.mGenerator != null) {
mTreeData = aThread.mGenerator;
}
}
- }
+ }
}
}
@@ -127,7 +126,7 @@ if (executor == null || mTreeData == null) {
}
public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing,
- final byte aColorIndex, final boolean aActive, final boolean aRedstone) {
+ final byte aColorIndex, final boolean aActive, final boolean aRedstone) {
if (aSide == aFacing) {
return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID),
new GT_RenderedTexture((IIconContainer) (aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced))};
@@ -150,7 +149,7 @@ if (executor == null || mTreeData == null) {
return "VacuumFreezer";
}
- public GT_Recipe.GT_Recipe_Map getRecipeMap() {
+ public GT_Recipe.GT_Recipe_Map getRecipeMap() {
return null;
}
@@ -192,15 +191,14 @@ if (executor == null || mTreeData == null) {
}
-
int aChance = MathUtils.randInt(0, 10);
AutoMap<ItemStack> aOutputs = new AutoMap<ItemStack>();
try {
if (aChance < 8) {
//1% Chance per Tick
- for (int u=0; u<(Math.max(4, (MathUtils.randInt((3*tTier), 100)*tTier*tTier)/14));u++) {
- aOutputs = mTreeData.generateOutput(0);
+ for (int u = 0; u < (Math.max(4, (MathUtils.randInt((3 * tTier), 100) * tTier * tTier) / 14)); u++) {
+ aOutputs = mTreeData.generateOutput(0);
if (aOutputs.size() > 0) {
ItemStack aLeaves = ItemUtils.getSimpleStack(Blocks.leaves);
@@ -211,17 +209,15 @@ if (executor == null || mTreeData == null) {
}
}
this.updateSlots();
- }
- }
+ }
+ }
- }
- }
- catch (Throwable t) {
+ }
+ } catch (Throwable t) {
t.printStackTrace();
}
return true;
- }
- else {
+ } else {
return false;
}
//return this.checkRecipeGeneric(4, 100, 100);
@@ -299,9 +295,9 @@ if (executor == null || mTreeData == null) {
ItemStack invItem = this.mInventory[1];
if (invItem == null) {
for (GT_MetaTileEntity_Hatch_InputBus mInputBus : this.mInputBusses) {
- for (int i = 0; i < mInputBus.mInventory.length ; i++) {
+ for (int i = 0; i < mInputBus.mInventory.length; i++) {
ItemStack uStack = mInputBus.mInventory[i];
- if(uStack != null && TreeFarmHelper.isCorrectPart(uStack)) {
+ if (uStack != null && TreeFarmHelper.isCorrectPart(uStack)) {
this.setGUIItemStack(uStack);
return true;
}
@@ -311,34 +307,38 @@ if (executor == null || mTreeData == null) {
return false;
}
+ public boolean tryDamageTool(ItemStack invItem) {
+ if (invItem != null && invItem.getItem() instanceof GT_MetaGenerated_Tool) {
+ long aDmg = GT_MetaGenerated_Tool.getToolDamage(invItem);
+ long aDmgMax = GT_MetaGenerated_Tool.getToolMaxDamage(invItem);
+ if (aDmg < aDmgMax && GT_MetaGenerated_Tool.getPrimaryMaterial(invItem) != Materials._NULL) {
+ return GT_ModHandler.damageOrDechargeItem(invItem, 1, 0, null);
+ }
+ }
+ return false;
+ }
+
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
replaceTool();
ItemStack invItem = this.mInventory[1];
- if (invItem != null && aTick % 200 == 0 && this.getBaseMetaTileEntity().isServerSide()) {
- if (isCorrectMachinePart(invItem)) {
- boolean didElectricDamage = true;
- if (EU.isElectricItem(invItem)) {
- if (!GT_ModHandler.damageOrDechargeItem(invItem, 2, 0, null)) {
- didElectricDamage = false;
- addOutput(invItem);
- this.mInventory[1] = null;
- if(!replaceTool())
- this.getBaseMetaTileEntity().disableWorking();
- }
- }
+ if (invItem != null && aTick % 200 == 0 && this.getBaseMetaTileEntity().isServerSide() && isCorrectMachinePart(invItem)) {
- if (!didElectricDamage && invItem.getItem() instanceof GT_MetaGenerated_Tool) {
- long aDmg = GT_MetaGenerated_Tool.getToolDamage(invItem);
- long aDmgMax = GT_MetaGenerated_Tool.getToolMaxDamage(invItem);
- if (aDmg < aDmgMax && GT_MetaGenerated_Tool.getPrimaryMaterial(invItem) != Materials._NULL) {
- GT_ModHandler.damageOrDechargeItem(invItem, 1, 0, null);
+ if (!tryDamageTool(invItem)) {
+ if (!invItem.getItem().isDamageable()) { //item durability is <= 0
+ this.mInventory[1] = null;
+ if (!replaceTool()) {
+ this.getBaseMetaTileEntity().disableWorking();
}
- else if (aDmg >= aDmgMax) {
- this.mInventory[1] = null;
- replaceTool();
+ tryDamageTool(invItem);
+ } else {
+ addOutput(invItem);
+ this.mInventory[1] = null;
+ if (!replaceTool()) {
+ this.getBaseMetaTileEntity().disableWorking();
}
+ tryDamageTool(invItem);
}
}
}