Added tree tapping mode to tree farm
Added config option to turn debug mode on or off Added base TE class to be lazy with some functions (e.g. for computer input and Math.min(Math.max(a,b),c) replacement
This commit is contained in:
parent
817a0ea3f4
commit
4447722001
6 changed files with 188 additions and 69 deletions
|
@ -147,7 +147,8 @@ public class WarpDrive implements LoadingCallback {
|
|||
|
||||
public static void debugPrint(String out)
|
||||
{
|
||||
System.out.println(out);
|
||||
if(WarpDriveConfig.i == null || WarpDriveConfig.i.debugMode)
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
@Init
|
||||
|
|
|
@ -27,6 +27,8 @@ public class WarpDriveConfig
|
|||
//
|
||||
public int[] IC2_Air;
|
||||
public int[] IC2_Empty;
|
||||
public int IC2_RubberTree;
|
||||
public ItemStack IC2_Resin;
|
||||
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<Integer> SpaceHelmets, Jetpacks, MinerOres, MinerLogs, MinerLeaves, scannerIgnoreBlocks;
|
||||
private Class<?> AEBlocks;
|
||||
|
@ -34,6 +36,8 @@ public class WarpDriveConfig
|
|||
private Class<?> AEItems;
|
||||
public ArrayList<int[]> CommonWorldGenOres;
|
||||
public Item AEExtraFDI;
|
||||
|
||||
public boolean debugMode = false;
|
||||
|
||||
// Mod config
|
||||
// Warp Core
|
||||
|
@ -178,20 +182,6 @@ public class WarpDriveConfig
|
|||
|
||||
// Particle Booster
|
||||
PB_MAX_ENERGY_VALUE = config.get("ParticleBooster", "max_energy_value", 100000).getInt();
|
||||
|
||||
// Mining Laser
|
||||
ML_MAX_BOOSTERS_NUMBER = config.get("MiningLaser", "max_boosters_number", 1).getInt();
|
||||
ML_SCAN_DELAY = 20 * config.get("MiningLaser", "scan_delay_seconds", 5).getInt();
|
||||
ML_MINE_DELAY = config.get("MiningLaser", "mine_delay_ticks", 10).getInt();
|
||||
ML_EU_PER_LAYER_SPACE = config.get("MiningLaser", "eu_per_layer_space", 100).getInt();
|
||||
ML_EU_PER_LAYER_EARTH = config.get("MiningLaser", "eu_per_layer_earth", 2500).getInt();
|
||||
ML_EU_PER_BLOCK_SPACE = config.get("MiningLaser", "eu_per_block_space", 10).getInt();
|
||||
ML_EU_PER_BLOCK_EARTH = config.get("MiningLaser", "eu_per_block_earth", 50).getInt();
|
||||
ML_MAX_SIZE = config.get("MiningLaser", "max_size", 128).getInt();
|
||||
ML_EU_MUL_SILKTOUCH = config.get("MiningLaser", "silktouch_power_mul", 2.5).getDouble(2.5);
|
||||
ML_EU_MUL_FORTUNE = config.get("MiningLaser", "fortune_power_base", 1.5).getDouble(1.5);
|
||||
ML_MAX_SPEED = config.get("MiningLaser", "max_speed_mul", 10).getDouble(10);
|
||||
ML_MIN_SPEED = config.get("MiningLaser", "min_speed_mul", 0.1).getDouble(0.1);
|
||||
|
||||
// Laser Emitter
|
||||
LE_MAX_BOOSTERS_NUMBER = config.get("LaserEmitter", "max_boosters_number", 10).getInt();
|
||||
|
@ -217,7 +207,25 @@ public class WarpDriveConfig
|
|||
CD_COIL_CAPTURE_BLOCKS = config.get("CloakingDevice", "coil_capture_blocks", 5).getInt();
|
||||
|
||||
// Dark's modifications
|
||||
debugMode = config.get("Dark's stuff", "debug_mode", false).getBoolean(false);
|
||||
schemaLocation = config.get("Dark's stuff", "schematic_location", schemaLocation).getString();
|
||||
|
||||
// Mining Laser
|
||||
ML_MAX_BOOSTERS_NUMBER = config.get("MiningLaser", "max_boosters_number", 1).getInt();
|
||||
ML_SCAN_DELAY = 20 * config.get("MiningLaser", "scan_delay_seconds", 5).getInt();
|
||||
ML_MINE_DELAY = config.get("MiningLaser", "mine_delay_ticks", 10).getInt();
|
||||
ML_EU_PER_LAYER_SPACE = config.get("MiningLaser", "eu_per_layer_space", 100).getInt();
|
||||
ML_EU_PER_LAYER_EARTH = config.get("MiningLaser", "eu_per_layer_earth", 2500).getInt();
|
||||
ML_EU_PER_BLOCK_SPACE = config.get("MiningLaser", "eu_per_block_space", 10).getInt();
|
||||
ML_EU_PER_BLOCK_EARTH = config.get("MiningLaser", "eu_per_block_earth", 50).getInt();
|
||||
ML_MAX_SIZE = config.get("MiningLaser", "max_size", 128).getInt();
|
||||
ML_EU_MUL_SILKTOUCH = config.get("MiningLaser", "silktouch_power_mul", 2.5).getDouble(2.5);
|
||||
ML_EU_MUL_FORTUNE = config.get("MiningLaser", "fortune_power_base", 1.5).getDouble(1.5);
|
||||
ML_MAX_SPEED = config.get("MiningLaser", "max_speed_mul", 10).getDouble(10);
|
||||
ML_MIN_SPEED = config.get("MiningLaser", "min_speed_mul", 0.1).getDouble(0.1);
|
||||
|
||||
// Tree Farm
|
||||
TF_MAX_SIZE = config.get("TreeFarm", "max_treefarm_size", 16).getInt();
|
||||
}
|
||||
|
||||
public void Init2()
|
||||
|
@ -362,6 +370,11 @@ public class WarpDriveConfig
|
|||
Jetpacks.add(Items.getItem("electricJetpack").itemID);
|
||||
IC2_Air = new int[] {Items.getItem("airCell").itemID, Items.getItem("airCell").getItemDamage()};
|
||||
IC2_Empty = new int[] {Items.getItem("cell").itemID, Items.getItem("cell").getItemDamage()};
|
||||
ItemStack rubberTree = Items.getItem("rubberWood");
|
||||
ItemStack stickyResin = Items.getItem("resin");
|
||||
if(rubberTree != null)
|
||||
IC2_RubberTree = rubberTree.itemID;
|
||||
IC2_Resin = stickyResin;
|
||||
CommonWorldGenOres.add(new int[] {Items.getItem("uraniumOre").itemID, Items.getItem("uraniumOre").getItemDamage()});
|
||||
CommonWorldGenOres.add(new int[] {Items.getItem("copperOre").itemID, Items.getItem("copperOre").getItemDamage()});
|
||||
CommonWorldGenOres.add(new int[] {Items.getItem("tinOre").itemID, Items.getItem("tinOre").getItemDamage()});
|
||||
|
|
|
@ -71,28 +71,6 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
minerVector = minerVector.translate(0.5);
|
||||
}
|
||||
|
||||
protected int toInt(double d)
|
||||
{
|
||||
return (int) Math.round(d);
|
||||
}
|
||||
|
||||
protected int toInt(Object o)
|
||||
{
|
||||
return toInt(toDouble(o));
|
||||
}
|
||||
|
||||
protected double toDouble(Object o)
|
||||
{
|
||||
return Double.parseDouble(o.toString());
|
||||
}
|
||||
|
||||
protected boolean toBool(Object o)
|
||||
{
|
||||
if(o.toString() == "true" || o.toString() == "1.0" || o.toString() == "1")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, int blockID, int blockMeta)
|
||||
{
|
||||
Block block = Block.blocksList[blockID];
|
||||
|
@ -165,7 +143,7 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
{
|
||||
try
|
||||
{
|
||||
fortuneLevel = Math.min(maxFortune(), Math.max(minFortune(),f));
|
||||
fortuneLevel = clamp(f,minFortune(),maxFortune());
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
|
@ -197,9 +175,14 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
}
|
||||
|
||||
protected int calculateBlockCost()
|
||||
{
|
||||
return calculateBlockCost(0);
|
||||
}
|
||||
|
||||
protected int calculateBlockCost(int blockID)
|
||||
{
|
||||
int enPerBlock = isOnEarth() ? WarpDriveConfig.i.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.i.ML_EU_PER_BLOCK_SPACE;
|
||||
if(silkTouch())
|
||||
if(silkTouch(blockID))
|
||||
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())));
|
||||
}
|
||||
|
@ -278,13 +261,18 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
}
|
||||
}
|
||||
|
||||
private void mineBlock(Vector3 valuable,int blockID, int blockMeta)
|
||||
protected void laserBlock(Vector3 valuable)
|
||||
{
|
||||
float r = getColorR();
|
||||
float g = getColorG();
|
||||
float b = getColorB();
|
||||
sendLaserPacket(minerVector, valuable.clone().translate(0.5), r, g, b, 2 * WarpDriveConfig.i.ML_MINE_DELAY, 0, 50);
|
||||
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
}
|
||||
|
||||
private void mineBlock(Vector3 valuable,int blockID, int blockMeta)
|
||||
{
|
||||
laserBlock(valuable);
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), blockID + (blockMeta << 12));
|
||||
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
}
|
||||
|
@ -301,10 +289,7 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
{
|
||||
for (ItemStack stack : stacks)
|
||||
{
|
||||
if (grid != null)
|
||||
didPlace = didPlace && putInGrid(stack) == stack.stackSize;
|
||||
else
|
||||
didPlace = didPlace && putInChest(findChest(), stack) == stack.stackSize;
|
||||
didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
|
||||
}
|
||||
}
|
||||
mineBlock(valuable,blockID,blockMeta);
|
||||
|
@ -317,6 +302,14 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
|
|||
return true;
|
||||
}
|
||||
|
||||
protected int dumpToInv(ItemStack item)
|
||||
{
|
||||
if (grid != null)
|
||||
return putInGrid(item);
|
||||
else
|
||||
return putInChest(findChest(), item);
|
||||
}
|
||||
|
||||
private int putInGrid(ItemStack itemStackSource)
|
||||
{
|
||||
int transferred = 0;
|
||||
|
|
|
@ -2,6 +2,7 @@ package cr0s.WarpDrive.machines;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cr0s.WarpDrive.Vector3;
|
||||
|
@ -19,6 +20,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
private int mode = 0;
|
||||
private boolean doLeaves = false;
|
||||
private boolean silkTouchLeaves = false;
|
||||
private boolean treeTap = false;
|
||||
|
||||
private final int defSize = 8;
|
||||
private final int scanWait = 40;
|
||||
|
@ -41,6 +43,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
"leaves",
|
||||
"silkTouch",
|
||||
"silkTouchLeaves",
|
||||
"treetap",
|
||||
"state"
|
||||
};
|
||||
|
||||
|
@ -63,7 +66,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
scan = 0;
|
||||
logs = scanTrees();
|
||||
if(logs.size() > 0)
|
||||
mode = 1;
|
||||
mode = treeTap ? 2 : 1;
|
||||
logIndex = 0;
|
||||
}
|
||||
}
|
||||
|
@ -72,35 +75,87 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
if(++scan >= mineWait * delayMul)
|
||||
{
|
||||
scan = 0;
|
||||
int cost = calculateBlockCost();
|
||||
if(collectEnergyPacketFromBooster(cost,true))
|
||||
|
||||
if(logIndex >= logs.size())
|
||||
{
|
||||
if(logIndex >= logs.size())
|
||||
mode = 0;
|
||||
return;
|
||||
}
|
||||
Vector3 pos = logs.get(logIndex);
|
||||
int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ());
|
||||
|
||||
if(mode == 1)
|
||||
{
|
||||
int cost = calculateBlockCost(blockID);
|
||||
if(collectEnergyPacketFromBooster(cost,true))
|
||||
{
|
||||
mode = 0;
|
||||
return;
|
||||
}
|
||||
Vector3 pos = logs.get(logIndex);
|
||||
int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ());
|
||||
if(isLog(blockID) || (doLeaves && isLeaf(blockID)))
|
||||
{
|
||||
delayMul = 1;
|
||||
if(isRoomForHarvest())
|
||||
if(isLog(blockID) || (doLeaves && isLeaf(blockID)))
|
||||
{
|
||||
if(collectEnergyPacketFromBooster(cost,false))
|
||||
delayMul = 1;
|
||||
if(isRoomForHarvest())
|
||||
{
|
||||
if(isLog(blockID))
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
harvestBlock(pos);
|
||||
if(collectEnergyPacketFromBooster(cost,false))
|
||||
{
|
||||
if(isLog(blockID))
|
||||
{
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
}
|
||||
harvestBlock(pos);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
logIndex++;
|
||||
}
|
||||
}
|
||||
else if(mode == 2)
|
||||
{
|
||||
int cost = calculateBlockCost(blockID);
|
||||
if(collectEnergyPacketFromBooster(cost,true))
|
||||
{
|
||||
if(isRoomForHarvest())
|
||||
{
|
||||
if(blockID == WarpDriveConfig.i.IC2_RubberTree)
|
||||
{
|
||||
int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
|
||||
if(metadata >= 2 && metadata <= 5)
|
||||
{
|
||||
WarpDrive.debugPrint("wetspot found");
|
||||
if(collectEnergyPacketFromBooster(cost,false))
|
||||
{
|
||||
ItemStack resin = WarpDriveConfig.i.IC2_Resin.copy();
|
||||
resin.stackSize = (int) Math.round(Math.random() * 4);
|
||||
dumpToInv(resin);
|
||||
worldObj.setBlockMetadataWithNotify(pos.intX(), pos.intY(), pos.intZ(), metadata+6, 3);
|
||||
laserBlock(pos);
|
||||
totalHarvested++;
|
||||
delayMul = 4;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
delayMul = 1;
|
||||
}
|
||||
else if(isLeaf(blockID))
|
||||
{
|
||||
if(collectEnergyPacketFromBooster(cost,true))
|
||||
{
|
||||
delayMul = 1;
|
||||
harvestBlock(pos);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
return;
|
||||
logIndex++;
|
||||
}
|
||||
logIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +243,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
tag.setInteger("zSize", zSize);
|
||||
tag.setBoolean("doLeaves", doLeaves);
|
||||
tag.setBoolean("active", active);
|
||||
tag.setBoolean("treetap", treeTap);
|
||||
tag.setBoolean("silkTouchLeaves", silkTouchLeaves);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,6 +257,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
|
||||
doLeaves = tag.getBoolean("doLeaves");
|
||||
active = tag.getBoolean("active");
|
||||
treeTap = tag.getBoolean("treetap");
|
||||
silkTouchLeaves = tag.getBoolean("silkTouchLeaves");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -246,13 +305,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
{
|
||||
if(arguments.length == 1)
|
||||
{
|
||||
xSize = toInt(arguments[0]);
|
||||
xSize = clamp(toInt(arguments[0]),3,WarpDriveConfig.i.TF_MAX_SIZE);
|
||||
zSize = xSize;
|
||||
}
|
||||
else if(arguments.length == 2)
|
||||
{
|
||||
xSize = toInt(arguments[0]);
|
||||
zSize = toInt(arguments[1]);
|
||||
xSize = clamp(toInt(arguments[0]),3,WarpDriveConfig.i.TF_MAX_SIZE);
|
||||
zSize = clamp(toInt(arguments[1]),3,WarpDriveConfig.i.TF_MAX_SIZE);
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
|
@ -296,7 +355,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
{
|
||||
try
|
||||
{
|
||||
silkTouchLeaves = toBool(arguments[0]);
|
||||
if(arguments.length >= 1)
|
||||
silkTouchLeaves = toBool(arguments[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -305,9 +365,23 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
|
|||
return new Object[] { silkTouchLeaves };
|
||||
}
|
||||
|
||||
if(methodStr == "treetap")
|
||||
{
|
||||
try
|
||||
{
|
||||
if(arguments.length >= 1)
|
||||
treeTap = toBool(arguments[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
treeTap = false;
|
||||
}
|
||||
return new Object[] { treeTap };
|
||||
}
|
||||
|
||||
if(methodStr == "state")
|
||||
{
|
||||
String state = active ? "active" : "inactive";
|
||||
String state = active ? (mode==0?"scanning" : (mode == 1 ? "harvesting" : "tapping")) : "inactive";
|
||||
return new Object[] { state, xSize,zSize,energy(),totalHarvested };
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.world.ChunkCoordIntPair;
|
|||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
||||
public abstract class WarpChunkTE extends TileEntity
|
||||
public abstract class WarpChunkTE extends WarpTE
|
||||
{
|
||||
private ArrayList<Ticket> ticketList = new ArrayList<Ticket>();
|
||||
|
||||
|
|
38
src/cr0s/WarpDrive/machines/WarpTE.java
Normal file
38
src/cr0s/WarpDrive/machines/WarpTE.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package cr0s.WarpDrive.machines;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public abstract class WarpTE extends TileEntity
|
||||
{
|
||||
protected int toInt(double d)
|
||||
{
|
||||
return (int) Math.round(d);
|
||||
}
|
||||
|
||||
protected int toInt(Object o)
|
||||
{
|
||||
return toInt(toDouble(o));
|
||||
}
|
||||
|
||||
protected double toDouble(Object o)
|
||||
{
|
||||
return Double.parseDouble(o.toString());
|
||||
}
|
||||
|
||||
protected boolean toBool(Object o)
|
||||
{
|
||||
if(o.toString() == "true" || o.toString() == "1.0" || o.toString() == "1")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int clamp(int a,int min,int max)
|
||||
{
|
||||
return Math.min(max, Math.max(a,min));
|
||||
}
|
||||
|
||||
protected double clamp(double a,double min,double max)
|
||||
{
|
||||
return Math.min(max, Math.max(a,min));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue