Fixed LUA support for laser machines
- OC was missing the laserMediumCount() method - energy method was doing bad multithreading Code cleanup
This commit is contained in:
parent
d75bbcf269
commit
4efd20e323
6 changed files with 135 additions and 101 deletions
|
@ -0,0 +1,10 @@
|
|||
package cr0s.warpdrive.api.computer;
|
||||
|
||||
public interface IAbstractLaser extends IInterfaced {
|
||||
|
||||
Object[] energy();
|
||||
|
||||
Object[] laserMediumDirection();
|
||||
|
||||
Object[] laserMediumCount();
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cr0s.warpdrive.block;
|
||||
|
||||
import cr0s.warpdrive.api.computer.IAbstractLaser;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
@ -16,12 +17,17 @@ import cpw.mods.fml.common.Optional;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
// Abstract class to manage laser mediums
|
||||
public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfaced {
|
||||
// direction of the laser medium stack
|
||||
protected ForgeDirection directionLaserMedium = ForgeDirection.UNKNOWN;
|
||||
protected ForgeDirection[] directionsValidLaserMedium = ForgeDirection.VALID_DIRECTIONS;
|
||||
protected int laserMediumMaxCount = 0;
|
||||
protected int laserMediumCount = 0;
|
||||
public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfaced implements IAbstractLaser {
|
||||
|
||||
// configuration overridden by derived classes
|
||||
protected ForgeDirection[] laserMedium_directionsValid = ForgeDirection.VALID_DIRECTIONS;
|
||||
protected int laserMedium_maxCount = 0;
|
||||
|
||||
// computed properties
|
||||
protected ForgeDirection laserMedium_direction = ForgeDirection.UNKNOWN;
|
||||
protected int cache_laserMedium_count = 0;
|
||||
protected int cache_laserMedium_energyStored = 0;
|
||||
protected int cache_laserMedium_maxStorage = 0;
|
||||
|
||||
private final int updateInterval_ticks = 20 * WarpDriveConfig.SHIP_CONTROLLER_UPDATE_INTERVAL_SECONDS;
|
||||
private int updateTicks = updateInterval_ticks;
|
||||
|
@ -48,7 +54,7 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
|
|||
// accelerate update ticks during boot
|
||||
if (bootTicks > 0) {
|
||||
bootTicks--;
|
||||
if (directionLaserMedium == ForgeDirection.UNKNOWN) {
|
||||
if (laserMedium_direction == ForgeDirection.UNKNOWN) {
|
||||
updateTicks = 1;
|
||||
}
|
||||
}
|
||||
|
@ -56,59 +62,83 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
|
|||
if (updateTicks <= 0) {
|
||||
updateTicks = updateInterval_ticks;
|
||||
|
||||
updateLaserMediumStatus();
|
||||
updateLaserMediumDirection();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLaserMediumStatus() {
|
||||
for(ForgeDirection direction : directionsValidLaserMedium) {
|
||||
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++;
|
||||
private void updateLaserMediumDirection() {
|
||||
assert(laserMedium_maxCount != 0);
|
||||
|
||||
for (final ForgeDirection direction : laserMedium_directionsValid) {
|
||||
TileEntity tileEntity = worldObj.getTileEntity(
|
||||
xCoord + direction.offsetX,
|
||||
yCoord + direction.offsetY,
|
||||
zCoord + direction.offsetZ);
|
||||
|
||||
if (tileEntity instanceof TileEntityLaserMedium) {
|
||||
// at least one found
|
||||
int energyStored = 0;
|
||||
int maxStorage = 0;
|
||||
int count = 1;
|
||||
while ( (tileEntity instanceof TileEntityLaserMedium)
|
||||
&& count <= laserMedium_maxCount) {
|
||||
// add current one
|
||||
energyStored += ((TileEntityLaserMedium) tileEntity).energy_getEnergyStored();
|
||||
maxStorage += ((TileEntityLaserMedium) tileEntity).energy_getMaxStorage();
|
||||
count++;
|
||||
|
||||
// check next one
|
||||
tileEntity = worldObj.getTileEntity(
|
||||
xCoord + (laserMediumCount + 1) * direction.offsetX,
|
||||
yCoord + (laserMediumCount + 1) * direction.offsetY,
|
||||
zCoord + (laserMediumCount + 1) * direction.offsetZ);
|
||||
xCoord + (count + 1) * direction.offsetX,
|
||||
yCoord + (count + 1) * direction.offsetY,
|
||||
zCoord + (count + 1) * direction.offsetZ);
|
||||
}
|
||||
|
||||
// save results
|
||||
laserMedium_direction = direction;
|
||||
cache_laserMedium_count = count;
|
||||
cache_laserMedium_energyStored = energyStored;
|
||||
cache_laserMedium_maxStorage = maxStorage;
|
||||
return;
|
||||
}
|
||||
}
|
||||
directionLaserMedium = ForgeDirection.UNKNOWN;
|
||||
|
||||
// nothing found
|
||||
laserMedium_direction = ForgeDirection.UNKNOWN;
|
||||
cache_laserMedium_count = 0;
|
||||
cache_laserMedium_energyStored = 0;
|
||||
cache_laserMedium_maxStorage = 0;
|
||||
}
|
||||
|
||||
protected int getEnergyStored() {
|
||||
return consumeCappedEnergyFromLaserMediums(Integer.MAX_VALUE, true);
|
||||
protected int laserMedium_getEnergyStored() {
|
||||
return laserMedium_consumeUpTo(Integer.MAX_VALUE, true);
|
||||
}
|
||||
|
||||
protected boolean consumeEnergyFromLaserMediums(final int amount, final boolean simulate) {
|
||||
protected boolean laserMedium_consumeExactly(final int amountRequested, final boolean simulate) {
|
||||
final int amountSimulated = laserMedium_consumeUpTo(amountRequested, true);
|
||||
if (simulate) {
|
||||
return amount <= consumeCappedEnergyFromLaserMediums(amount, true);
|
||||
} else {
|
||||
if (amount > consumeCappedEnergyFromLaserMediums(amount, true)) {
|
||||
return false;
|
||||
} else {
|
||||
return amount <= consumeCappedEnergyFromLaserMediums(amount, false);
|
||||
}
|
||||
return amountRequested <= amountSimulated;
|
||||
}
|
||||
if (amountRequested > amountSimulated) {
|
||||
return false;
|
||||
}
|
||||
return amountRequested <= laserMedium_consumeUpTo(amountRequested, false);
|
||||
}
|
||||
|
||||
protected int consumeCappedEnergyFromLaserMediums(final int amount, final boolean simulate) {
|
||||
if (directionLaserMedium == ForgeDirection.UNKNOWN) {
|
||||
protected int laserMedium_consumeUpTo(final int amount, final boolean simulate) {
|
||||
if (laserMedium_direction == ForgeDirection.UNKNOWN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Primary scan of all laser mediums
|
||||
int totalEnergy = 0;
|
||||
int count = 1;
|
||||
List<TileEntityLaserMedium> laserMediums = new LinkedList<>();
|
||||
for (; count <= laserMediumMaxCount; count++) {
|
||||
TileEntity tileEntity = worldObj.getTileEntity(
|
||||
xCoord + count * directionLaserMedium.offsetX,
|
||||
yCoord + count * directionLaserMedium.offsetY,
|
||||
zCoord + count * directionLaserMedium.offsetZ);
|
||||
final List<TileEntityLaserMedium> laserMediums = new LinkedList<>();
|
||||
for (; count <= laserMedium_maxCount; count++) {
|
||||
final TileEntity tileEntity = worldObj.getTileEntity(
|
||||
xCoord + count * laserMedium_direction.offsetX,
|
||||
yCoord + count * laserMedium_direction.offsetY,
|
||||
zCoord + count * laserMedium_direction.offsetZ);
|
||||
if (!(tileEntity instanceof TileEntityLaserMedium)) {
|
||||
break;
|
||||
}
|
||||
|
@ -151,37 +181,22 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
|
|||
return energyTotalConsumed;
|
||||
}
|
||||
|
||||
protected Object[] energy() {
|
||||
if (directionLaserMedium == ForgeDirection.UNKNOWN) {
|
||||
return new Object[] { 0, 0 };
|
||||
} else {
|
||||
int energyStored = 0;
|
||||
int energyStoredMax = 0;
|
||||
int count = 1;
|
||||
// List<TileEntityLaserMedium> laserMediums = new LinkedList();
|
||||
for (; count <= laserMediumMaxCount; count++) {
|
||||
TileEntity tileEntity = worldObj.getTileEntity(
|
||||
xCoord + count * directionLaserMedium.offsetX,
|
||||
yCoord + count * directionLaserMedium.offsetY,
|
||||
zCoord + count * directionLaserMedium.offsetZ);
|
||||
if (!(tileEntity instanceof TileEntityLaserMedium)) {
|
||||
break;
|
||||
}
|
||||
// laserMediums.add((TileEntityLaserMedium) tileEntity);
|
||||
energyStored += ((TileEntityLaserMedium) tileEntity).energy_getEnergyStored();
|
||||
energyStoredMax += ((TileEntityLaserMedium) tileEntity).energy_getMaxStorage();
|
||||
}
|
||||
return new Object[] { energyStored, energyStoredMax };
|
||||
}
|
||||
// IAbstractLaser overrides
|
||||
@Override
|
||||
public Object[] energy() {
|
||||
return new Object[] { cache_laserMedium_energyStored, cache_laserMedium_maxStorage };
|
||||
}
|
||||
|
||||
protected Object[] laserMediumDirection() {
|
||||
return new Object[] { directionLaserMedium.name(), directionLaserMedium.offsetX, directionLaserMedium.offsetY, directionLaserMedium.offsetZ };
|
||||
@Override
|
||||
public Object[] laserMediumDirection() {
|
||||
return new Object[] { laserMedium_direction.name(), laserMedium_direction.offsetX, laserMedium_direction.offsetY, laserMedium_direction.offsetZ };
|
||||
}
|
||||
|
||||
protected Object[] laserMediumCount() {
|
||||
return new Object[] { laserMediumCount };
|
||||
@Override
|
||||
public Object[] laserMediumCount() {
|
||||
return new Object[] { cache_laserMedium_count };
|
||||
}
|
||||
|
||||
// OpenComputers callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
|
@ -195,6 +210,12 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractInterfac
|
|||
return laserMediumDirection();
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] laserMediumCount(Context context, Arguments arguments) {
|
||||
return laserMediumCount();
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
|
|
|
@ -78,7 +78,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
|
|||
"beamFrequency",
|
||||
"getScanResult"
|
||||
});
|
||||
laserMediumMaxCount = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT;
|
||||
laserMedium_maxCount = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,8 +118,8 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
|
|||
|| (beamFrequency == BEAM_FREQUENCY_SCANNING && delayTicks > WarpDriveConfig.LASER_CANNON_EMIT_SCAN_DELAY_TICKS))) {
|
||||
delayTicks = 0;
|
||||
isEmitting = false;
|
||||
int beamEnergy = Math.min(
|
||||
consumeCappedEnergyFromLaserMediums(Integer.MAX_VALUE, false) + MathHelper.floor_double(energyFromOtherBeams * WarpDriveConfig.LASER_CANNON_BOOSTER_BEAM_ENERGY_EFFICIENCY),
|
||||
final int beamEnergy = Math.min(
|
||||
laserMedium_consumeUpTo(Integer.MAX_VALUE, false) + MathHelper.floor_double(energyFromOtherBeams * WarpDriveConfig.LASER_CANNON_BOOSTER_BEAM_ENERGY_EFFICIENCY),
|
||||
WarpDriveConfig.LASER_CANNON_MAX_LASER_ENERGY);
|
||||
emitBeam(beamEnergy);
|
||||
energyFromOtherBeams = 0;
|
||||
|
|
|
@ -91,7 +91,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
"silktouch",
|
||||
"tapTrees"
|
||||
});
|
||||
laserMediumMaxCount = WarpDriveConfig.TREE_FARM_MAX_MEDIUMS_COUNT;
|
||||
laserMedium_maxCount = WarpDriveConfig.TREE_FARM_MAX_MEDIUMS_COUNT;
|
||||
CC_scripts = Arrays.asList("farm", "stop");
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
// check power level
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, true);
|
||||
enoughPower = laserMedium_consumeExactly(energyCost, true);
|
||||
if (!enoughPower) {
|
||||
currentState = STATE_WARMUP; // going back to warmup state to show the animation when it'll be back online
|
||||
delayTicks = 0;
|
||||
|
@ -194,7 +194,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
delayTicks = 0;
|
||||
|
||||
// consume power
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, false);
|
||||
enoughPower = laserMedium_consumeExactly(energyCost, false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNING_LOW_POWER);
|
||||
|
@ -274,7 +274,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
// consume power
|
||||
final int energyCost = TREE_FARM_ENERGY_PER_WET_SPOT;
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, false);
|
||||
enoughPower = laserMedium_consumeExactly(energyCost, false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMING_LOW_POWER);
|
||||
|
@ -311,7 +311,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
if (enableSilktouch) {
|
||||
energyCost *= TREE_FARM_SILKTOUCH_ENERGY_FACTOR;
|
||||
}
|
||||
enoughPower = consumeEnergyFromLaserMediums((int) Math.round(energyCost), false);
|
||||
enoughPower = laserMedium_consumeExactly((int) Math.round(energyCost), false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMING_LOW_POWER);
|
||||
|
@ -435,7 +435,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
// consume power
|
||||
final int energyCost = TREE_FARM_ENERGY_PER_SAPLING;
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, false);
|
||||
enoughPower = laserMedium_consumeExactly(energyCost, false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_PLANTING_LOW_POWER);
|
||||
|
@ -481,7 +481,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
private LinkedList<VectorI> scanSoils() {
|
||||
int maxRadius = WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_NO_LASER_MEDIUM + laserMediumCount * WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_PER_LASER_MEDIUM;
|
||||
int maxRadius = WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_NO_LASER_MEDIUM + cache_laserMedium_count * WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_PER_LASER_MEDIUM;
|
||||
int xMin = xCoord - Math.min(radiusX, maxRadius);
|
||||
int xMax = xCoord + Math.min(radiusX, maxRadius);
|
||||
int yMin = yCoord;
|
||||
|
@ -514,13 +514,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
private Collection<VectorI> scanTrees() {
|
||||
int maxRadius = WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_NO_LASER_MEDIUM + laserMediumCount * WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_PER_LASER_MEDIUM;
|
||||
int xMin = xCoord - Math.min(radiusX, maxRadius);
|
||||
int xMax = xCoord + Math.min(radiusX, maxRadius);
|
||||
int yMin = yCoord + 1;
|
||||
int yMax = yCoord + 1 + (tapTrees ? 8 : 0);
|
||||
int zMin = zCoord - Math.min(radiusZ, maxRadius);
|
||||
int zMax = zCoord + Math.min(radiusZ, maxRadius);
|
||||
final int maxScanRadius = WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_NO_LASER_MEDIUM + cache_laserMedium_count * WarpDriveConfig.TREE_FARM_MAX_SCAN_RADIUS_PER_LASER_MEDIUM;
|
||||
final int xMin = xCoord - Math.min(radiusX, maxScanRadius);
|
||||
final int xMax = xCoord + Math.min(radiusX, maxScanRadius);
|
||||
final int yMin = yCoord + 1;
|
||||
final int yMax = yCoord + 1 + (tapTrees ? 8 : 0);
|
||||
final int zMin = zCoord - Math.min(radiusZ, maxScanRadius);
|
||||
final int zMax = zCoord + Math.min(radiusZ, maxScanRadius);
|
||||
|
||||
Collection<VectorI> logPositions = new HashSet<>();
|
||||
|
||||
|
@ -542,11 +542,12 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
if (!logPositions.isEmpty()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
HashSet<Block> whitelist = (HashSet<Block>) Dictionary.BLOCKS_LOGS.clone();
|
||||
final HashSet<Block> whitelist = (HashSet<Block>) Dictionary.BLOCKS_LOGS.clone();
|
||||
if (breakLeaves) {
|
||||
whitelist.addAll(Dictionary.BLOCKS_LEAVES);
|
||||
}
|
||||
logPositions = Commons.getConnectedBlocks(worldObj, logPositions, Commons.UP_DIRECTIONS, whitelist, WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE + laserMediumCount * WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE_PER_MEDIUM);
|
||||
final int maxLogDistance = WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE + cache_laserMedium_count * WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE_PER_MEDIUM;
|
||||
logPositions = Commons.getConnectedBlocks(worldObj, logPositions, Commons.UP_DIRECTIONS, whitelist, maxLogDistance);
|
||||
}
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found " + logPositions.size() + " valuables");
|
||||
|
@ -644,7 +645,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
private Object[] state() {
|
||||
final int energy = getEnergyStored();
|
||||
final int energy = laserMedium_getEnergyStored();
|
||||
final String status = getStatusHeaderInPureText();
|
||||
final Integer retValuables, retValuablesIndex;
|
||||
if (isFarming() && valuables != null) {
|
||||
|
@ -745,7 +746,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
@Override
|
||||
public String getStatusHeader() {
|
||||
final int energy = getEnergyStored();
|
||||
final int energy = laserMedium_getEnergyStored();
|
||||
String state = "IDLE (not farming)";
|
||||
if (currentState == STATE_IDLE) {
|
||||
state = "IDLE (not farming)";
|
||||
|
|
|
@ -47,6 +47,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
private boolean enoughPower = false;
|
||||
private int currentLayer;
|
||||
|
||||
private int radiusCapacity = WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS;
|
||||
private final ArrayList<VectorI> valuablesInLayer = new ArrayList<>();
|
||||
private int valuableIndex = 0;
|
||||
|
||||
|
@ -63,7 +64,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
"silktouch"
|
||||
});
|
||||
CC_scripts = Arrays.asList("mine", "stop");
|
||||
laserMediumMaxCount = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT;
|
||||
laserMedium_maxCount = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryReturnStatement")
|
||||
|
@ -90,6 +91,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
final boolean isOnPlanet = CelestialObjectManager.hasAtmosphere(worldObj, xCoord, zCoord);
|
||||
radiusCapacity = WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + cache_laserMedium_count - 1;
|
||||
|
||||
delayTicks--;
|
||||
if (currentState == STATE_WARMUP) {
|
||||
|
@ -104,7 +106,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
} else if (currentState == STATE_SCANNING) {
|
||||
if (delayTicks == WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS - 1) {
|
||||
// check power level
|
||||
enoughPower = consumeEnergyFromLaserMediums(isOnPlanet ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER, true);
|
||||
enoughPower = laserMedium_consumeExactly(isOnPlanet ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER, true);
|
||||
if (!enoughPower) {
|
||||
updateMetadata(BlockMiningLaser.ICON_SCANNING_LOW_POWER);
|
||||
delayTicks = WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS;
|
||||
|
@ -115,10 +117,10 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
|
||||
// show current layer
|
||||
int age = Math.max(40, 5 * WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS);
|
||||
double xMax = xCoord + WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 1.0D;
|
||||
double xMin = xCoord - WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 0.0D;
|
||||
double zMax = zCoord + WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 1.0D;
|
||||
double zMin = zCoord - WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 0.0D;
|
||||
double xMax = xCoord + radiusCapacity + 1.0D;
|
||||
double xMin = xCoord - radiusCapacity + 0.0D;
|
||||
double zMax = zCoord + radiusCapacity + 1.0D;
|
||||
double zMin = zCoord - radiusCapacity + 0.0D;
|
||||
double y = currentLayer + 1.0D;
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xMin, y, zMin), new Vector3(xMax, y, zMin), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xMax, y, zMin), new Vector3(xMax, y, zMax), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
|
@ -133,7 +135,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
// consume power
|
||||
enoughPower = consumeEnergyFromLaserMediums(isOnPlanet ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER, false);
|
||||
enoughPower = laserMedium_consumeExactly(isOnPlanet ? 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;
|
||||
|
@ -145,7 +147,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
// scan
|
||||
scanLayer();
|
||||
if (!valuablesInLayer.isEmpty()) {
|
||||
int r = (int) Math.ceil(WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS / 2.0D);
|
||||
int r = (int) Math.ceil(radiusCapacity / 2.0D);
|
||||
int offset = (yCoord - currentLayer) % (2 * r);
|
||||
int age = Math.max(20, Math.round(2.5F * WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS));
|
||||
double y = currentLayer + 1.0D;
|
||||
|
@ -194,7 +196,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
if (enableSilktouch) {
|
||||
requiredPower *= WarpDriveConfig.MINING_LASER_SILKTOUCH_ENERGY_FACTOR;
|
||||
}
|
||||
enoughPower = consumeEnergyFromLaserMediums(requiredPower, false);
|
||||
enoughPower = laserMedium_consumeExactly(requiredPower, false);
|
||||
if (!enoughPower) {
|
||||
updateMetadata(BlockMiningLaser.ICON_MINING_LOW_POWER);
|
||||
return;
|
||||
|
@ -296,7 +298,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
for (radius = 1; radius <= WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS; radius++) {
|
||||
for (radius = 1; radius <= radiusCapacity; radius++) {
|
||||
xMax = xCoord + radius;
|
||||
xMin = xCoord - radius;
|
||||
zMax = zCoord + radius;
|
||||
|
@ -432,7 +434,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
}
|
||||
|
||||
private Object[] state() {
|
||||
final int energy = getEnergyStored();
|
||||
final int energy = laserMedium_getEnergyStored();
|
||||
final String status = getStatusHeaderInPureText();
|
||||
final Integer retValuablesInLayer, retValuablesMined;
|
||||
if (isActive()) {
|
||||
|
@ -521,7 +523,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
|
||||
@Override
|
||||
public String getStatusHeader() {
|
||||
final int energy = getEnergyStored();
|
||||
final int energy = laserMedium_getEnergyStored();
|
||||
String state = "IDLE (not mining)";
|
||||
if (currentState == STATE_IDLE) {
|
||||
state = "IDLE (not mining)";
|
||||
|
|
|
@ -36,8 +36,8 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser {
|
|||
"stabilize"
|
||||
});
|
||||
peripheralName = "warpdriveEnanReactorLaser";
|
||||
laserMediumMaxCount = 1;
|
||||
directionsValidLaserMedium = new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN };
|
||||
laserMedium_maxCount = 1;
|
||||
laserMedium_directionsValid = new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN };
|
||||
}
|
||||
|
||||
public void scanForReactor() {
|
||||
|
@ -119,13 +119,13 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser {
|
|||
}
|
||||
|
||||
scanForReactor();
|
||||
if (directionLaserMedium == ForgeDirection.UNKNOWN) {
|
||||
if (laserMedium_direction == ForgeDirection.UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
if (reactor == null) {
|
||||
return;
|
||||
}
|
||||
if (consumeEnergyFromLaserMediums(energy, false)) {
|
||||
if (laserMedium_consumeExactly(energy, false)) {
|
||||
if (WarpDriveConfig.LOGGING_ENERGY && WarpDriveConfig.LOGGING_LUA) {
|
||||
WarpDrive.logger.info("ReactorLaser on " + side + " side sending " + energy);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue