Refactored isAssemblyValid and hasReactor APIs (wip)

This commit is contained in:
Unknown 2018-09-24 10:08:56 +02:00 committed by unknown
parent 90db731236
commit a0676b6b97
9 changed files with 51 additions and 78 deletions

View file

@ -2,8 +2,6 @@ package cr0s.warpdrive.api.computer;
public interface IEnanReactorLaser extends IAbstractLaser {
Object[] hasReactor();
Object[] stabilize(Object[] arguments);
Object[] side();

View file

@ -2,7 +2,9 @@ package cr0s.warpdrive.api.computer;
public interface IMachine extends IInterfaced {
String[] name(final Object[] arguments);
Object[] enable(final Object[] arguments);
String[] name(final Object[] arguments);
Object[] isAssemblyValid();
}

View file

@ -1,6 +1,5 @@
package cr0s.warpdrive.api.computer;
public interface IMultiBlockCoreOrController extends IMultiBlock {
Object[] isAssemblyValid();
}

View file

@ -3,16 +3,8 @@ package cr0s.warpdrive.block;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.api.computer.IMultiBlockCoreOrController;
import cr0s.warpdrive.api.computer.IMultiBlockCore;
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 javax.annotation.Nonnull;
import net.minecraftforge.fml.common.Optional;
public abstract class TileEntityAbstractEnergyCoreOrController extends TileEntityAbstractEnergyConsumer implements IMultiBlockCoreOrController {
// persistent properties
@ -25,40 +17,24 @@ public abstract class TileEntityAbstractEnergyCoreOrController extends TileEntit
super();
// (abstract) peripheralName = "xxx";
addMethods(new String[] {
"isAssemblyValid",
});
// addMethods(new String[] {
// });
}
@Override
public void onCoreUpdated(@Nonnull final IMultiBlockCore multiblockCore) {
assert multiblockCore instanceof TileEntityAbstractEnergyCoreOrController;
name = ((TileEntityAbstractEnergyCoreOrController) multiblockCore).name;
}
// Common OC/CC methods
@Override
abstract public Object[] isAssemblyValid();
// (none)
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] isAssemblyValid(final Context context, final Arguments arguments) {
return isAssemblyValid();
}
// (none)
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "computercraft")
public Object[] callMethod(@Nonnull final IComputerAccess computer, @Nonnull final ILuaContext context, final int method, @Nonnull final Object[] arguments) {
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
switch (methodName) {
case "isAssemblyValid":
return isAssemblyValid();
}
return super.callMethod(computer, context, method, arguments);
}
// ComputerCraft IPeripheral methods
// (none)
@Override
public String toString() {

View file

@ -200,6 +200,14 @@ public abstract class TileEntityAbstractLaser extends TileEntityAbstractMachine
return new Object[] { cache_laserMedium_count };
}
@Override
public Object[] isAssemblyValid() {
if (laserMedium_direction == null) {
return new Object[] { false, "No laser medium detected" };
}
return super.isAssemblyValid();
}
// OpenComputers callback methods
@Callback
@Optional.Method(modid = "opencomputers")

View file

@ -33,6 +33,7 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
addMethods(new String[] {
"name",
"enable",
"isAssemblyValid"
});
}
@ -135,6 +136,11 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
return new Object[] { isEnabled };
}
@Override
public Object[] isAssemblyValid() {
return new Object[] { true, "ok" };
}
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "opencomputers")
@ -149,6 +155,11 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
}
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] isAssemblyValid(final Context context, final Arguments arguments) {
return isAssemblyValid();
}
// ComputerCraft IPeripheral methods
@Override
@Optional.Method(modid = "computercraft")
@ -161,6 +172,9 @@ public abstract class TileEntityAbstractMachine extends TileEntityAbstractInterf
case "enable":
return enable(arguments);
case "isAssemblyValid":
return isAssemblyValid();
}
return super.callMethod(computer, context, method, arguments);

View file

@ -11,13 +11,7 @@ import cr0s.warpdrive.data.EnumComponentType;
import cr0s.warpdrive.data.SoundEvents;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.network.PacketHandler;
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 javax.annotation.Nonnull;
import java.util.Arrays;
import net.minecraft.block.state.IBlockState;
@ -28,8 +22,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraftforge.fml.common.Optional;
public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
private static final int CLOAKING_CORE_SOUND_UPDATE_TICKS = 40;
@ -469,31 +461,21 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergyConsumer {
return new Object[] { energyRequired / updateRate };
}
@Override
public Object[] isAssemblyValid() {
return new Object[] { isValid, Commons.removeFormatting(textValidityIssues.getUnformattedText()) };
if (!isValid) {
return new Object[] { false, Commons.removeFormatting(textValidityIssues.getUnformattedText()) };
}
return super.isAssemblyValid();
}
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] isAssemblyValid(final Context context, final Arguments arguments) {
return isAssemblyValid();
}
// (none)
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "computercraft")
public Object[] callMethod(@Nonnull final IComputerAccess computer, @Nonnull final ILuaContext context, final int method, @Nonnull final Object[] arguments) {
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
switch (methodName) {
case "isAssemblyValid":
return isAssemblyValid();
}
return super.callMethod(computer, context, method, arguments);
}
// ComputerCraft IPeripheral methods
// (none)
// TileEntityAbstractEnergy methods
@Override
public int energy_getMaxStorage() {
return WarpDriveConfig.CLOAKING_MAX_ENERGY_STORED;

View file

@ -43,7 +43,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
super();
addMethods(new String[] {
"hasReactor",
"isAssemblyValid",
"side",
"stabilize"
});
@ -202,8 +202,11 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
// Common OC/CC methods
@Override
public Object[] hasReactor() {
return new Object[] { reactorFace != EnumReactorFace.UNKNOWN };
public Object[] isAssemblyValid() {
if (reactorFace == EnumReactorFace.UNKNOWN) {
return new Object[] { false, "No reactor detected" };
}
return super.isAssemblyValid();
}
@Override
@ -230,12 +233,6 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
}
// OpenComputers callback methods
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] hasReactor(final Context context, final Arguments arguments) {
return hasReactor();
}
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] stabilize(final Context context, final Arguments arguments) {
@ -255,9 +252,6 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
switch (methodName) {
case "hasReactor":
return hasReactor();
case "stabilize":
return stabilize(arguments);

View file

@ -1212,10 +1212,10 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
// Common OC/CC methods
@Override
public Object[] isAssemblyValid() {
if (isValid) {
return new Object[] { true, "ok" };
if (!isValid) {
return new Object[] { false, reasonInvalid.getUnformattedText() };
}
return new Object[] { false, reasonInvalid.getUnformattedText() };
return super.isAssemblyValid();
}
@Override