Implemented projector LUA API (wip)
Fixed SMP support Fixed CME when changing shape parameters Improved projector guide messages Fixed server lag issue (wip)
This commit is contained in:
parent
d1de099e3a
commit
03f284948e
5 changed files with 100 additions and 39 deletions
|
@ -18,19 +18,19 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class BlockForceFieldRelay extends BlockAbstractForceField {
|
public class BlockForceFieldRelay extends BlockAbstractForceField {
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private final IIcon[] icons;
|
private IIcon[] icons;
|
||||||
|
|
||||||
public BlockForceFieldRelay(final byte tier) {
|
public BlockForceFieldRelay(final byte tier) {
|
||||||
super(tier, Material.iron);
|
super(tier, Material.iron);
|
||||||
isRotating = false;
|
isRotating = false;
|
||||||
setBlockName("warpdrive.forcefield.relay" + tier);
|
setBlockName("warpdrive.forcefield.relay" + tier);
|
||||||
setBlockTextureName("warpdrive:forcefield/relay");
|
setBlockTextureName("warpdrive:forcefield/relay");
|
||||||
|
|
||||||
icons = new IIcon[EnumForceFieldUpgrade.length + 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||||
|
icons = new IIcon[EnumForceFieldUpgrade.length + 1];
|
||||||
|
|
||||||
for (EnumForceFieldUpgrade enumForceFieldUpgrade : EnumForceFieldUpgrade.values()) {
|
for (EnumForceFieldUpgrade enumForceFieldUpgrade : EnumForceFieldUpgrade.values()) {
|
||||||
if (enumForceFieldUpgrade.maxCountOnRelay > 0) {
|
if (enumForceFieldUpgrade.maxCountOnRelay > 0) {
|
||||||
icons[enumForceFieldUpgrade.ordinal()] = iconRegister.registerIcon("warpdrive:forcefield/relay" + "_" + enumForceFieldUpgrade.unlocalizedName);
|
icons[enumForceFieldUpgrade.ordinal()] = iconRegister.registerIcon("warpdrive:forcefield/relay" + "_" + enumForceFieldUpgrade.unlocalizedName);
|
||||||
|
|
|
@ -112,8 +112,8 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
String strEnergyStatus = getEnergyStatus();
|
String strEnergyStatus = getEnergyStatus();
|
||||||
return (worldObj != null ? StatCollector.translateToLocalFormatted("warpdrive.guide.prefix", getBlockType().getLocalizedName()) : "")
|
return (worldObj != null ? StatCollector.translateToLocalFormatted("warpdrive.guide.prefix", getBlockType().getLocalizedName()) : "")
|
||||||
+ getBeamFrequencyStatus()
|
+ (strEnergyStatus.isEmpty() ? "" : "\n" + strEnergyStatus
|
||||||
+ (strEnergyStatus.isEmpty() ? "" : "\n" + strEnergyStatus);
|
+ "\n" + getBeamFrequencyStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,11 @@ import cr0s.warpdrive.api.IForceFieldShape;
|
||||||
import cr0s.warpdrive.config.*;
|
import cr0s.warpdrive.config.*;
|
||||||
import cr0s.warpdrive.config.Dictionary;
|
import cr0s.warpdrive.config.Dictionary;
|
||||||
import cr0s.warpdrive.data.*;
|
import cr0s.warpdrive.data.*;
|
||||||
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.BlockStaticLiquid;
|
import net.minecraft.block.BlockStaticLiquid;
|
||||||
|
@ -29,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class TileEntityForceFieldProjector extends TileEntityAbstractForceField {
|
public class TileEntityForceFieldProjector extends TileEntityAbstractForceField {
|
||||||
private static final int PROJECTOR_MAX_ENERGY_STORED = 10000;
|
private static final int PROJECTOR_MAX_ENERGY_STORED = 10000;
|
||||||
private static final int PROJECTOR_COOLDOWN_TICKS = 20;
|
private static final int PROJECTOR_COOLDOWN_TICKS = 100;
|
||||||
public static final int PROJECTOR_PROJECTION_UPDATE_TICKS = 8;
|
public static final int PROJECTOR_PROJECTION_UPDATE_TICKS = 8;
|
||||||
private static final int PROJECTOR_SETUP_TICKS = 20;
|
private static final int PROJECTOR_SETUP_TICKS = 20;
|
||||||
private static final int PROJECTOR_SOUND_UPDATE_TICKS = 100;
|
private static final int PROJECTOR_SOUND_UPDATE_TICKS = 100;
|
||||||
|
@ -76,7 +81,8 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
|
|
||||||
peripheralName = "warpdriveForceFieldProjector";
|
peripheralName = "warpdriveForceFieldProjector";
|
||||||
addMethods(new String[] {
|
addMethods(new String[] {
|
||||||
"status" // isConnected, isPowered, shape
|
"rotation",
|
||||||
|
"state"
|
||||||
});
|
});
|
||||||
|
|
||||||
for (EnumForceFieldUpgrade enumForceFieldUpgrade : EnumForceFieldUpgrade.values()) {
|
for (EnumForceFieldUpgrade enumForceFieldUpgrade : EnumForceFieldUpgrade.values()) {
|
||||||
|
@ -243,11 +249,15 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
return calculated_forceField.contains(vector);
|
return calculated_forceField.contains(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<VectorI> getInteriorPoints() {
|
private boolean isPartOfInterior(VectorI vector) {
|
||||||
if (!isCalculated()) {
|
if (!isEnabled || !isValid()) {
|
||||||
throw new ConcurrentModificationException("Calculation ongoing...");
|
return false;
|
||||||
}
|
}
|
||||||
return calculated_interiorField;
|
if (!isCalculated()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// only consider the forcefield interior
|
||||||
|
return calculated_interiorField.contains(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void projectForceField() {
|
private void projectForceField() {
|
||||||
|
@ -296,7 +306,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
// skip if fusion upgrade is present and it's inside another projector area
|
// skip if fusion upgrade is present and it's inside another projector area
|
||||||
if (forceFieldSetup.hasFusion) {
|
if (forceFieldSetup.hasFusion) {
|
||||||
for (TileEntityForceFieldProjector projector : forceFieldSetup.projectors) {
|
for (TileEntityForceFieldProjector projector : forceFieldSetup.projectors) {
|
||||||
if (projector.getInteriorPoints().contains(vector)) {
|
if (projector.isPartOfInterior(vector)) {
|
||||||
doProjectThisBlock = false;
|
doProjectThisBlock = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +369,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
if (doProjectThisBlock) {
|
if (doProjectThisBlock) {
|
||||||
if (forceFieldSetup.breaking_maxHardness > 0) {
|
if (forceFieldSetup.breaking_maxHardness > 0) {
|
||||||
doProjectThisBlock = ! isBlockBreakCanceled(null, worldObj, vector.x, vector.y, vector.z);
|
doProjectThisBlock = ! isBlockBreakCanceled(null, worldObj, vector.x, vector.y, vector.z);
|
||||||
} else {
|
} else if (!(block instanceof BlockForceField)) {
|
||||||
doProjectThisBlock = ! isBlockPlaceCanceled(null, worldObj, vector.x, vector.y, vector.z, WarpDrive.blockForceFields[tier - 1], metadataForceField);
|
doProjectThisBlock = ! isBlockPlaceCanceled(null, worldObj, vector.x, vector.y, vector.z, WarpDrive.blockForceFields[tier - 1], metadataForceField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -571,6 +581,23 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnumForceFieldShape getShape() {
|
||||||
|
if (shape == null) {
|
||||||
|
return EnumForceFieldShape.NONE;
|
||||||
|
}
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setShape(EnumForceFieldShape shape) {
|
||||||
|
this.shape = shape;
|
||||||
|
cache_forceFieldSetup = null;
|
||||||
|
isDirty.set(true);
|
||||||
|
markDirty();
|
||||||
|
if (worldObj != null) {
|
||||||
|
destroyForceField(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mountUpgrade(Object upgrade) {
|
public boolean mountUpgrade(Object upgrade) {
|
||||||
if (super.mountUpgrade(upgrade)) {
|
if (super.mountUpgrade(upgrade)) {
|
||||||
|
@ -693,21 +720,55 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumForceFieldShape getShape() {
|
// OpenComputer callback methods
|
||||||
if (shape == null) {
|
@Callback
|
||||||
return EnumForceFieldShape.NONE;
|
@cpw.mods.fml.common.Optional.Method(modid = "OpenComputers")
|
||||||
}
|
public Object[] state(Context context, Arguments arguments) {
|
||||||
return shape;
|
return state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setShape(EnumForceFieldShape shape) {
|
@Callback
|
||||||
this.shape = shape;
|
@cpw.mods.fml.common.Optional.Method(modid = "OpenComputers")
|
||||||
cache_forceFieldSetup = null;
|
public Object[] rotation(Context context, Arguments arguments) {
|
||||||
isDirty.set(true);
|
if (arguments.count() == 1) {
|
||||||
markDirty();
|
setRotation((float)arguments.checkDouble(0), rotationPitch, rotationRoll);
|
||||||
if (worldObj != null) {
|
} else if (arguments.count() == 2) {
|
||||||
destroyForceField(false);
|
setRotation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), rotationRoll);
|
||||||
|
} else if (arguments.count() == 3) {
|
||||||
|
setRotation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(2));
|
||||||
}
|
}
|
||||||
|
return new Float[] { rotationYaw, rotationPitch, rotationRoll };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common OC/CC methods
|
||||||
|
private Object[] state() { // isConnected, isPowered, shape
|
||||||
|
int energy = getEnergyStored();
|
||||||
|
String status = getStatus();
|
||||||
|
return new Object[] { status, isEnabled, isConnected, isPowered, getShape().name(), energy };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputerCraft IPeripheral methods implementation
|
||||||
|
@Override
|
||||||
|
@cpw.mods.fml.common.Optional.Method(modid = "ComputerCraft")
|
||||||
|
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||||
|
String methodName = getMethodName(method);
|
||||||
|
|
||||||
|
switch (methodName) {
|
||||||
|
case "rotation":
|
||||||
|
if (arguments.length == 1) {
|
||||||
|
setRotation(toFloat(arguments[0]), rotationPitch, rotationRoll);
|
||||||
|
} else if (arguments.length == 2) {
|
||||||
|
setRotation(toFloat(arguments[0]), toFloat(arguments[1]), rotationRoll);
|
||||||
|
} else if (arguments.length == 3) {
|
||||||
|
setRotation(toFloat(arguments[0]), toFloat(arguments[1]), toFloat(arguments[2]));
|
||||||
|
}
|
||||||
|
return new Float[] { rotationYaw, rotationPitch, rotationRoll };
|
||||||
|
|
||||||
|
case "state":
|
||||||
|
return state();
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.callMethod(computer, context, method, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ThreadCalculation extends Thread {
|
private class ThreadCalculation extends Thread {
|
||||||
|
|
|
@ -15,20 +15,20 @@ public enum EnumForceFieldUpgrade implements IForceFieldUpgrade, IForceFieldUpgr
|
||||||
// Upgrade - Compatibility - ----- Value ----- -- Scan speed -- -- Place speed -- ------- Energy costs ------- comment
|
// Upgrade - Compatibility - ----- Value ----- -- Scan speed -- -- Place speed -- ------- Energy costs ------- comment
|
||||||
// name projector relay incr. cap minimum maximum minimum maximum startup scan place entity
|
// name projector relay incr. cap minimum maximum minimum maximum startup scan place entity
|
||||||
NONE ("none" , 0, 0, 0.0F, 0.0F, 0.000F, 0.000F, 0.000F, 0.000F, 0.0F, 0.000F, 0.000F, 0.0F, ""),
|
NONE ("none" , 0, 0, 0.0F, 0.0F, 0.000F, 0.000F, 0.000F, 0.000F, 0.0F, 0.000F, 0.000F, 0.0F, ""),
|
||||||
BREAKING ("breaking" , 0, 1, 1.0F, 25.0F, 0.400F, 0.500F, 0.010F, 0.100F, 70.0F, 0.020F, 1.000F, 0.0F, "value is hardness level"),
|
BREAKING ("breaking" , 0, 1, 1.0F, 25.0F, 0.400F, 0.500F, 0.010F, 0.100F, 70.0F, 0.080F, 4.000F, 0.0F, "value is hardness level"),
|
||||||
CAMOUFLAGE ("camouflage" , 0, 1, 1.0F, 3.0F, 0.600F, 0.850F, 0.700F, 0.950F, 100.0F, 0.100F, 0.300F, 0.0F, "value is boolean"),
|
CAMOUFLAGE ("camouflage" , 0, 1, 1.0F, 3.0F, 0.600F, 0.850F, 0.700F, 0.950F, 100.0F, 0.400F, 1.200F, 0.0F, "value is boolean"),
|
||||||
COOLING ("cooling" , 3, 1, 30.0F, 300.0F, 0.000F, 0.000F, 0.900F, 0.900F, 15.0F, 0.020F, 0.500F, 10.0F, "value is heat units"),
|
COOLING ("cooling" , 3, 1, 30.0F, 300.0F, 0.000F, 0.000F, 0.900F, 0.900F, 15.0F, 0.060F, 1.500F, 100.0F, "value is heat units"),
|
||||||
FUSION ("fusion" , 1, 1, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 100.0F, 0.050F, 0.050F, 0.0F, "value is boolean"),
|
FUSION ("fusion" , 1, 1, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 100.0F, 0.150F, 0.150F, 0.0F, "value is boolean"),
|
||||||
HEATING ("heating" , 3, 1, 100.0F, 10000.0F, 0.000F, 0.000F, 0.900F, 0.900F, 15.0F, 0.100F, 1.000F, 5.0F, "value is heat units"),
|
HEATING ("heating" , 3, 1, 100.0F, 10000.0F, 0.000F, 0.000F, 0.900F, 0.900F, 15.0F, 0.300F, 3.000F, 50.0F, "value is heat units"),
|
||||||
INVERSION ("inversion" , 1, 0, 1.0F, 1.0F, 0.250F, 0.250F, 0.000F, 0.000F, 150.0F, 0.050F, 0.050F, 1.0F, "value is boolean"),
|
INVERSION ("inversion" , 1, 0, 1.0F, 1.0F, 0.250F, 0.250F, 0.000F, 0.000F, 150.0F, 0.150F, 0.150F, 10.0F, "value is boolean"),
|
||||||
PUMPING ("pumping" , 0, 1, 1000.0F, 50000.0F, 0.800F, 1.000F, 0.400F, 1.000F, 80.0F, 0.010F, 0.500F, 0.0F, "value is viscosity"),
|
PUMPING ("pumping" , 0, 1, 1000.0F, 50000.0F, 0.800F, 1.000F, 0.400F, 1.000F, 80.0F, 0.050F, 1.500F, 0.0F, "value is viscosity"),
|
||||||
RANGE ("range" , 4, 1, 8.0F, 56.0F, 1.100F, 0.800F, 1.100F, 0.800F, 1.0F, 0.100F, 0.250F, 4.0F, "value is bonus blocks"),
|
RANGE ("range" , 4, 1, 8.0F, 56.0F, 1.100F, 0.800F, 1.100F, 0.800F, 1.0F, 0.300F, 0.750F, 40.0F, "value is bonus blocks"),
|
||||||
ROTATION ("rotation" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 10.0F, 0.000F, 0.000F, 0.0F, "value is boolean"),
|
ROTATION ("rotation" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 10.0F, 0.000F, 0.000F, 0.0F, "value is boolean"),
|
||||||
SHOCK ("shock" , 3, 1, 1.0F, 10.0F, 0.800F, 0.800F, 0.800F, 0.800F, 30.0F, 0.100F, 2.000F, 30.0F, "value is damage points"),
|
SHOCK ("shock" , 3, 1, 1.0F, 10.0F, 0.800F, 0.800F, 0.800F, 0.800F, 30.0F, 0.300F, 4.000F, 300.0F, "value is damage points"),
|
||||||
SILENCER ("silencer" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 0.0F, 0.010F, 0.020F, 0.0F, "value is boolean"),
|
SILENCER ("silencer" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 0.0F, 0.030F, 0.060F, 0.0F, "value is boolean"),
|
||||||
SPEED ("speed" , 4, 1, 1.0F, 20.0F, 1.250F, 6.000F, 1.200F, 5.000F, 20.0F, 0.100F, 1.000F, 5.0F, "value is not used (just a counter)"),
|
SPEED ("speed" , 4, 1, 1.0F, 20.0F, 1.250F, 6.000F, 1.200F, 5.000F, 20.0F, 0.100F, 1.000F, 50.0F, "value is not used (just a counter)"),
|
||||||
STABILIZATION("stabilization", 0, 1, 1.0F, 6.0F, 0.450F, 0.550F, 0.050F, 0.150F, 40.0F, 0.100F, 1.000F, 0.0F, "value is boolean"),
|
STABILIZATION("stabilization", 0, 1, 1.0F, 6.0F, 0.450F, 0.550F, 0.050F, 0.150F, 40.0F, 0.250F, 3.200F, 0.0F, "value is boolean"),
|
||||||
THICKNESS ("thickness" , 5, 1, 0.2F, 1.0F, 0.800F, 1.600F, 0.000F, 0.000F, 10.0F, 0.100F, 1.000F, 1.0F, "value is bonus ratio"),
|
THICKNESS ("thickness" , 5, 1, 0.2F, 1.0F, 0.800F, 1.600F, 0.000F, 0.000F, 10.0F, 0.450F, 2.400F, 10.0F, "value is bonus ratio"),
|
||||||
TRANSLATION ("translation" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 10.0F, 0.000F, 0.000F, 0.0F, "value is boolean"),
|
TRANSLATION ("translation" , 1, 0, 1.0F, 1.0F, 0.000F, 0.000F, 0.000F, 0.000F, 10.0F, 0.000F, 0.000F, 0.0F, "value is boolean"),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ public class ForceFieldSetup extends GlobalPosition {
|
||||||
if (isValidCamouflage(blockCandidate)) {
|
if (isValidCamouflage(blockCandidate)) {
|
||||||
blockCamouflage = blockCandidate;
|
blockCamouflage = blockCandidate;
|
||||||
metadataCamouflage = tileEntity.getWorldObj().getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
metadataCamouflage = tileEntity.getWorldObj().getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
||||||
colorMultiplierCamouflage = blockCandidate.colorMultiplier(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
colorMultiplierCamouflage = 0x808080; // blockCandidate.colorMultiplier(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
||||||
lightCamouflage = blockCandidate.getLightValue(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
lightCamouflage = blockCandidate.getLightValue(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue