aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2018-02-14 18:23:41 +1000
committerJordan Byrne <draknyte1@hotmail.com>2018-02-14 18:23:41 +1000
commit6858a01769a5875e722eca0d309dd2d020d331d1 (patch)
treec9f511320e1c5fdd0e456d619dd38be2a03bc132 /src/Java/gtPlusPlus/xmod/gregtech
parent6bd0c3409c4b1820fc40afabc4d55405b22e1c08 (diff)
downloadGT5-Unofficial-6858a01769a5875e722eca0d309dd2d020d331d1.tar.gz
GT5-Unofficial-6858a01769a5875e722eca0d309dd2d020d331d1.tar.bz2
GT5-Unofficial-6858a01769a5875e722eca0d309dd2d020d331d1.zip
$ Fixed Tree Farm not using internal power storage.
$ Improved mapping of log cutting targets.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java78
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java40
2 files changed, 77 insertions, 41 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
index c8ef2d3ad1..3d2b227d38 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
@@ -3,6 +3,7 @@ package gtPlusPlus.xmod.gregtech.common.helpers;
import static gtPlusPlus.core.lib.CORE.ConfigSwitches.enableTreeFarmerParticles;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -404,8 +405,8 @@ public class TreeFarmHelper {
if (((i != -7) && (i != 7)) && ((j != -7) && (j != 7))) {
if (h == 1) {
if (TreeFarmHelper.isWoodLog(aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j))) {
- Logger.INFO("Found a Log");
- return new BlockPos(xDir + i, h, zDir + j);
+ //Logger.INFO("Found a Log");
+ return new BlockPos(aBaseMetaTileEntity.getXCoord()+xDir + i, aBaseMetaTileEntity.getYCoord()+h, aBaseMetaTileEntity.getZCoord()+zDir + j);
}
}
}
@@ -414,59 +415,70 @@ public class TreeFarmHelper {
}
return null;
}
-
-
+
+
public static ItemStack[] findTreeFromBase(World world, BlockPos h) {
- AutoMap<BlockPos> mResultsAroundBaseLayer = findTreeViaBranching(world, h);
- AutoMap<AutoMap<BlockPos>> mOtherResults = new AutoMap<AutoMap<BlockPos>>();
- mOtherResults.put(mResultsAroundBaseLayer);
+ Map<String, BlockPos> mResultsAroundBaseLayer = findTreeViaBranching(world, h);
+ Map<String, Map<String, BlockPos>> mOtherResults = new ConcurrentHashMap<String, Map<String, BlockPos>>();
+ String hash = Utils.calculateChecksumMD5(mResultsAroundBaseLayer);
+ mOtherResults.put(hash, mResultsAroundBaseLayer);
+ Logger.INFO("Initial Search found "+mResultsAroundBaseLayer.size()+" blocks to search around.");
for (BlockPos j : mResultsAroundBaseLayer.values()) {
- Logger.INFO("Branching.");
- mOtherResults.put(findTreeViaBranching(world, j));
+ Map<String, BlockPos> x = findTreeViaBranching(world, j);
+ hash = Utils.calculateChecksumMD5(x);
+ if (hash != null && !mOtherResults.containsKey(hash)) {
+ Logger.INFO("Branching.");
+ mOtherResults.put(hash, x);
+ }
}
if (mOtherResults.size() > 0) {
TreeCutter harvestManager = new TreeCutter(world);
- for (AutoMap<BlockPos> a : mOtherResults.values()) {
+ for (Map<String, BlockPos> a : mOtherResults.values()) {
for (BlockPos p : a.values()) {
harvestManager.queue(p);
}
}
-
if (harvestManager.isValid) {
- Logger.INFO("Returning Drops from harvestManager Queue.");
- return harvestManager.getDrops();
+ ItemStack[] loot = harvestManager.getDrops();
+ if (loot.length > 0) {
+ Logger.INFO("Returning Drops from harvestManager Queue.");
+ return loot;
+ }
}
-
}
-
return new ItemStack[] {};
-
}
- public static AutoMap<BlockPos> findTreeViaBranching(World world, BlockPos h) {
- AutoMap<BlockPos> results = new AutoMap<BlockPos>();
+ public static Map<String, BlockPos> findTreeViaBranching(World world, BlockPos h) {
+ Map<String, BlockPos> results = new ConcurrentHashMap<String, BlockPos>();
final Block block = world.getBlock(h.xPos, h.yPos, h.zPos);
+ Logger.INFO("Searching around "+h.getLocationString());
int xRel = h.xPos, yRel = h.yPos, zRel = h.zPos;
- if (TreeFarmHelper.isWoodLog(block)) {
- for (int a=-2;a<2;a++) {
- for (int b=-2;b<2;b++) {
- for (int c=-2;c<2;c++) {
- //Check block
- Block log = world.getBlock(xRel+a, yRel+b, zRel+c);
- if (TreeFarmHelper.isWoodLog(log) || TreeFarmHelper.isLeaves(log)) {
- results.put(new BlockPos(xRel+a, yRel+b, zRel+c));
+ //if (TreeFarmHelper.isWoodLog(block)) {
+ for (int a=-2;a<2;a++) {
+ for (int b=-2;b<2;b++) {
+ for (int c=-2;c<2;c++) {
+ //Check block
+ //Logger.INFO("Looking at X: "+(xRel+a)+" | Y: "+(yRel+b)+" | Z: "+(zRel+c));
+ Block log = world.getBlock(xRel+a, yRel+b, zRel+c);
+ BlockPos P = new BlockPos(xRel+a, yRel+b, zRel+c);
+ String hash = Utils.calculateChecksumMD5(P);
+ if (TreeFarmHelper.isWoodLog(log) || TreeFarmHelper.isLeaves(log)) {
+ if (hash != null && !results.containsKey(hash)) {
+ results.put(hash, P);
}
}
}
}
}
+ //}
if (results.isEmpty()) {
- Logger.INFO("Returning Empty Iteration.");
- return null;
+ //Logger.INFO("Returning Empty Branch Iteration.");
+ return new HashMap<String, BlockPos>();
}
else {
- Logger.INFO("Returning Valid Iteration.");
+ Logger.INFO("Returning Valid Branch Iteration.");
return results;
}
}
@@ -489,9 +501,10 @@ public class TreeFarmHelper {
}
public boolean queue(BlockPos pos) {
- if (isValid) {
+ if (isValid && pos != null) {
+ Logger.INFO("Queued: "+pos.getLocationString());
String hash = Utils.calculateChecksumMD5(pos);
- if ((pos != null && hash != null) && !mQueue.containsKey(hash)) {
+ if (hash != null && !mQueue.containsKey(hash)) {
mQueue.put(hash, pos);
return true;
}
@@ -501,6 +514,7 @@ public class TreeFarmHelper {
private boolean emptyQueue() {
if (isValid) {
+ Logger.INFO("Emptying Queue.");
if (this.mQueue.size() > 0) {
int totalRemoved = 0;
for (BlockPos h : mQueue.values()) {
@@ -512,7 +526,7 @@ public class TreeFarmHelper {
mDrops.put(drops);
//Remove drop that was added to the bus.
mWorld.setBlockToAir(h.xPos, h.yPos, h.zPos);
- new BlockBreakParticles(mWorld, h.xPos, h.yPos, h.zPos, block);
+ //new BlockBreakParticles(mWorld, h.xPos, h.yPos, h.zPos, block);
totalRemoved++;
}
}
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java
index 30a4035366..6cb0e4ebb3 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java
@@ -85,6 +85,27 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
}
@Override
+ public boolean drainEnergyInput(final long aEU) {
+ if (aEU <= 0L) {
+ return true;
+ }
+
+ //Special Override, so that this function uses internally stored power first.
+ if (this.getEUVar() >= aEU) {
+ this.setEUVar(this.getEUVar()-aEU);
+ return true;
+ }
+
+ for (final GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) {
+ if (isValidMetaTileEntity((MetaTileEntity) tHatch)
+ && tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU, false)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) {
if (aSide == 0) {
return new ITexture[]{new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Acacia_Log)};
@@ -195,7 +216,7 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
@Override
public boolean onRunningTick(final ItemStack aStack) {
//Logger.INFO("s");
-
+
return super.onRunningTick(aStack);
}
@@ -204,8 +225,8 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
//Do Main Multi Logic first
super.onPostTick(aBaseMetaTileEntity, aTick);
- //Do Tree Farm logic next on server side
- if (aBaseMetaTileEntity.isServerSide()) {
+ //Do Tree Farm logic next on server side, once per second
+ if (aBaseMetaTileEntity.isServerSide() && (aTick % 20 == 0)) {
//Simple Repairs for a simple machine
if (isCurrentlyWorking()) {
@@ -229,16 +250,17 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase
}
}
-
+
//Try Work
- BlockPos t;
- if ((t = TreeFarmHelper.checkForLogsInGrowArea(this.getBaseMetaTileEntity())) != null) {
- Logger.INFO("Lets try find new logs/branches.");
- TreeFarmHelper.findTreeFromBase(this.getBaseMetaTileEntity().getWorld(), t);
+ if (this.drainEnergyInput(32)) {
+ BlockPos t;
+ if ((t = TreeFarmHelper.checkForLogsInGrowArea(this.getBaseMetaTileEntity())) != null) {
+ //Logger.INFO("Lets try find new logs/branches.");
+ TreeFarmHelper.findTreeFromBase(this.getBaseMetaTileEntity().getWorld(), t);
+ }
}
-
}
}