li.cil.oc.api.machine.Callback Java Examples

The following examples show how to use li.cil.oc.api.machine.Callback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnvironmentGeneratorTest.java    From OpenPeripheral with MIT License 6 votes vote down vote up
private static void testMethod(Object target, Object wrapper, Class<?> generatedClass, String name, IMethodExecutor executor, IMethodCall call, ArgVerifier verifier) throws Exception {
	Method m = getMethod(generatedClass, name.substring(0, 1));

	Callback callback = m.getAnnotation(Callback.class);
	Assert.assertNotNull(callback);

	Assert.assertEquals(executor.isAsynchronous(), callback.direct());

	// that's what I get for not injecting ...
	Assert.assertEquals("function()", callback.doc());

	Arguments args = mock(Arguments.class);
	final Object[] argArray = new Object[] { 1, 2, 3 };
	when(args.toArray()).thenReturn(argArray);
	Context context = mock(Context.class);

	m.invoke(wrapper, context, args);

	verify(executor).startCall(target);

	verify(args).toArray();
	verifier.verifyCall(call, context);
	verify(call).call(argArray);
}
 
Example #2
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Callback(doc = "function(face, direction):boolean -- Sets the motor's face and direction. Returns true if it succeeded, false if it didn't.")
public Object[] set(Context context, Arguments args) {

    if (args.count() < 2)
        throw new RuntimeException("At least 2 arguments are required (face, direction)");

    ForgeDirection face = toFD(args.checkAny(0));
    ForgeDirection direction = toFD(args.checkAny(1));

    if (face == null || direction == null)
        throw new RuntimeException("Invalid directions!");
    if (face == direction || face == direction.getOpposite())
        throw new RuntimeException("Motors cannot push or pull blocks!");

    // te.setFace(face, true);
    // te.setDirection(direction, true);

    return new Object[] { true };
}
 
Example #3
Source File: EnvironmentGeneratorTest.java    From OpenPeripheral with MIT License 5 votes vote down vote up
private static void testSignallingMethod(Class<?> generatedClass, String name) throws Exception {
	Method m = getMethod(generatedClass, name.substring(0, 1));

	Callback callback = m.getAnnotation(Callback.class);
	Assert.assertNotNull(callback);

	Assert.assertTrue(callback.direct());
}
 
Example #4
Source File: FabricatorTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] setProgram(Context context, Arguments args) {

    boolean success = false;
    String message = "There was an error setting the program";

    try {

        int max = FabricatorRecipes.getRecipes().size() - 1;

        Object[] arguments = args.toArray();

        if (arguments == null) {
            message = "Invalid argument. Must be integer between 0 and " + max;
            return new Object[] { success, message };
        }

        Double thing = (Double) arguments[0];

        int program = thing.intValue();

        if (program < 0 || program > max) {
            message = "Invalid argument. Must be integer between 0 and " + max;
        } else {
            this.setProgram(program);
            success = true;
            message = "Fabricator program set to " + program;
        }

    } catch (Exception ex) {
        message = ex.toString();
    }

    return new Object[] { success, message };
}
 
Example #5
Source File: TileEntity_GTDataServer.java    From bartworks with MIT License 5 votes vote down vote up
@Optional.Method(modid = "OpenComputers")
@Callback
public Object[] listData(Context context, Arguments args) {
    Set<String> ret = new HashSet<>();
    for (Map.Entry<Long,GT_NBT_DataBase> entry : OrbDataBase.entrySet()){
        ret.add((entry.getValue().getId()+Long.MAX_VALUE)+". "+entry.getValue().getmDataTitle());
    }
    return ret.toArray(new String[0]);
}
 
Example #6
Source File: GPSTileEntity.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getPosition(Context context, Arguments args) {
    java.util.Optional<PhysicsObject> physicsObjectOptional = ValkyrienUtils
        .getPhysicsObject(getWorld(), getPos());
    if (physicsObjectOptional.isPresent()) {
        BlockPos pos = physicsObjectOptional.get()
            .getWrapperEntity()
            .getPosition();
        return new Object[]{pos.getX(), pos.getY(), pos.getZ()};
    }
    return null;
}
 
Example #7
Source File: GPSTileEntity.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getRotation(Context context, Arguments args) {
    java.util.Optional<PhysicsObject> physicsObjectOptional = ValkyrienUtils
        .getPhysicsObject(getWorld(), getPos());
    if (physicsObjectOptional.isPresent()) {
        PhysicsWrapperEntity ship = physicsObjectOptional.get()
            .getWrapperEntity();
        return new Object[]{ship.getYaw(), ship.getPitch(), ship.getRoll()};
    }
    return null;
}
 
Example #8
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Callback(doc = "function(face):boolean -- Sets the motor's face. Returns true if it succeeded, false if it didn't.")
public Object[] setFace(Context context, Arguments args) {

    if (args.count() == 0)
        throw new RuntimeException("At least 1 argument is required (direction)");
    return new Object[] { te.setFace(toFD(args.checkAny(0))) };
}
 
Example #9
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Callback(doc = "function(direction):boolean -- Sets the motor's direction. Returns true if it succeeded, false if it didn't.")
public Object[] setDirection(Context context, Arguments args) {

    if (args.count() == 0)
        throw new RuntimeException("At least 1 argument is required (direction)");
    return new Object[] { /* te.setDirection(toFD(args.checkAny(0))) */};
}
 
Example #10
Source File: CookerTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getProgress(Context context, Arguments args) {
    int value = getProgress();
    return new Object[] { value };
}
 
Example #11
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@Callback(doc = "function():number -- Gets the face the blocks that will be moved are on.")
public Object[] getFace(Context context, Arguments args) {

    return new Object[] { te.getFace().ordinal() };
}
 
Example #12
Source File: AlgaeBioreactorTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getWaterLevel(Context context, Arguments args) {
    int level = getWater();
    return new Object[] { level };
}
 
Example #13
Source File: AlgaeBioreactorTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getGasLevel(Context context, Arguments args) {
    int level = getGas();
    return new Object[] { level };
}
 
Example #14
Source File: AlgaeBioreactorTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getEnergyLevel(Context context, Arguments args) {
    int level = getEnergy();
    return new Object[] { level };
}
 
Example #15
Source File: AlgaeBioreactorTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getProgress(Context context, Arguments args) {
    int value = getProgress();
    return new Object[] { value };
}
 
Example #16
Source File: ShredderTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getEnergyLevel(Context context, Arguments args) {
    int level = getEnergy();
    return new Object[] { level };
}
 
Example #17
Source File: ShredderTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getProgress(Context context, Arguments args) {
    int value = getProgress();
    return new Object[] { value };
}
 
Example #18
Source File: PiezoelectricTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] isSteppedOn(Context context, Arguments args) {
    boolean stepped = this.cooldown == 10;
    return new Object[] { stepped };
}
 
Example #19
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getWaterLevel(Context context, Arguments args) {
    int level = getWater();
    return new Object[] { level };
}
 
Example #20
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getMaxWaterLevel(Context context, Arguments args) {
    int level = Reference.HYDROPONIC_FLUID_CAPACITY;
    return new Object[] { level };
}
 
Example #21
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getEnergyLevel(Context context, Arguments args) {
    int level = getEnergy();
    return new Object[] { level };
}
 
Example #22
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getMaxEnergyLevel(Context context, Arguments args) {
    int level = Reference.HYDROPONIC_ENERGY_CAPACITY;
    return new Object[] { level };
}
 
Example #23
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getMediumName(Context context, Arguments args) {
    String name = getItemStack().getDisplayName();
    return new Object[] { name };
}
 
Example #24
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getMediumGrowthMultiplier(Context context, Arguments args) {
    int probability = HydroponicHelper.getGrowthProbabilityForMedium(getItemStack());
    return new Object[] { probability };
}
 
Example #25
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getLightLevel(Context context, Arguments args) {
    int level = PlantHelper.getPlantLightAtPosition(world, pos);
    return new Object[] { level };
}
 
Example #26
Source File: CookerTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getHeatLevel(Context context, Arguments args) {
    int level = getHeat();
    return new Object[] { level };
}
 
Example #27
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getPlantGrowth(Context context, Arguments args) {
    int growth = PlantHelper.getPlantGrowthAtPosition(world, pos.add(0, 1, 0));
    return new Object[] { growth };
}
 
Example #28
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Callback
@Optional.Method(modid = "opencomputers")
public Object[] getPlantName(Context context, Arguments args) {
    String name = PlantHelper.getPlantNameAtPosition(world, pos);
    return new Object[] { name };
}
 
Example #29
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@Callback(doc = "function():boolean -- Attempts to move the motor. Returns true if it succeeded, false if it didn't.")
public Object[] move(Context context, Arguments args) {

    return new Object[] { te.move() };
}
 
Example #30
Source File: TileEntity_GTDataServer.java    From bartworks with MIT License 4 votes vote down vote up
@Optional.Method(modid = "OpenComputers")
@Callback
public Object[] imprintOrb(Context context, Arguments args) {
    return new Object[]{false};
}