Laser Tree Farm beginnings

This commit is contained in:
DarkholmeTenk 2014-02-25 06:47:49 +00:00
parent dcb339e1ce
commit 726417a320
7 changed files with 381 additions and 78 deletions

View file

@ -22,6 +22,7 @@ import cr0s.WarpDrive.machines.BlockCloakingCoil;
import cr0s.WarpDrive.machines.BlockCloakingDeviceCore;
import cr0s.WarpDrive.machines.BlockLaser;
import cr0s.WarpDrive.machines.BlockLaserCam;
import cr0s.WarpDrive.machines.BlockLaserTreeFarm;
import cr0s.WarpDrive.machines.BlockLift;
import cr0s.WarpDrive.machines.BlockMiningLaser;
import cr0s.WarpDrive.machines.BlockMonitor;
@ -35,6 +36,7 @@ import cr0s.WarpDrive.machines.TileEntityAirGenerator;
import cr0s.WarpDrive.machines.TileEntityCamera;
import cr0s.WarpDrive.machines.TileEntityCloakingDeviceCore;
import cr0s.WarpDrive.machines.TileEntityLaser;
import cr0s.WarpDrive.machines.TileEntityLaserTreeFarm;
import cr0s.WarpDrive.machines.TileEntityLift;
import cr0s.WarpDrive.machines.TileEntityMiningLaser;
import cr0s.WarpDrive.machines.TileEntityMonitor;
@ -92,6 +94,7 @@ public class WarpDrive implements LoadingCallback {
public static Block monitorBlock;
public static Block boosterBlock;
public static Block miningLaserBlock;
public static Block laserTreeFarmBlock;
public static Block liftBlock;
public static Block scannerBlock;
public static Block cloakBlock;
@ -263,6 +266,15 @@ public class WarpDrive implements LoadingCallback {
GameRegistry.registerTileEntity(TileEntityMiningLaser.class,
"miningLaserBlock");
// LASER TREE FARM
this.laserTreeFarmBlock = new BlockLaserTreeFarm(WarpDriveConfig.i.laserTreeFarmID,0,Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone)
.setUnlocalizedName("Laser Tree Farm");
LanguageRegistry.addName(laserTreeFarmBlock, "Laser Tree Farm");
GameRegistry.registerBlock(laserTreeFarmBlock, "laserTreeFarmBlock");
GameRegistry.registerTileEntity(TileEntityLaserTreeFarm.class,"laserTreeFarmBlock");
// PARTICLE BOOSTER
this.boosterBlock = new BlockParticleBooster(
WarpDriveConfig.i.particleBoosterID, 0, Material.rock)

View file

@ -21,13 +21,14 @@ public class WarpDriveConfig
public static WarpDriveConfig i;
private Configuration config;
public int coreID, controllerID, radarID, isolationID, airID, airgenID, gasID, laserID, miningLaserID, particleBoosterID, liftID, laserCamID, camID, monitorID, iridiumID, shipScannerID, cloakCoreID, cloakCoilID;
public int laserTreeFarmID;
//
public boolean isGregLoaded = false, isAELoaded = false, isAdvSolPanelLoaded = false, isASLoaded = false, isAEExtraLoaded = false, isICBMLoaded = false, isMFFSLoaded = false, isGraviSuiteLoaded = false;
//
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<Integer> SpaceHelmets, Jetpacks, MinerOres, scannerIgnoreBlocks;
public Set<Integer> SpaceHelmets, Jetpacks, MinerOres, MinerLogs, scannerIgnoreBlocks;
private Class<?> AEBlocks;
private Class<?> AEMaterials;
private Class<?> AEItems;
@ -230,6 +231,7 @@ public class WarpDriveConfig
SpaceHelmets = new HashSet<Integer>();
Jetpacks = new HashSet<Integer>();
MinerOres = new HashSet<Integer>();
MinerLogs = new HashSet<Integer>();
scannerIgnoreBlocks = new HashSet<Integer>();
config.load();
coreID = config.getBlock("core", 500).getInt();
@ -250,6 +252,7 @@ public class WarpDriveConfig
shipScannerID = config.getBlock("shipscanner", 516).getInt();
cloakCoreID = config.getBlock("cloakcore", 517).getInt();
cloakCoilID = config.getBlock("cloakcoil", 518).getInt();
laserTreeFarmID = config.getBlock("lasertreefarm", 519).getInt();
LoadIC2();
LoadCC();
@ -304,6 +307,15 @@ public class WarpDriveConfig
WarpDrive.debugPrint("WD: Added ore ID: "+i.itemID);
}
}
if(oreName.contains("log") || oreName.contains("Log"))
{
ArrayList<ItemStack> item = OreDictionary.getOres(oreName);
for(ItemStack i: item)
{
MinerLogs.add(i.itemID);
WarpDrive.debugPrint("WD: Added log ID: "+i.itemID);
}
}
}
// Ignore WarpDrive blocks (which potentially will be duplicated by cheaters using ship scan/deploy)

View file

@ -0,0 +1,71 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockLaserTreeFarm extends BlockContainer
{
private Icon[] iconBuffer;
private final int ICON_SIDE = 0;
public BlockLaserTreeFarm(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[2];
// Solid textures
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:particleBoosterTopBottom");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:miningLaserSide0");
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == 0 || side == 1)
{
return iconBuffer[0];
}
return iconBuffer[metadata + 1];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityLaserTreeFarm();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
}

View file

@ -44,7 +44,7 @@ public class BlockMiningLaser extends BlockContainer
return iconBuffer[metadata + 1];
}
@Override
public TileEntity createNewTileEntity(World var1)
{

View file

@ -113,17 +113,17 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
private IInventory findChest()
{
int[] xPos = {1,-1,0,0,0,0};
int[] yPos = {0,0,-1,1,0,0};
int[] zPos = {0,0,0,0,-1,1};
TileEntity result = null;
for(int x=-1;x<=1;x++)
for(int i=0;i<6;i++)
{
for(int y=-1;y<=1;y++)
result = worldObj.getBlockTileEntity(xCoord+xPos[i], yCoord+yPos[i], zCoord+zPos[i]);
if(result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory))
{
for(int z=-1;z<=1;z++)
{
result = worldObj.getBlockTileEntity(xCoord+x, yCoord+y, zCoord+z);
if(result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory))
return (IInventory) result;
}
return (IInventory) result;
}
}
return null;
@ -147,6 +147,11 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
return silkTouch();
}
protected boolean silkTouch(Object o)
{
return silkTouch(toBool(o));
}
protected int fortune(int f)
{
try
@ -177,9 +182,22 @@ public abstract class TileEntityAbstractMiner extends WarpChunkTE implements IGr
//DATA RET
protected int calculateLayerCost()
{
return isOnEarth() ? WarpDriveConfig.i.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.i.ML_EU_PER_LAYER_SPACE;
}
protected int calculateBlockCost()
{
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())));
}
protected boolean isRoomForHarvest()
{
if(grid != null && isMEReady)
if(isMEReady && grid != null)
return true;
IInventory inv = findChest();

View file

@ -0,0 +1,255 @@
package cr0s.WarpDrive.machines;
import java.util.ArrayList;
import net.minecraftforge.oredict.OreDictionary;
import cr0s.WarpDrive.Vector3;
import cr0s.WarpDrive.WarpDrive;
import cr0s.WarpDrive.WarpDriveConfig;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements IPeripheral
{
protected final boolean canSilktouch=true;
protected final int minFortune=0;
protected final int maxFortune=0;
protected final int laserBelow = -1;
Boolean active = false;
private int mode = 0;
private final int defSize = 8;
private final int scanWait = 20;
private final int mineWait = 20;
private int scan=0;
private int xSize = defSize;
private int zSize = defSize;
ArrayList<Vector3> logs;
private int logIndex = 0;
private String[] methodsArray = {
"start",
"stop",
"area",
"silktouch",
"state"
};
public TileEntityLaserTreeFarm()
{
super();
}
@Override
public void updateEntity()
{
if(active)
{
if(mode == 0)
{
if(++scan >= scanWait)
{
scan = 0;
logs = scanTrees();
if(logs.size() > 0)
mode = 1;
logIndex = 0;
}
}
else
{
if(++scan >= mineWait)
{
scan = 0;
int cost = calculateBlockCost();
if(collectEnergyPacketFromBooster(cost,true))
{
if(logIndex >= logs.size())
{
mode = 0;
return;
}
Vector3 pos = logs.get(logIndex);
int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ());
if(WarpDriveConfig.i.MinerLogs.contains(blockID))
{
if(isRoomForHarvest())
{
if(collectEnergyPacketFromBooster(cost,false))
{
harvestBlock(pos);
}
else
return;
}
}
logIndex++;
}
}
}
}
}
private boolean isLog(int blockID)
{
return WarpDriveConfig.i.MinerLogs.contains(blockID);
}
private void addTree(ArrayList<Vector3> list,Vector3 newTree)
{
WarpDrive.debugPrint("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
list.add(newTree);
}
private ArrayList<Vector3> scanTrees()
{
int xmax, zmax, x1, x2, z1, z2;
int xmin, zmin;
x1 = xCoord + xSize / 2;
x2 = xCoord - xSize / 2;
xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
z1 = zCoord + zSize / 2;
z2 = zCoord - zSize / 2;
zmin = Math.min(z1, z2);
zmax = Math.max(z1, z2);
ArrayList<Vector3> logPositions = new ArrayList<Vector3>();
for(int x=xmin;x<=xmax;x++)
{
for(int z=zmin;z<=zmax;z++)
{
int blockID = worldObj.getBlockId(x, yCoord, z);
if(isLog(blockID))
{
Vector3 pos = new Vector3(x,yCoord,z);
logPositions.add(pos);
scanNearby(logPositions,x,yCoord,z,0);
}
}
}
return logPositions;
}
private void scanNearby(ArrayList<Vector3> current,int x,int y,int z,int d)
{
for(int dx=-1;dx<=1;dx++)
{
for(int dy=0;dy<=1;dy++)
{
for(int dz=-1;dz<=1;dz++)
{
int blockID = worldObj.getBlockId(x+dx, y+dy, z+dz);
if(isLog(blockID))
{
Vector3 pos = new Vector3(x+dx,y+dy,z+dz);
if(!current.contains(pos))
{
addTree(current,pos);
if(d < 18)
scanNearby(current,x+dx,y+dy,z+dz,d+1);
}
}
}
}
}
}
@Override
public boolean shouldChunkLoad()
{
return active;
}
@Override
public String getType()
{
return "treefarmLaser";
}
@Override
public String[] getMethodNames()
{
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
String methodStr = methodsArray[method];
if(methodStr == "start")
active = true;
if(methodStr == "stop")
active = false;
if(methodStr == "area")
{
try
{
if(arguments.length == 1)
{
xSize = toInt(arguments[0]);
zSize = xSize;
}
else if(arguments.length == 2)
{
xSize = toInt(arguments[0]);
zSize = toInt(arguments[1]);
}
}
catch(NumberFormatException e)
{
xSize = defSize;
zSize = defSize;
}
defineMiningArea(xSize,zSize);
return new Integer[] {xSize,zSize};
}
if(methodStr == "silktouch")
{
try
{
silkTouch(arguments[0]);
}
catch(Exception e)
{
silkTouch(false);
}
return new Boolean[] { silkTouch() };
}
if(methodStr == "state")
{
String state = active ? "active" : "inactive";
return new Object[] { state, xSize,zSize,energy() };
}
return null;
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
}

View file

@ -26,11 +26,13 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner implements IP
private int miningDelay = 0;
private int minLayer = 1;
@Override
protected int calculateLayerCost()
{
return isOnEarth() ? WarpDriveConfig.i.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.i.ML_EU_PER_LAYER_SPACE;
}
@Override
protected int calculateBlockCost()
{
int enPerBlock = isOnEarth() ? WarpDriveConfig.i.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.i.ML_EU_PER_BLOCK_SPACE;
@ -195,10 +197,6 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner implements IP
zmin = z2;
zmax = z1;
}
//System.out.println("Layer: xmax: " + xmax + ", xmin: " + xmin);
//System.out.println("Layer: zmax: " + zmax + ", zmin: " + zmin);
defineMiningArea(xmin,zmin,xmax,zmax);
// Search for valuable blocks
@ -221,69 +219,6 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner implements IP
//System.out.println("[ML] Found " + valuablesInLayer.size() + " valuables");
}
private void scanLayer()
{
//System.out.println("Scanning layer");
valuablesInLayer.clear();
int xmax, zmax, x1, x2, z1, z2;
int xmin, zmin;
x1 = xCoord + digX / 2;
x2 = xCoord - digX / 2;
if (x1 < x2)
{
xmin = x1;
xmax = x2;
}
else
{
xmin = x2;
xmax = x1;
}
z1 = zCoord + digZ / 2;
z2 = zCoord - digZ / 2;
if (z1 < z2)
{
zmin = z1;
zmax = z2;
}
else
{
zmin = z2;
zmax = z1;
}
//System.out.println("Layer: xmax: " + xmax + ", xmin: " + xmin);
//System.out.println("Layer: zmax: " + zmax + ", zmin: " + zmin);
minChunk = worldObj.getChunkFromBlockCoords(xmin,zmin).getChunkCoordIntPair();
maxChunk = worldObj.getChunkFromBlockCoords(xmax,zmax).getChunkCoordIntPair();
refreshLoading(true);
// Search for valuable blocks
for (int x = xmin; x <= xmax; x++)
for (int z = zmin; z <= zmax; z++)
{
int blockID = worldObj.getBlockId(x, currentLayer, z);
if (canDig(blockID))
if (isQuarry) // Quarry collects all blocks
{
if (!worldObj.isAirBlock(x, currentLayer, z) && blockID != Block.lavaMoving.blockID && blockID != Block.lavaStill.blockID)
valuablesInLayer.add(new Vector3(x, currentLayer, z));
}
else // Not-quarry collect only valuables blocks
if (WarpDriveConfig.i.MinerOres.contains(worldObj.getBlockId(x, currentLayer, z)))
valuablesInLayer.add(new Vector3(x, currentLayer, z));
}
valuableIndex = 0;
//System.out.println("[ML] Found " + valuablesInLayer.size() + " valuables");
}
@Override
public void readFromNBT(NBTTagCompound tag)
{