Fixed various issues with mining lasers

Fixed a hardness bypass
Fixed state engine to properly cooldown in case of low power
This commit is contained in:
LemADEC 2016-07-25 23:49:15 +02:00
parent 6b8684c093
commit 3bafe38464
3 changed files with 29 additions and 22 deletions

View file

@ -113,6 +113,10 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
boolean overflow = false;
if (itemStacks != null) {
for (ItemStack itemStack : itemStacks) {
if (itemStack.getItem() == null) {
WarpDrive.logger.error(this + "Invalid itemStack with null item...");
continue;
}
int qtyLeft = itemStack.stackSize;
ItemStack itemStackLeft = itemStack.copy();
for (IInventory inventory : inventories) {
@ -143,7 +147,7 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
}
private static int addToInventory(final ItemStack itemStackSource, IInventory inventory) {
if (itemStackSource == null) {
if (itemStackSource == null || itemStackSource.getItem() == null) {
return 0;
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
@ -42,6 +43,9 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
protected void harvestBlock(VectorI valuable) {
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
if (block == Blocks.air) {
return;
}
int blockMeta = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
if (block != null && (block instanceof BlockLiquid)) {
// Evaporate fluid
@ -60,6 +64,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
private List<ItemStack> getItemStackFromBlock(int x, int y, int z, Block block, int blockMeta) {
if (block == null) {
WarpDrive.logger.error(this + " Invalid block at " + x + " " + y + " " + z);
return null;
}
if (enableSilktouch) {

View file

@ -31,9 +31,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
private int layerOffset = 1;
private boolean mineAllBlocks = true;
private int delayTicksWarmup = 0;
private int delayTicksScan = 0;
private int delayTicksMine = 0;
private int delayTicks = 0;
private static final int STATE_IDLE = 0;
private static final int STATE_WARMUP = 1;
@ -73,9 +71,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
}
if (currentState == STATE_IDLE) {
delayTicksWarmup = 0;
delayTicksScan = 0;
delayTicksMine = 0;
delayTicks = WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS;
updateMetadata(BlockMiningLaser.ICON_IDLE);
// force start if no computer control is available
@ -90,23 +86,23 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
boolean isOnEarth = isOnPlanet();
delayTicks--;
if (currentState == STATE_WARMUP) {
delayTicksWarmup++;
updateMetadata(BlockMiningLaser.ICON_SCANNING_LOW_POWER);
if (delayTicksWarmup >= WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS) {
delayTicksScan = 0;
if (delayTicks < 0) {
delayTicks = WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS;
currentState = STATE_SCANNING;
updateMetadata(BlockMiningLaser.ICON_SCANNING_LOW_POWER);
return;
}
} else if (currentState == STATE_SCANNING) {
delayTicksScan++;
if (delayTicksScan == 1) {
if (delayTicks == WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS - 1) {
// check power level
enoughPower = consumeEnergyFromLaserMediums(isOnEarth ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER, true);
if (!enoughPower) {
updateMetadata(BlockMiningLaser.ICON_SCANNING_LOW_POWER);
delayTicksScan = 0;
delayTicks = WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS;
return;
} else {
updateMetadata(BlockMiningLaser.ICON_SCANNING_POWERED);
@ -124,8 +120,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
PacketHandler.sendBeamPacket(worldObj, new Vector3(xMax, y, zMax), new Vector3(xMin, y, zMax), 0.3F, 0.0F, 1.0F, age, 0, 50);
PacketHandler.sendBeamPacket(worldObj, new Vector3(xMin, y, zMax), new Vector3(xMin, y, zMin), 0.3F, 0.0F, 1.0F, age, 0, 50);
} else if (delayTicksScan >= WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS) {
delayTicksScan = 0;
} else if (delayTicks < 0) {
delayTicks = WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS;
if (currentLayer <= 0) {
stop();
return;
@ -135,6 +131,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
enoughPower = consumeEnergyFromLaserMediums(isOnEarth ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER, false);
if (!enoughPower) {
updateMetadata(BlockMiningLaser.ICON_SCANNING_LOW_POWER);
delayTicks = WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS;
return;
} else {
updateMetadata(BlockMiningLaser.ICON_SCANNING_POWERED);
@ -156,7 +153,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(xCoord - r, y, zCoord - r + offset).translate(0.3D),
0.0F, 0.0F, 1.0F, age, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
delayTicksMine = 0;
delayTicks = WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS;
currentState = STATE_MINING;
updateMetadata(BlockMiningLaser.ICON_MINING_POWERED);
return;
@ -167,12 +165,11 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
}
}
} else if (currentState == STATE_MINING) {
delayTicksMine++;
if (delayTicksMine >= WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS) {
delayTicksMine = 0;
if (delayTicks < 0) {
delayTicks = WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS;
if (valuableIndex < 0 || valuableIndex >= valuablesInLayer.size()) {
delayTicksScan = 0;
delayTicks = WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS;
currentState = STATE_SCANNING;
updateMetadata(BlockMiningLaser.ICON_SCANNING_POWERED);
@ -208,7 +205,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
// Skip if block is too hard or its empty block (check again in case it changed)
if (!canDig(block, valuable.x, valuable.y, valuable.z)) {
delayTicksMine = Math.round(WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS * 0.8F);
delayTicks = Math.round(WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS * 0.2F);
return;
}
int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS));
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(valuable.x, valuable.y, valuable.z).translate(0.5D),
@ -419,7 +417,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
}
enableSilktouch &= canSilktouch;
delayTicksWarmup = 0;
delayTicks = WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS;
currentState = STATE_WARMUP;
currentLayer = yCoord - layerOffset - 1;
if (WarpDriveConfig.LOGGING_LUA) {