From bd0485d62fd1f249afe9b26a318e0092035f73e1 Mon Sep 17 00:00:00 2001 From: DarkholmeTenk Date: Tue, 25 Feb 2014 07:58:46 +0000 Subject: [PATCH] Bit more work on the tree farm, balancing, cosmetics and recipes to do! --- src/cr0s/WarpDrive/WarpDriveConfig.java | 64 ++++++++----- .../machines/TileEntityAbstractMiner.java | 22 +++-- .../machines/TileEntityLaserTreeFarm.java | 96 ++++++++++++++++--- .../machines/TileEntityMiningLaser.java | 7 +- src/cr0s/WarpDrive/machines/WarpChunkTE.java | 1 + 5 files changed, 140 insertions(+), 50 deletions(-) diff --git a/src/cr0s/WarpDrive/WarpDriveConfig.java b/src/cr0s/WarpDrive/WarpDriveConfig.java index da74e597..e1c3ab3e 100644 --- a/src/cr0s/WarpDrive/WarpDriveConfig.java +++ b/src/cr0s/WarpDrive/WarpDriveConfig.java @@ -28,7 +28,7 @@ public class WarpDriveConfig public int[] IC2_Air; public int[] IC2_Empty; public int CC_Computer = 0, CC_peripheral = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0, GT_Ores = 0, GT_Granite = 0, GT_Machine = 0, ASP = 0, AS_Turbine = 0, ICBM_Machine = 0, ICBM_Missile = 0, MFFS_Field = 0; - public Set SpaceHelmets, Jetpacks, MinerOres, MinerLogs, scannerIgnoreBlocks; + public Set SpaceHelmets, Jetpacks, MinerOres, MinerLogs, MinerLeaves, scannerIgnoreBlocks; private Class AEBlocks; private Class AEMaterials; private Class AEItems; @@ -232,6 +232,7 @@ public class WarpDriveConfig Jetpacks = new HashSet(); MinerOres = new HashSet(); MinerLogs = new HashSet(); + MinerLeaves = new HashSet(); scannerIgnoreBlocks = new HashSet(); config.load(); coreID = config.getBlock("core", 500).getInt(); @@ -294,30 +295,7 @@ public class WarpDriveConfig MinerOres.add(Block.web.blockID); MinerOres.add(Block.fence.blockID); //MinerOres.add(Block.torchWood.blockID); - - String[] oreNames = OreDictionary.getOreNames(); - for(String oreName: oreNames) - { - if(oreName.substring(0,3).equals("ore")) - { - ArrayList item = OreDictionary.getOres(oreName); - for(ItemStack i: item) - { - MinerOres.add(i.itemID); - WarpDrive.debugPrint("WD: Added ore ID: "+i.itemID); - } - } - if(oreName.contains("log") || oreName.contains("Log")) - { - ArrayList item = OreDictionary.getOres(oreName); - for(ItemStack i: item) - { - MinerLogs.add(i.itemID); - WarpDrive.debugPrint("WD: Added log ID: "+i.itemID); - } - } - } - + LoadOreDict(); // Ignore WarpDrive blocks (which potentially will be duplicated by cheaters using ship scan/deploy) scannerIgnoreBlocks.add(coreID); scannerIgnoreBlocks.add(controllerID); @@ -335,6 +313,42 @@ public class WarpDriveConfig loadWarpDriveConfig(); config.save(); } + + private void LoadOreDict() + { + String[] oreNames = OreDictionary.getOreNames(); + for(String oreName: oreNames) + { + String lowerOreName = oreName.toLowerCase(); + if(oreName.substring(0,3).equals("ore")) + { + ArrayList item = OreDictionary.getOres(oreName); + for(ItemStack i: item) + { + MinerOres.add(i.itemID); + WarpDrive.debugPrint("WD: Added ore ID: "+i.itemID); + } + } + if(lowerOreName.contains("log")) + { + ArrayList item = OreDictionary.getOres(oreName); + for(ItemStack i: item) + { + MinerLogs.add(i.itemID); + WarpDrive.debugPrint("WD: Added log ID: "+i.itemID); + } + } + if(lowerOreName.contains("leave") || lowerOreName.contains("leaf")) + { + ArrayList item = OreDictionary.getOres(oreName); + for(ItemStack i: item) + { + MinerLeaves.add(i.itemID); + WarpDrive.debugPrint("WD: Added leaf ID: "+i.itemID); + } + } + } + } private void LoadIC2() { diff --git a/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java b/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java index df8a23d8..26da3c77 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java +++ b/src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java @@ -94,7 +94,7 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr Block block = Block.blocksList[blockID]; if (block == null) return null; - if (silkTouch) + if (silkTouch()) { if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta)) { @@ -131,16 +131,16 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr //GETTERSETTERS - protected boolean silkTouch() - { - return silkTouch; - } - protected int fortune() { return fortuneLevel; } + protected boolean silkTouch() + { + return silkTouch; + } + protected boolean silkTouch(boolean b) { silkTouch = canSilktouch && b; @@ -451,6 +451,8 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr protected void defineMiningArea(int minX, int minZ, int maxX, int maxZ) { + if(worldObj == null) + return; ChunkCoordIntPair a = worldObj.getChunkFromBlockCoords(minX, minZ).getChunkCoordIntPair(); ChunkCoordIntPair b = worldObj.getChunkFromBlockCoords(maxX, maxZ).getChunkCoordIntPair(); if(a.equals(minChunk)) @@ -503,6 +505,14 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr } //OVERRIDES + @Override + public void updateEntity() + { + if(shouldChunkLoad() != areChunksLoaded) + refreshLoading(); + + } + @Override public float getPowerDrainPerTick() { diff --git a/src/cr0s/WarpDrive/machines/TileEntityLaserTreeFarm.java b/src/cr0s/WarpDrive/machines/TileEntityLaserTreeFarm.java index a7899dda..ad0c23a3 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityLaserTreeFarm.java +++ b/src/cr0s/WarpDrive/machines/TileEntityLaserTreeFarm.java @@ -2,6 +2,7 @@ package cr0s.WarpDrive.machines; import java.util.ArrayList; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; import cr0s.WarpDrive.Vector3; import cr0s.WarpDrive.WarpDrive; @@ -20,10 +21,14 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements Boolean active = false; private int mode = 0; + private boolean doLeaves = false; private final int defSize = 8; - private final int scanWait = 20; - private final int mineWait = 20; + private final int scanWait = 40; + private final int mineWait = 4; + private int delayMul = 4; + + private int totalHarvested=0; private int scan=0; private int xSize = defSize; @@ -36,7 +41,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements "start", "stop", "area", - "silktouch", + "leaves", + "silkTouch", "state" }; @@ -48,6 +54,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements @Override public void updateEntity() { + super.updateEntity(); + if(active) { if(mode == 0) @@ -63,7 +71,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements } else { - if(++scan >= mineWait) + if(++scan >= mineWait * delayMul) { scan = 0; int cost = calculateBlockCost(); @@ -76,17 +84,23 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements } Vector3 pos = logs.get(logIndex); int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ()); - if(WarpDriveConfig.i.MinerLogs.contains(blockID)) + if(isLog(blockID) || (doLeaves && isLeaf(blockID))) { + delayMul = 1; if(isRoomForHarvest()) { if(collectEnergyPacketFromBooster(cost,false)) { + if(isLog(blockID)) + delayMul = 4; + totalHarvested++; harvestBlock(pos); } else return; } + else + return; } logIndex++; } @@ -100,6 +114,11 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements return WarpDriveConfig.i.MinerLogs.contains(blockID); } + private boolean isLeaf(int blockID) + { + return WarpDriveConfig.i.MinerLeaves.contains(blockID); + } + private void addTree(ArrayList list,Vector3 newTree) { WarpDrive.debugPrint("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z); @@ -140,20 +159,21 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements private void scanNearby(ArrayList current,int x,int y,int z,int d) { - for(int dx=-1;dx<=1;dx++) + int[] deltas = {0,-1,1}; + for(int dx : deltas) { - for(int dy=0;dy<=1;dy++) + for(int dy=1;dy>=0;dy--) { - for(int dz=-1;dz<=1;dz++) + for(int dz : deltas) { int blockID = worldObj.getBlockId(x+dx, y+dy, z+dz); - if(isLog(blockID)) + if(isLog(blockID) || (doLeaves && isLeaf(blockID))) { Vector3 pos = new Vector3(x+dx,y+dy,z+dz); if(!current.contains(pos)) { addTree(current,pos); - if(d < 18) + if(d < 35) scanNearby(current,x+dx,y+dy,z+dz,d+1); } } @@ -162,6 +182,28 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements } } + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + tag.setInteger("xSize", xSize); + tag.setInteger("zSize", zSize); + tag.setBoolean("doLeaves", doLeaves); + tag.setBoolean("active", active); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + xSize = tag.getInteger("xSize"); + zSize = tag.getInteger("zSize"); + defineMiningArea(xSize,zSize); + + doLeaves = tag.getBoolean("doLeaves"); + active = tag.getBoolean("active"); + } + @Override public boolean shouldChunkLoad() { @@ -185,10 +227,20 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements { String methodStr = methodsArray[method]; if(methodStr == "start") - active = true; + { + if(!active) + { + mode = 0; + totalHarvested = 0; + active = true; + } + return new Boolean[] { true }; + } if(methodStr == "stop") + { active = false; + } if(methodStr == "area") { @@ -211,11 +263,25 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements zSize = defSize; } defineMiningArea(xSize,zSize); - return new Integer[] {xSize,zSize}; + return new Integer[] { xSize , zSize }; } - if(methodStr == "silktouch") + if(methodStr == "leaves") + { + try + { + if(arguments.length > 0) + doLeaves = toBool(arguments[0]); + } + catch(Exception e) + { + + } + return new Boolean[] { doLeaves }; + } + + if(methodStr == "silkTouch") { try { @@ -225,13 +291,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements { silkTouch(false); } - return new Boolean[] { silkTouch() }; + return new Object[] { silkTouch() }; } if(methodStr == "state") { String state = active ? "active" : "inactive"; - return new Object[] { state, xSize,zSize,energy() }; + return new Object[] { state, xSize,zSize,energy(),totalHarvested }; } return null; } diff --git a/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java b/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java index 4058f3b8..91630ada 100644 --- a/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java +++ b/src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java @@ -37,8 +37,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner implements IP { int enPerBlock = isOnEarth() ? WarpDriveConfig.i.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.i.ML_EU_PER_BLOCK_SPACE; if(silkTouch()) - return (int) Math.round(enPerBlock * WarpDriveConfig.i.ML_EU_MUL_SILKTOUCH); - return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.i.ML_EU_MUL_FORTUNE, fortune()))); + return (int) Math.round(enPerBlock * WarpDriveConfig.i.ML_EU_MUL_SILKTOUCH * speedMul); + return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.i.ML_EU_MUL_FORTUNE, fortune())) * speedMul); } private String[] methodsArray = @@ -71,8 +71,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner implements IP @Override public void updateEntity() { - if(shouldChunkLoad() != areChunksLoaded) - refreshLoading(); + super.updateEntity(); if(minLayer > yCoord - 1) minLayer = yCoord - 1; diff --git a/src/cr0s/WarpDrive/machines/WarpChunkTE.java b/src/cr0s/WarpDrive/machines/WarpChunkTE.java index 0bb8b209..d292490c 100644 --- a/src/cr0s/WarpDrive/machines/WarpChunkTE.java +++ b/src/cr0s/WarpDrive/machines/WarpChunkTE.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import cr0s.WarpDrive.WarpDrive; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.ChunkCoordIntPair; import net.minecraftforge.common.ForgeChunkManager;