Preparing for AE update
This commit is contained in:
parent
d59e3b5d5e
commit
d1cce7764c
2 changed files with 152 additions and 140 deletions
|
@ -2,18 +2,10 @@ package cr0s.warpdrive.machines;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import appeng.api.IAEItemStack;
|
|
||||||
import appeng.api.Util;
|
|
||||||
import appeng.api.WorldCoord;
|
|
||||||
import appeng.api.events.GridTileLoadEvent;
|
|
||||||
import appeng.api.events.GridTileUnloadEvent;
|
|
||||||
import appeng.api.me.tiles.IGridMachine;
|
|
||||||
import appeng.api.me.tiles.ITileCable;
|
|
||||||
import appeng.api.me.util.IGridInterface;
|
|
||||||
import appeng.api.me.util.IMEInventoryHandler;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFluid;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -21,39 +13,45 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.ChunkCoordIntPair;
|
import net.minecraft.world.ChunkCoordIntPair;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import cr0s.warpdrive.data.Vector3;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
|
import appeng.api.networking.IGrid;
|
||||||
|
import appeng.api.networking.IGridNode;
|
||||||
|
import appeng.api.storage.IMEInventoryHandler;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.api.util.WorldCoord;
|
||||||
import cr0s.warpdrive.PacketHandler;
|
import cr0s.warpdrive.PacketHandler;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.WarpDriveConfig;
|
import cr0s.warpdrive.WarpDriveConfig;
|
||||||
|
import cr0s.warpdrive.data.Vector3;
|
||||||
|
|
||||||
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser implements IGridMachine, ITileCable
|
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser implements IGridNode, ITileCable
|
||||||
{
|
{
|
||||||
//FOR STORAGE
|
//FOR STORAGE
|
||||||
private boolean silkTouch = false;
|
private boolean silkTouch = false;
|
||||||
private int fortuneLevel = 0;
|
private int fortuneLevel = 0;
|
||||||
|
|
||||||
private TileEntityParticleBooster booster = null;
|
private TileEntityParticleBooster booster = null;
|
||||||
private Vector3 minerVector;
|
private Vector3 minerVector;
|
||||||
|
|
||||||
Boolean powerStatus = false;
|
Boolean powerStatus = false;
|
||||||
private IGridInterface grid;
|
private IGrid grid;
|
||||||
private boolean isMEReady = false;
|
private boolean isMEReady = false;
|
||||||
|
|
||||||
abstract boolean canSilkTouch();
|
abstract boolean canSilkTouch();
|
||||||
abstract int minFortune();
|
abstract int minFortune();
|
||||||
abstract int maxFortune();
|
abstract int maxFortune();
|
||||||
abstract double laserBelow();
|
abstract double laserBelow();
|
||||||
|
|
||||||
abstract float getColorR();
|
abstract float getColorR();
|
||||||
abstract float getColorG();
|
abstract float getColorG();
|
||||||
abstract float getColorB();
|
abstract float getColorB();
|
||||||
|
|
||||||
public TileEntityAbstractMiner()
|
public TileEntityAbstractMiner()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
fixMinerVector();
|
fixMinerVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixMinerVector()
|
private void fixMinerVector()
|
||||||
{
|
{
|
||||||
if(minerVector == null)
|
if(minerVector == null)
|
||||||
|
@ -63,70 +61,71 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
minerVector.z = zCoord;
|
minerVector.z = zCoord;
|
||||||
minerVector.translate(0.5);
|
minerVector.translate(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, int blockID, int blockMeta)
|
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta)
|
||||||
{
|
{
|
||||||
Block block = Block.blocksList[blockID];
|
|
||||||
if (block == null)
|
if (block == null)
|
||||||
return null;
|
return null;
|
||||||
if (silkTouch(blockID))
|
|
||||||
|
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
|
||||||
|
if (silkTouch(block))
|
||||||
{
|
{
|
||||||
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta))
|
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta))
|
||||||
{
|
{
|
||||||
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
|
t.add(new ItemStack(block, 1, blockMeta));
|
||||||
t.add(new ItemStack(blockID, 1, blockMeta));
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block.getBlockDropped(worldObj, i, j, k, blockMeta, fortuneLevel);
|
t.add(new ItemStack(block.getItemDropped(blockMeta, new Random(), fortuneLevel), block.damageDropped(blockMeta), block.quantityDropped(blockMeta, fortuneLevel, new Random())));
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isOnEarth()
|
protected boolean isOnEarth()
|
||||||
{
|
{
|
||||||
return worldObj.provider.dimensionId == 0;
|
return worldObj.provider.dimensionId == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IInventory findChest() {
|
private IInventory findChest() {
|
||||||
TileEntity result = null;
|
TileEntity result = null;
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++) {
|
for(int i = 0; i < 6; i++) {
|
||||||
Vector3 sideOffset = adjacentSideOffsets[i];
|
Vector3 sideOffset = adjacentSideOffsets[i];
|
||||||
result = worldObj.getBlockTileEntity(xCoord + sideOffset.intX(), yCoord + sideOffset.intY(), zCoord + sideOffset.intZ());
|
result = worldObj.getTileEntity(xCoord + sideOffset.intX(), yCoord + sideOffset.intY(), zCoord + sideOffset.intZ());
|
||||||
if (result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory)) {
|
if (result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory)) {
|
||||||
return (IInventory) result;
|
return (IInventory) result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GETTERSETTERS
|
//GETTERSETTERS
|
||||||
|
|
||||||
protected int fortune()
|
protected int fortune()
|
||||||
{
|
{
|
||||||
return fortuneLevel;
|
return fortuneLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean silkTouch()
|
protected boolean silkTouch()
|
||||||
{
|
{
|
||||||
return silkTouch;
|
return silkTouch;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean silkTouch(int blockID)
|
protected boolean silkTouch(int blockID)
|
||||||
{
|
{
|
||||||
return silkTouch();
|
return silkTouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean silkTouch(boolean b)
|
protected boolean silkTouch(boolean b)
|
||||||
{
|
{
|
||||||
silkTouch = canSilkTouch() && b;
|
silkTouch = canSilkTouch() && b;
|
||||||
return silkTouch();
|
return silkTouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean silkTouch(Object o)
|
protected boolean silkTouch(Object o)
|
||||||
{
|
{
|
||||||
return silkTouch(toBool(o));
|
return silkTouch(toBool(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int fortune(int f)
|
protected int fortune(int f)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -139,14 +138,14 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
}
|
}
|
||||||
return fortune();
|
return fortune();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TileEntityParticleBooster booster()
|
protected TileEntityParticleBooster booster()
|
||||||
{
|
{
|
||||||
if(booster == null)
|
if(booster == null)
|
||||||
findFirstBooster();
|
findFirstBooster();
|
||||||
return booster;
|
return booster;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int energy() {
|
protected int energy() {
|
||||||
TileEntityParticleBooster te = booster();
|
TileEntityParticleBooster te = booster();
|
||||||
if (te != null) {
|
if (te != null) {
|
||||||
|
@ -154,32 +153,32 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//DATA RET
|
//DATA RET
|
||||||
|
|
||||||
protected int calculateLayerCost()
|
protected int calculateLayerCost()
|
||||||
{
|
{
|
||||||
return isOnEarth() ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE;
|
return isOnEarth() ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int calculateBlockCost()
|
protected int calculateBlockCost()
|
||||||
{
|
{
|
||||||
return calculateBlockCost(0);
|
return calculateBlockCost(Blocks.air);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int calculateBlockCost(int blockID)
|
protected int calculateBlockCost(Block block)
|
||||||
{
|
{
|
||||||
int enPerBlock = isOnEarth() ? WarpDriveConfig.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.ML_EU_PER_BLOCK_SPACE;
|
int enPerBlock = isOnEarth() ? WarpDriveConfig.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.ML_EU_PER_BLOCK_SPACE;
|
||||||
if(silkTouch(blockID))
|
if (silkTouch(block))
|
||||||
return (int) Math.round(enPerBlock * WarpDriveConfig.ML_EU_MUL_SILKTOUCH);
|
return (int) Math.round(enPerBlock * WarpDriveConfig.ML_EU_MUL_SILKTOUCH);
|
||||||
return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.ML_EU_MUL_FORTUNE, fortune())));
|
return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.ML_EU_MUL_FORTUNE, fortune())));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isRoomForHarvest()
|
protected boolean isRoomForHarvest()
|
||||||
{
|
{
|
||||||
if(isMEReady && grid != null)
|
if(isMEReady && grid != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
IInventory inv = findChest();
|
IInventory inv = findChest();
|
||||||
if(inv != null)
|
if(inv != null)
|
||||||
{
|
{
|
||||||
|
@ -191,33 +190,33 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canDig(int blockID, int x, int y, int z) {// not used
|
private boolean canDig(Block block, int x, int y, int z) {// not used
|
||||||
// ignore air & fluids
|
// ignore air & fluids
|
||||||
if (!WarpDriveConfig.isAirBlock(worldObj, blockID, x, y, z) && Block.blocksList[blockID] != null && !(Block.blocksList[blockID] instanceof BlockFluid)) {
|
if (block == null || (worldObj.isAirBlock(x, y, z) || (block instanceof IFluidBlock))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check blacklist
|
// check blacklist
|
||||||
if (blockID == Block.bedrock) {
|
if (block.isAssociatedBlock(Blocks.bedrock)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (WarpDriveConfig.forceFieldBlocks.contains(blockID)) {
|
if (WarpDriveConfig.forceFieldBlocks.contains(block)) {
|
||||||
// isMining = false;
|
// isMining = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check whitelist
|
// check whitelist
|
||||||
// WarpDriveConfig.MinerOres.contains(blockID) then true ?
|
// WarpDriveConfig.MinerOres.contains(blockID) then true ?
|
||||||
else if (blockID == WarpDriveConfig.GT_Granite || blockID == WarpDriveConfig.GT_Ores || blockID == WarpDriveConfig.iridiumBlockID) {
|
else if (block.isAssociatedBlock(WarpDrive.iridiumBlock)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// check default
|
// check default
|
||||||
else if ( (Block.blocksList[blockID] != null) && (Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) ) {
|
else if (block.getExplosionResistance(null) <= Blocks.obsidian.getExplosionResistance(null)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//MINING FUNCTIONS
|
//MINING FUNCTIONS
|
||||||
|
|
||||||
protected void laserBlock(Vector3 valuable)
|
protected void laserBlock(Vector3 valuable)
|
||||||
{
|
{
|
||||||
fixMinerVector();
|
fixMinerVector();
|
||||||
|
@ -227,22 +226,22 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
PacketHandler.sendBeamPacket(worldObj, minerVector, valuable.clone().translate(0.5D), r, g, b, 2 * WarpDriveConfig.ML_MINE_DELAY_TICKS, 0, 50);
|
PacketHandler.sendBeamPacket(worldObj, minerVector, valuable.clone().translate(0.5D), r, g, b, 2 * WarpDriveConfig.ML_MINE_DELAY_TICKS, 0, 50);
|
||||||
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mineBlock(Vector3 valuable,int blockID, int blockMeta)
|
private void mineBlock(Vector3 valuable, Block block, int blockMeta)
|
||||||
{
|
{
|
||||||
laserBlock(valuable);
|
laserBlock(valuable);
|
||||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), blockID + (blockMeta << 12));
|
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), (blockMeta << 12));
|
||||||
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean harvestBlock(Vector3 valuable)
|
protected boolean harvestBlock(Vector3 valuable)
|
||||||
{
|
{
|
||||||
int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ());
|
Block block = worldObj.getBlock(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||||
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
|
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||||
if (blockID != Block.waterMoving && blockID != Block.waterStill && blockID != Block.lavaMoving && blockID != Block.lavaStill)
|
if (!block.isAssociatedBlock(Blocks.water) && !block.isAssociatedBlock(Blocks.lava))
|
||||||
{
|
{
|
||||||
boolean didPlace = true;
|
boolean didPlace = true;
|
||||||
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), blockID, blockMeta);
|
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), block, blockMeta);
|
||||||
if (stacks != null)
|
if (stacks != null)
|
||||||
{
|
{
|
||||||
for (ItemStack stack : stacks)
|
for (ItemStack stack : stacks)
|
||||||
|
@ -250,16 +249,16 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
|
didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mineBlock(valuable,blockID,blockMeta);
|
mineBlock(valuable, block, blockMeta);
|
||||||
return didPlace;
|
return didPlace;
|
||||||
}
|
}
|
||||||
else if (blockID == Block.waterMoving || blockID == Block.waterStill)
|
else if (block.isAssociatedBlock(Blocks.water))
|
||||||
// Evaporate water
|
// Evaporate water
|
||||||
worldObj.playSoundEffect(valuable.intX() + 0.5D, valuable.intY() + 0.5D, valuable.intZ() + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
worldObj.playSoundEffect(valuable.intX() + 0.5D, valuable.intY() + 0.5D, valuable.intZ() + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
||||||
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int dumpToInv(ItemStack item)
|
protected int dumpToInv(ItemStack item)
|
||||||
{
|
{
|
||||||
if (grid != null)
|
if (grid != null)
|
||||||
|
@ -267,7 +266,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
else
|
else
|
||||||
return putInChest(findChest(), item);
|
return putInChest(findChest(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int putInGrid(ItemStack itemStackSource)
|
private int putInGrid(ItemStack itemStackSource)
|
||||||
{
|
{
|
||||||
int transferred = 0;
|
int transferred = 0;
|
||||||
|
@ -344,7 +343,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
|
|
||||||
return transferred;
|
return transferred;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean consumeEnergyFromBooster(int requiredEnergy, boolean simulate)
|
protected boolean consumeEnergyFromBooster(int requiredEnergy, boolean simulate)
|
||||||
{
|
{
|
||||||
TileEntityParticleBooster te = booster();
|
TileEntityParticleBooster te = booster();
|
||||||
|
@ -353,18 +352,18 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileEntityParticleBooster findFirstBooster()
|
private TileEntityParticleBooster findFirstBooster()
|
||||||
{
|
{
|
||||||
TileEntity result;
|
TileEntity result;
|
||||||
int[] xPos = {1,-1,0,0,0,0};
|
int[] xPos = {1,-1,0,0,0,0};
|
||||||
int[] yPos = {0,0,-1,1,0,0};
|
int[] yPos = {0,0,-1,1,0,0};
|
||||||
int[] zPos = {0,0,0,0,-1,1};
|
int[] zPos = {0,0,0,0,-1,1};
|
||||||
|
|
||||||
for(int i=0;i<6;i++)
|
for(int i=0;i<6;i++)
|
||||||
{
|
{
|
||||||
result = worldObj.getBlockTileEntity(xCoord + xPos[i], yCoord + yPos[i], zCoord + zPos[i]);
|
result = worldObj.getTileEntity(xCoord + xPos[i], yCoord + yPos[i], zCoord + zPos[i]);
|
||||||
|
|
||||||
if (result != null && result instanceof TileEntityParticleBooster)
|
if (result != null && result instanceof TileEntityParticleBooster)
|
||||||
{
|
{
|
||||||
booster = (TileEntityParticleBooster) result;
|
booster = (TileEntityParticleBooster) result;
|
||||||
|
@ -374,7 +373,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
booster = null;
|
booster = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void defineMiningArea(int xSize,int zSize)
|
protected void defineMiningArea(int xSize,int zSize)
|
||||||
{
|
{
|
||||||
int xmax, zmax, x1, x2, z1, z2;
|
int xmax, zmax, x1, x2, z1, z2;
|
||||||
|
@ -406,10 +405,10 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
zmin = z2;
|
zmin = z2;
|
||||||
zmax = z1;
|
zmax = z1;
|
||||||
}
|
}
|
||||||
|
|
||||||
defineMiningArea(xmin,zmin,xmax,zmax);
|
defineMiningArea(xmin,zmin,xmax,zmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void defineMiningArea(int minX, int minZ, int maxX, int maxZ)
|
protected void defineMiningArea(int minX, int minZ, int maxX, int maxZ)
|
||||||
{
|
{
|
||||||
if(worldObj == null)
|
if(worldObj == null)
|
||||||
|
@ -426,14 +425,14 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
maxChunk = b;
|
maxChunk = b;
|
||||||
refreshLoading(true);
|
refreshLoading(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack copyWithSize(ItemStack itemStack, int newSize)
|
private static ItemStack copyWithSize(ItemStack itemStack, int newSize)
|
||||||
{
|
{
|
||||||
ItemStack ret = itemStack.copy();
|
ItemStack ret = itemStack.copy();
|
||||||
ret.stackSize = newSize;
|
ret.stackSize = newSize;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//NBT DATA
|
//NBT DATA
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag)
|
public void readFromNBT(NBTTagCompound tag)
|
||||||
|
@ -441,13 +440,13 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
super.readFromNBT(tag);
|
super.readFromNBT(tag);
|
||||||
silkTouch = tag.getBoolean("silkTouch");
|
silkTouch = tag.getBoolean("silkTouch");
|
||||||
fortuneLevel = tag.getInteger("fortuneLevel");
|
fortuneLevel = tag.getInteger("fortuneLevel");
|
||||||
|
|
||||||
minerVector.x = xCoord;
|
minerVector.x = xCoord;
|
||||||
minerVector.y = yCoord - (laserBelow());
|
minerVector.y = yCoord - (laserBelow());
|
||||||
minerVector.z = zCoord;
|
minerVector.z = zCoord;
|
||||||
minerVector = minerVector.translate(0.5);
|
minerVector = minerVector.translate(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound tag)
|
public void writeToNBT(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
|
@ -455,20 +454,20 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
tag.setBoolean("silkTouch", silkTouch);
|
tag.setBoolean("silkTouch", silkTouch);
|
||||||
tag.setInteger("fortuneLevel", fortuneLevel);
|
tag.setInteger("fortuneLevel", fortuneLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
//AE INTERFACE
|
//AE INTERFACE
|
||||||
@Override
|
@Override
|
||||||
public void setNetworkReady( boolean isReady )
|
public void setNetworkReady( boolean isReady )
|
||||||
{
|
{
|
||||||
isMEReady = isReady;
|
isMEReady = isReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMachineActive()
|
public boolean isMachineActive()
|
||||||
{
|
{
|
||||||
return isMEReady;
|
return isMEReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getPowerDrainPerTick()
|
public float getPowerDrainPerTick()
|
||||||
{
|
{
|
||||||
|
@ -512,7 +511,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
{
|
{
|
||||||
return powerStatus;
|
return powerStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IGridInterface getGrid()
|
public IGridInterface getGrid()
|
||||||
{
|
{
|
||||||
|
@ -524,7 +523,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
{
|
{
|
||||||
grid = gi;
|
grid = gi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean coveredConnections()
|
public boolean coveredConnections()
|
||||||
{
|
{
|
||||||
|
@ -536,5 +535,5 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
||||||
{
|
{
|
||||||
return worldObj;
|
return worldObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,55 +2,56 @@ package cr0s.warpdrive.machines;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import cr0s.warpdrive.data.Vector3;
|
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.WarpDriveConfig;
|
import cr0s.warpdrive.WarpDriveConfig;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import cr0s.warpdrive.data.Vector3;
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
|
||||||
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
Boolean active = false;
|
Boolean active = false;
|
||||||
|
|
||||||
private int mode = 0;
|
private int mode = 0;
|
||||||
private boolean doLeaves = false;
|
private boolean doLeaves = false;
|
||||||
private boolean silkTouchLeaves = false;
|
private boolean silkTouchLeaves = false;
|
||||||
private boolean treeTap = false;
|
private boolean treeTap = false;
|
||||||
|
|
||||||
private final int defSize = 8;
|
private final int defSize = 8;
|
||||||
private final int scanWait = 40;
|
private final int scanWait = 40;
|
||||||
private final int mineWait = 4;
|
private final int mineWait = 4;
|
||||||
private int delayMul = 4;
|
private int delayMul = 4;
|
||||||
|
|
||||||
private int totalHarvested=0;
|
private int totalHarvested=0;
|
||||||
|
|
||||||
private int scan = 0;
|
private int scan = 0;
|
||||||
private int xSize = defSize;
|
private int xSize = defSize;
|
||||||
private int zSize = defSize;
|
private int zSize = defSize;
|
||||||
|
|
||||||
LinkedList<Vector3> logs;
|
LinkedList<Vector3> logs;
|
||||||
private int logIndex = 0;
|
private int logIndex = 0;
|
||||||
|
|
||||||
public TileEntityLaserTreeFarm() {
|
public TileEntityLaserTreeFarm() {
|
||||||
super();
|
super();
|
||||||
peripheralName = "treefarmLaser";
|
peripheralName = "treefarmLaser";
|
||||||
methodsArray = new String[] {
|
methodsArray = new String[] {
|
||||||
"start",
|
"start",
|
||||||
"stop",
|
"stop",
|
||||||
"area",
|
"area",
|
||||||
"leaves",
|
"leaves",
|
||||||
"silkTouch",
|
"silkTouch",
|
||||||
"silkTouchLeaves",
|
"silkTouchLeaves",
|
||||||
"treetap",
|
"treetap",
|
||||||
"state"
|
"state"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
scan++;
|
scan++;
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
|
@ -64,22 +65,22 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
} else {
|
} else {
|
||||||
if (scan >= mineWait * delayMul) {
|
if (scan >= mineWait * delayMul) {
|
||||||
scan = 0;
|
scan = 0;
|
||||||
|
|
||||||
if (logIndex >= logs.size()) {
|
if (logIndex >= logs.size()) {
|
||||||
mode = 0;
|
mode = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector3 pos = logs.get(logIndex);
|
Vector3 pos = logs.get(logIndex);
|
||||||
int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ());
|
Block block = worldObj.getBlock(pos.intX(), pos.intY(), pos.intZ());
|
||||||
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
int cost = calculateBlockCost(blockID);
|
int cost = calculateBlockCost(block);
|
||||||
if (consumeEnergyFromBooster(cost, true)) {
|
if (consumeEnergyFromBooster(cost, true)) {
|
||||||
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) {
|
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||||
delayMul = 1;
|
delayMul = 1;
|
||||||
if (isRoomForHarvest()) {
|
if (isRoomForHarvest()) {
|
||||||
if (consumeEnergyFromBooster(cost, false)) {
|
if (consumeEnergyFromBooster(cost, false)) {
|
||||||
if (isLog(blockID)) {
|
if (isLog(block)) {
|
||||||
delayMul = 4;
|
delayMul = 4;
|
||||||
totalHarvested++;
|
totalHarvested++;
|
||||||
}
|
}
|
||||||
|
@ -94,10 +95,10 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
logIndex++;
|
logIndex++;
|
||||||
}
|
}
|
||||||
} else if(mode == 2) {
|
} else if(mode == 2) {
|
||||||
int cost = calculateBlockCost(blockID);
|
int cost = calculateBlockCost(block);
|
||||||
if (consumeEnergyFromBooster(cost, true)) {
|
if (consumeEnergyFromBooster(cost, true)) {
|
||||||
if (isRoomForHarvest()) {
|
if (isRoomForHarvest()) {
|
||||||
if (blockID == WarpDriveConfig.IC2_RubberWood) {
|
if (block.isAssociatedBlock(Block.getBlockFromItem(WarpDriveConfig.IC2_RubberWood.getItem()))) {
|
||||||
int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
|
int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
|
||||||
if (metadata >= 2 && metadata <= 5) {
|
if (metadata >= 2 && metadata <= 5) {
|
||||||
WarpDrive.debugPrint("wetspot found");
|
WarpDrive.debugPrint("wetspot found");
|
||||||
|
@ -115,7 +116,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
} else {
|
} else {
|
||||||
delayMul = 1;
|
delayMul = 1;
|
||||||
}
|
}
|
||||||
} else if(isLog(blockID)) {
|
} else if (isLog(block)) {
|
||||||
if (consumeEnergyFromBooster(cost, false)) {
|
if (consumeEnergyFromBooster(cost, false)) {
|
||||||
delayMul = 4;
|
delayMul = 4;
|
||||||
totalHarvested++;
|
totalHarvested++;
|
||||||
|
@ -123,7 +124,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if(isLeaf(blockID)) {
|
} else if (isLeaf(block)) {
|
||||||
if (consumeEnergyFromBooster(cost, true)) {
|
if (consumeEnergyFromBooster(cost, true)) {
|
||||||
delayMul = 1;
|
delayMul = 1;
|
||||||
harvestBlock(pos);
|
harvestBlock(pos);
|
||||||
|
@ -141,20 +142,20 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLog(int blockID) {
|
private static boolean isLog(Block block) {
|
||||||
return WarpDriveConfig.minerLogs.contains(blockID);
|
return WarpDriveConfig.minerLogs.contains(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLeaf(int blockID) {
|
private static boolean isLeaf(Block block) {
|
||||||
return WarpDriveConfig.minerLeaves.contains(blockID);
|
return WarpDriveConfig.minerLeaves.contains(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addTree(LinkedList<Vector3> list, Vector3 newTree) {
|
private static void addTree(LinkedList<Vector3> list, Vector3 newTree) {
|
||||||
WarpDrive.debugPrint("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
|
WarpDrive.debugPrint("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
|
||||||
list.add(newTree);
|
list.add(newTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkedList<Vector3> scanTrees() {
|
private LinkedList<Vector3> scanTrees() {
|
||||||
int xmax, zmax, x1, x2, z1, z2;
|
int xmax, zmax, x1, x2, z1, z2;
|
||||||
int xmin, zmin;
|
int xmin, zmin;
|
||||||
|
@ -167,13 +168,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
z2 = zCoord - zSize / 2;
|
z2 = zCoord - zSize / 2;
|
||||||
zmin = Math.min(z1, z2);
|
zmin = Math.min(z1, z2);
|
||||||
zmax = Math.max(z1, z2);
|
zmax = Math.max(z1, z2);
|
||||||
|
|
||||||
LinkedList<Vector3> logPositions = new LinkedList<Vector3>();
|
LinkedList<Vector3> logPositions = new LinkedList<Vector3>();
|
||||||
|
|
||||||
for(int x = xmin; x <= xmax; x++) {
|
for(int x = xmin; x <= xmax; x++) {
|
||||||
for(int z = zmin; z <= zmax; z++) {
|
for(int z = zmin; z <= zmax; z++) {
|
||||||
int blockID = worldObj.getBlockId(x, yCoord, z);
|
Block block = worldObj.getBlock(x, yCoord, z);
|
||||||
if (isLog(blockID)) {
|
if (isLog(block)) {
|
||||||
Vector3 pos = new Vector3(x, yCoord, z);
|
Vector3 pos = new Vector3(x, yCoord, z);
|
||||||
logPositions.add(pos);
|
logPositions.add(pos);
|
||||||
scanNearby(logPositions, x, yCoord, z, 0);
|
scanNearby(logPositions, x, yCoord, z, 0);
|
||||||
|
@ -182,14 +183,14 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
}
|
}
|
||||||
return logPositions;
|
return logPositions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanNearby(LinkedList<Vector3> current, int x, int y, int z, int d) {
|
private void scanNearby(LinkedList<Vector3> current, int x, int y, int z, int d) {
|
||||||
int[] deltas = {0, -1, 1};
|
int[] deltas = {0, -1, 1};
|
||||||
for(int dx : deltas) {
|
for(int dx : deltas) {
|
||||||
for(int dy = 1; dy >= 0; dy--) {
|
for(int dy = 1; dy >= 0; dy--) {
|
||||||
for(int dz : deltas) {
|
for(int dz : deltas) {
|
||||||
int blockID = worldObj.getBlockId(x+dx, y+dy, z+dz);
|
Block block = worldObj.getBlock(x + dx, y + dy, z + dz);
|
||||||
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) {
|
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||||
Vector3 pos = new Vector3(x + dx, y + dy, z + dz);
|
Vector3 pos = new Vector3(x + dx, y + dy, z + dz);
|
||||||
if (!current.contains(pos)) {
|
if (!current.contains(pos)) {
|
||||||
addTree(current, pos);
|
addTree(current, pos);
|
||||||
|
@ -198,11 +199,11 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound tag) {
|
public void writeToNBT(NBTTagCompound tag) {
|
||||||
super.writeToNBT(tag);
|
super.writeToNBT(tag);
|
||||||
|
@ -213,20 +214,20 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
tag.setBoolean("treetap", treeTap);
|
tag.setBoolean("treetap", treeTap);
|
||||||
tag.setBoolean("silkTouchLeaves", silkTouchLeaves);
|
tag.setBoolean("silkTouchLeaves", silkTouchLeaves);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag) {
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
super.readFromNBT(tag);
|
super.readFromNBT(tag);
|
||||||
xSize = tag.getInteger("xSize");
|
xSize = tag.getInteger("xSize");
|
||||||
zSize = tag.getInteger("zSize");
|
zSize = tag.getInteger("zSize");
|
||||||
defineMiningArea(xSize,zSize);
|
defineMiningArea(xSize,zSize);
|
||||||
|
|
||||||
doLeaves = tag.getBoolean("doLeaves");
|
doLeaves = tag.getBoolean("doLeaves");
|
||||||
active = tag.getBoolean("active");
|
active = tag.getBoolean("active");
|
||||||
treeTap = tag.getBoolean("treetap");
|
treeTap = tag.getBoolean("treetap");
|
||||||
silkTouchLeaves = tag.getBoolean("silkTouchLeaves");
|
silkTouchLeaves = tag.getBoolean("silkTouchLeaves");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldChunkLoad() {
|
public boolean shouldChunkLoad() {
|
||||||
return active;
|
return active;
|
||||||
|
@ -237,7 +238,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
|
|
||||||
// ComputerCraft IPeripheral methods implementation
|
// ComputerCraft IPeripheral methods implementation
|
||||||
@Override
|
@Override
|
||||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||||
String methodName = methodsArray[method];
|
String methodName = methodsArray[method];
|
||||||
if (methodName.equals("start")) {
|
if (methodName.equals("start")) {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
|
@ -269,7 +270,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
doLeaves = toBool(arguments[0]);
|
doLeaves = toBool(arguments[0]);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return new Boolean[] { doLeaves };
|
return new Boolean[] { doLeaves };
|
||||||
} else if (methodName.equals("silkTouch")) {
|
} else if (methodName.equals("silkTouch")) {
|
||||||
|
@ -306,13 +307,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
|
|
||||||
//ABSTRACT LASER IMPLEMENTATION
|
//ABSTRACT LASER IMPLEMENTATION
|
||||||
@Override
|
@Override
|
||||||
protected boolean silkTouch(int blockID) {
|
protected boolean silkTouch(Block block) {
|
||||||
if (isLeaf(blockID)) {
|
if (isLeaf(block)) {
|
||||||
return silkTouchLeaves;
|
return silkTouchLeaves;
|
||||||
}
|
}
|
||||||
return silkTouch();
|
return silkTouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canSilkTouch() {
|
protected boolean canSilkTouch() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -347,4 +348,16 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||||
protected float getColorB() {
|
protected float getColorB() {
|
||||||
return 0.4f;
|
return 0.4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSinkTier() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceTier() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue