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