Added laserMediumCount to LUA API

This commit is contained in:
LemADEC 2015-11-17 16:32:16 +01:00
parent 70cf61d797
commit dce510cdfe
4 changed files with 30 additions and 15 deletions

View file

@ -20,7 +20,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
// direction of the laser medium stack // direction of the laser medium stack
protected ForgeDirection directionLaserMedium = ForgeDirection.UNKNOWN; protected ForgeDirection directionLaserMedium = ForgeDirection.UNKNOWN;
protected ForgeDirection[] directionsValidLaserMedium = ForgeDirection.VALID_DIRECTIONS; 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 final int updateInterval_ticks = 20 * WarpDriveConfig.SHIP_CONTROLLER_UPDATE_INTERVAL_SECONDS;
private int updateTicks = updateInterval_ticks; private int updateTicks = updateInterval_ticks;
@ -31,7 +32,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
addMethods(new String[] { addMethods(new String[] {
"energy", "energy",
"laserMediumDirection" "laserMediumDirection",
"laserMediumCount"
}); });
} }
@ -54,15 +56,23 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
if (updateTicks <= 0) { if (updateTicks <= 0) {
updateTicks = updateInterval_ticks; updateTicks = updateInterval_ticks;
updateLaserMediumDirection(); updateLaserMediumStatus();
} }
} }
private void updateLaserMediumDirection() { private void updateLaserMediumStatus() {
for(ForgeDirection direction : directionsValidLaserMedium) { 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) { if (tileEntity != null && tileEntity instanceof TileEntityLaserMedium) {
directionLaserMedium = direction; 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; return;
} }
} }
@ -87,7 +97,7 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
int totalEnergy = 0; int totalEnergy = 0;
int count = 1; int count = 1;
List<TileEntityLaserMedium> laserMediums = new LinkedList(); List<TileEntityLaserMedium> laserMediums = new LinkedList();
for (; count <= countMaxLaserMediums; count++) { for (; count <= laserMediumMaxCount; count++) {
TileEntity tileEntity = worldObj.getTileEntity( TileEntity tileEntity = worldObj.getTileEntity(
xCoord + count * directionLaserMedium.offsetX, xCoord + count * directionLaserMedium.offsetX,
yCoord + count * directionLaserMedium.offsetY, yCoord + count * directionLaserMedium.offsetY,
@ -142,7 +152,7 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
int energyStoredMax = 0; int energyStoredMax = 0;
int count = 1; int count = 1;
List<TileEntityLaserMedium> laserMediums = new LinkedList(); List<TileEntityLaserMedium> laserMediums = new LinkedList();
for (; count <= countMaxLaserMediums; count++) { for (; count <= laserMediumMaxCount; count++) {
TileEntity tileEntity = worldObj.getTileEntity( TileEntity tileEntity = worldObj.getTileEntity(
xCoord + count * directionLaserMedium.offsetX, xCoord + count * directionLaserMedium.offsetX,
yCoord + count * directionLaserMedium.offsetY, 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 }; return new Object[] { directionLaserMedium.name(), directionLaserMedium.offsetX, directionLaserMedium.offsetY, directionLaserMedium.offsetZ };
} }
protected Object[] laserMediumCount() {
return new Object[] { laserMediumCount };
}
// OpenComputers callback methods // OpenComputers callback methods
@Callback @Callback
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
@ -185,6 +198,8 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
return energy(); return energy();
} else if (methodName.equals("laserMediumDirection")) { } else if (methodName.equals("laserMediumDirection")) {
return laserMediumDirection(); return laserMediumDirection();
} else if (methodName.equals("laserMediumCount")) {
return laserMediumCount();
} }
return super.callMethod(computer, context, method, arguments); return super.callMethod(computer, context, method, arguments);

View file

@ -77,7 +77,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser {
"getScanResult", "getScanResult",
"videoChannel" "videoChannel"
}); });
countMaxLaserMediums = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT; laserMediumMaxCount = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT;
} }
@Override @Override

View file

@ -24,7 +24,7 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityMiningLaser extends TileEntityAbstractMiner { public class TileEntityMiningLaser extends TileEntityAbstractMiner {
private final boolean canSilktouch = (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium")); private final boolean canSilktouch = (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium"));
private boolean isMining() { private boolean isActive() {
return currentState != STATE_IDLE; return currentState != STATE_IDLE;
} }
@ -60,7 +60,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
"silktouch" "silktouch"
}); });
CC_scripts = Arrays.asList("mine", "stop"); CC_scripts = Arrays.asList("mine", "stop");
countMaxLaserMediums = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT; laserMediumMaxCount = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT;
} }
@Override @Override
@ -375,7 +375,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
// Common OC/CC methods // Common OC/CC methods
private Object[] start(Object[] arguments) { private Object[] start(Object[] arguments) {
if (isMining()) { if (isActive()) {
return new Object[] { false, "Already started" }; return new Object[] { false, "Already started" };
} }
@ -390,13 +390,13 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
int energy = getEnergyStored(); int energy = getEnergyStored();
String status = getStatus(); String status = getStatus();
Integer retValuablesInLayer, retValuablesMined; Integer retValuablesInLayer, retValuablesMined;
if (isMining()) { if (isActive()) {
retValuablesInLayer = valuablesInLayer.size(); retValuablesInLayer = valuablesInLayer.size();
retValuablesMined = valuableIndex; 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) { private Object[] onlyOres(Object[] arguments) {

View file

@ -32,7 +32,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser {
"stabilize" "stabilize"
}); });
peripheralName = "warpdriveEnanReactorLaser"; peripheralName = "warpdriveEnanReactorLaser";
countMaxLaserMediums = 1; laserMediumMaxCount = 1;
directionsValidLaserMedium = new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN }; directionsValidLaserMedium = new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN };
} }