From dce510cdfe01d791b28d8a2044a0d3b75467411a Mon Sep 17 00:00:00 2001 From: LemADEC Date: Tue, 17 Nov 2015 16:32:16 +0100 Subject: [PATCH] Added laserMediumCount to LUA API --- .../block/TileEntityAbstractLaser.java | 29 ++++++++++++++----- .../cr0s/warpdrive/block/TileEntityLaser.java | 2 +- .../collection/TileEntityMiningLaser.java | 12 ++++---- .../energy/TileEntityEnanReactorLaser.java | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/block/TileEntityAbstractLaser.java b/src/main/java/cr0s/warpdrive/block/TileEntityAbstractLaser.java index 957bddb6..0e1bc6bc 100644 --- a/src/main/java/cr0s/warpdrive/block/TileEntityAbstractLaser.java +++ b/src/main/java/cr0s/warpdrive/block/TileEntityAbstractLaser.java @@ -20,7 +20,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac // direction of the laser medium stack protected ForgeDirection directionLaserMedium = ForgeDirection.UNKNOWN; protected ForgeDirection[] directionsValidLaserMedium = ForgeDirection.VALID_DIRECTIONS; - protected int countMaxLaserMediums = 0; + protected int laserMediumMaxCount = 0; + protected int laserMediumCount = 0; private final int updateInterval_ticks = 20 * WarpDriveConfig.SHIP_CONTROLLER_UPDATE_INTERVAL_SECONDS; private int updateTicks = updateInterval_ticks; @@ -31,7 +32,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac addMethods(new String[] { "energy", - "laserMediumDirection" + "laserMediumDirection", + "laserMediumCount" }); } @@ -54,15 +56,23 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac if (updateTicks <= 0) { updateTicks = updateInterval_ticks; - updateLaserMediumDirection(); + updateLaserMediumStatus(); } } - private void updateLaserMediumDirection() { + private void updateLaserMediumStatus() { for(ForgeDirection direction : directionsValidLaserMedium) { - TileEntity tileEntity = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); + TileEntity tileEntity = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); if (tileEntity != null && tileEntity instanceof TileEntityLaserMedium) { directionLaserMedium = direction; + laserMediumCount = 0; + while(tileEntity != null && tileEntity instanceof TileEntityLaserMedium && laserMediumCount < laserMediumMaxCount) { + laserMediumCount++; + tileEntity = worldObj.getTileEntity( + xCoord + laserMediumMaxCount * direction.offsetX, + yCoord + laserMediumMaxCount * direction.offsetY, + zCoord + laserMediumMaxCount * direction.offsetZ); + } return; } } @@ -87,7 +97,7 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac int totalEnergy = 0; int count = 1; List laserMediums = new LinkedList(); - for (; count <= countMaxLaserMediums; count++) { + for (; count <= laserMediumMaxCount; count++) { TileEntity tileEntity = worldObj.getTileEntity( xCoord + count * directionLaserMedium.offsetX, yCoord + count * directionLaserMedium.offsetY, @@ -142,7 +152,7 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac int energyStoredMax = 0; int count = 1; List laserMediums = new LinkedList(); - for (; count <= countMaxLaserMediums; count++) { + for (; count <= laserMediumMaxCount; count++) { TileEntity tileEntity = worldObj.getTileEntity( xCoord + count * directionLaserMedium.offsetX, yCoord + count * directionLaserMedium.offsetY, @@ -162,6 +172,9 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac return new Object[] { directionLaserMedium.name(), directionLaserMedium.offsetX, directionLaserMedium.offsetY, directionLaserMedium.offsetZ }; } + protected Object[] laserMediumCount() { + return new Object[] { laserMediumCount }; + } // OpenComputers callback methods @Callback @Optional.Method(modid = "OpenComputers") @@ -185,6 +198,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac return energy(); } else if (methodName.equals("laserMediumDirection")) { return laserMediumDirection(); + } else if (methodName.equals("laserMediumCount")) { + return laserMediumCount(); } return super.callMethod(computer, context, method, arguments); diff --git a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java index 254ff260..724996ea 100644 --- a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java +++ b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java @@ -77,7 +77,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser { "getScanResult", "videoChannel" }); - countMaxLaserMediums = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT; + laserMediumMaxCount = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT; } @Override diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java index 7556b040..1984924c 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java @@ -24,7 +24,7 @@ import dan200.computercraft.api.peripheral.IComputerAccess; public class TileEntityMiningLaser extends TileEntityAbstractMiner { private final boolean canSilktouch = (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium")); - private boolean isMining() { + private boolean isActive() { return currentState != STATE_IDLE; } @@ -60,7 +60,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner { "silktouch" }); CC_scripts = Arrays.asList("mine", "stop"); - countMaxLaserMediums = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT; + laserMediumMaxCount = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT; } @Override @@ -375,7 +375,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner { // Common OC/CC methods private Object[] start(Object[] arguments) { - if (isMining()) { + if (isActive()) { return new Object[] { false, "Already started" }; } @@ -390,13 +390,13 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner { int energy = getEnergyStored(); String status = getStatus(); Integer retValuablesInLayer, retValuablesMined; - if (isMining()) { + if (isActive()) { retValuablesInLayer = valuablesInLayer.size(); retValuablesMined = valuableIndex; - return new Object[] { status, isMining(), energy, currentLayer, retValuablesMined, retValuablesInLayer }; + return new Object[] { status, isActive(), energy, currentLayer, retValuablesMined, retValuablesInLayer }; } - return new Object[] { status, isMining(), energy, currentLayer, 0, 0 }; + return new Object[] { status, isActive(), energy, currentLayer, 0, 0 }; } private Object[] onlyOres(Object[] arguments) { diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java index 9f834793..f6603c09 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java @@ -32,7 +32,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser { "stabilize" }); peripheralName = "warpdriveEnanReactorLaser"; - countMaxLaserMediums = 1; + laserMediumMaxCount = 1; directionsValidLaserMedium = new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN }; }