Search in sources :

Example 1 with Callback

use of li.cil.oc.api.machine.Callback in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretBase method addTrustedPlayer.

@Optional.Method(modid = omtteam.omlib.compatability.ModCompatibility.OCModID)
@Callback(doc = "function(name:String, [canOpenGUI:boolean , canChangeTargeting:boolean , " + "admin:boolean]):string; adds Trusted player to Trustlist.")
public Object[] addTrustedPlayer(Context context, Arguments args) {
    if (!computerAccessible) {
        return new Object[] { "Computer access deactivated!" };
    }
    if (!this.addTrustedPlayer(args.checkString(0))) {
        return new Object[] { "Name not valid!" };
    }
    TrustedPlayer trustedPlayer = this.getTrustedPlayer(args.checkString(0));
    trustedPlayer.canOpenGUI = args.optBoolean(1, false);
    trustedPlayer.canChangeTargeting = args.optBoolean(1, false);
    trustedPlayer.admin = args.optBoolean(1, false);
    trustedPlayer.uuid = getPlayerUUID(args.checkString(0));
    return null;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) Callback(li.cil.oc.api.machine.Callback)

Example 2 with Callback

use of li.cil.oc.api.machine.Callback in project Charset by CharsetMC.

the class TraitRecordPlayerOC method seek.

@Callback(doc = "function(duration:number):number -- Seeks the specified amount of seconds on the record. " + "Negative values for rewinding. Returns the number of seconds sought.")
public Object[] seek(Context context, Arguments args) {
    if (hasReadyStorage()) {
        int seekAmount = (int) Math.round(args.checkDouble(0) * getBytesPerSecond());
        if (seekAmount == 0) {
            return new Object[] { 0.0 };
        } else {
            IDataStorage storage = getStorage();
            int oldPos = storage.getPosition();
            int newPos = oldPos + seekAmount;
            if (newPos < 0)
                newPos = 0;
            else if (newPos > storage.getSize())
                newPos = storage.getSize();
            storage.setPosition(newPos);
            return new Object[] { (double) (newPos - oldPos) / getBytesPerSecond() };
        }
    } else {
        return new Object[] { 0.0 };
    }
}
Also used : IDataStorage(pl.asie.charset.api.tape.IDataStorage) Callback(li.cil.oc.api.machine.Callback)

Example 3 with Callback

use of li.cil.oc.api.machine.Callback in project RFTools by McJty.

the class ScreenControllerTileEntity method getTags.

@Callback(doc = "Get a table of all tags supported by all connected screens", getter = true)
@Optional.Method(modid = "opencomputers")
public Object[] getTags(Context context, Arguments args) {
    List<String> tags = new ArrayList<>();
    for (BlockPos screen : connectedScreens) {
        TileEntity te = getWorld().getTileEntity(screen);
        if (te instanceof ScreenTileEntity) {
            ScreenTileEntity screenTileEntity = (ScreenTileEntity) te;
            tags.addAll(screenTileEntity.getTags());
        }
    }
    return new Object[] { tags };
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) Callback(li.cil.oc.api.machine.Callback)

Example 4 with Callback

use of li.cil.oc.api.machine.Callback in project RFTools by McJty.

the class ScreenControllerTileEntity method getScreens.

@Callback(doc = "Get a table with coordinates (every coordinate is a table indexed with 'x', 'y', and 'z') for all connected screens", getter = true)
@Optional.Method(modid = "opencomputers")
public Object[] getScreens(Context context, Arguments args) {
    List<Map<String, Integer>> result = new ArrayList<>();
    for (BlockPos screen : connectedScreens) {
        Map<String, Integer> coordinate = new HashMap<>();
        coordinate.put("x", screen.getX());
        coordinate.put("y", screen.getY());
        coordinate.put("z", screen.getZ());
        result.add(coordinate);
    }
    return new Object[] { result };
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Example 5 with Callback

use of li.cil.oc.api.machine.Callback in project RFTools by McJty.

the class ScreenControllerTileEntity method getScreenIndex.

@Callback(doc = "Given a screen coordinate (table indexed by 'x', 'y', and 'z') return the index of that screen", getter = true)
@Optional.Method(modid = "opencomputers")
public Object[] getScreenIndex(Context context, Arguments args) throws Exception {
    Map screen = args.checkTable(0);
    if (!screen.containsKey("x") || !screen.containsKey("y") || !screen.containsKey("z")) {
        throw new IllegalArgumentException("Screen map doesn't contain the right x,y,z coordinate!");
    }
    BlockPos recC = new BlockPos(((Double) screen.get("x")).intValue(), ((Double) screen.get("y")).intValue(), ((Double) screen.get("z")).intValue());
    return getScreenIndex(recC);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Aggregations

Callback (li.cil.oc.api.machine.Callback)9 BlockPos (net.minecraft.util.math.BlockPos)4 HashMap (java.util.HashMap)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 PermissionException (logisticspipes.security.PermissionException)2 TrustedPlayer (omtteam.omlib.util.TrustedPlayer)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IDataStorage (pl.asie.charset.api.tape.IDataStorage)1