当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中li.cil.oc.api.machine.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于li.cil.oc.api.machine包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback(doc="function(address:string, data:string), sending data to a specific address.")
public Object[] send(Context context, Arguments arguments) throws Exception{
    Connector connector = (Connector) node;
    if(distance > 0 && isStructure && (connector.tryChangeBuffer(Config.ldaEnergyUsage) || !API.isPowerEnabled)){
        String address = arguments.checkString(0);
        String data = arguments.checkString(1);
        if(data.length() > Config.ldaMaxPacketSize)
            return new Object[]{false};

        LDASystem.sendMessage(this, address, data);
        transmitTime = 60;
        return new Object[]{true};
    }

    return new Object[]{false};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:17,代码来源:TileEntityLDA.java

示例2: transfer

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback(doc="")
public Object[] transfer(Context context, Arguments arguments) throws Exception{
    int count = arguments.checkInteger(0);
    if(count > 0){
        if(count > energyInputBuffer)
            count = energyInputBuffer;

        if(outputBufferCapacity - energyOutputBuffer >= count){
            energyInputBuffer -= count;
            energyOutputBuffer += count;
        }else{
            return new Object[]{false};
        }
    }
    return new Object[]{true};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:17,代码来源:TileEntityEnergyController.java

示例3: getEntitiesId

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback(doc="returns entities on the teleporter and their UUIDs.")
public Object[] getEntitiesId(Context context, Arguments arguments) throws Exception{
	try{
		List<Entity> entities = getEntitiesInBound(Entity.class, worldObj, xCoord, yCoord, zCoord, xCoord+1, yCoord+2, zCoord+1);
		if(entities.size() == 0 || entities.size() > Config.entityTeleportationLimit)
			throw new Exception("entity limit.");
			if(entities != null && entities.size() > 0){
			for(int z = 0; z < 30; z++){
				String uuid = UUID.randomUUID().toString();
				if(!UuidList.isUuid(uuid)){
					EntityId entityId = new EntityId(entities, xCoord, yCoord, zCoord);
					UuidList.addUuid(uuid, entityId);
					return new Object[]{uuid};
				}
			}
		}else{
				throw new Exception("entities not found.");
		}
	}catch(Exception e){
		throw new Exception("error");
	}
	return null;
}
 
开发者ID:java8compiler,项目名称:OpenTeleporter,代码行数:24,代码来源:TileEntityTeleporter.java

示例4: getEnergyToTeleport

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback(doc="returns the amount of energy for teleporting.")
public Object[] getEnergyToTeleport(Context context, Arguments arguments) throws Exception{
	try{
		if(!arguments.checkString(0).isEmpty()){
			String address = arguments.checkString(0);
			Iterable<Node> nodes = node.reachableNodes();
			for(Node n : nodes){
				if(!n.address().isEmpty() && address.equals(n.address())){
					return new Object[]{Math.pow(distance(node, n), Config.pow)};
				}
			}
			throw new Exception("teleporter not found.");
		}
	}catch(Exception e){
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:java8compiler,项目名称:OpenTeleporter,代码行数:19,代码来源:TileEntityTeleporter.java

示例5: beep

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
public Object[] beep(Context ctx, Object[] args) {
	if (args.length == 1 && args[0] instanceof String) {
		FakeMachine.this.beep((String) args[0]);
	} else {
		float freq = 200f;
		float duration = 0.5f;
		if (args.length >= 1 && args[0] instanceof Number) {
			freq = ((Number) args[0]).floatValue();
		}
		if (args.length >= 2 && args[1] instanceof Number) {
			duration = ((Number) args[1]).floatValue();
		}
		FakeMachine.this.beep((short) freq, (short) (duration * 20));
	}
	return new Object[]{};
}
 
开发者ID:SolraBizna,项目名称:jarm,代码行数:18,代码来源:FakeMachine.java

示例6: seek

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
public Object[] seek(Context ctx, Object[] args) {
	int handle = HandleValue.getHandle(address(), args[0]);
	if (handle >= MAX_HANDLES || handle < 0 || handles[handle] == null) {
		return new Object[]{null, "no such handle"};
	}
	String whenceStr = SimComponent.toString(args[1]);
	Whence whence;
	if (whenceStr.equals("set")) {
		whence = Whence.SET;
	} else if (whenceStr.equals("cur")) {
		whence = Whence.CUR;
	} else if (whenceStr.equals("end")) {
		whence = Whence.END;
	} else {
		return new Object[]{null, "unknown whence value"};
	}
	long offset = ((Number) args[2]).longValue();
	return new Object[]{handles[handle].seek(whence, offset)};
}
 
开发者ID:SolraBizna,项目名称:jarm,代码行数:21,代码来源:SimFilesystem.java

示例7: say

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback(doc="function(message:string); say some text")
public Object[] say(Context context, Arguments arguments) throws Exception{

    String message = arguments.checkString(0);

    if (message.length() > Config.maxMessageLength)
        message = message.substring(0, Config.maxMessageLength);

    System.out.println(String.format("say: x=%d, y=%d, z=%d", xCoord, yCoord, zCoord));

    List<EntityPlayer> players = worldObj.playerEntities;
    for (EntityPlayer player : players){
        if (player.getDistance(this.xCoord, this.yCoord, this.zCoord) <= radius){
            player.addChatMessage(ForgeHooks.newChatWithLinks(message));
        }
    }
    return new Object[]{};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:19,代码来源:TileEntityChatBox.java

示例8: setData

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
public Object[] setData(Context ctx, Object[] args) {
	byte[] array;
	if (args.length == 0) {
		array = new byte[0];
	} else {
		array = (byte[]) args[0];
	}
	if (array.length > (sram.getSramArray().length < 256 ? 256 : sram.getSramArray().length)) {
		return new Object[]{null, "data too long"};
	}
	System.arraycopy(array, 0, sram.getNvramArray(), 0, array.length);
	try {
		sram.maybeWriteNVRAM();
	} catch (IOException e) {
		System.err.println("While saving NVRAM");
		e.printStackTrace(System.err);
	}
	return null;
}
 
开发者ID:SolraBizna,项目名称:jarm,代码行数:21,代码来源:SimEEPROM.java

示例9: invoke

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Override
@Optional.Method(modid = ModIds.OPEN_COMPUTERS)
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
    if ("greet".equals(method)) return new Object[]{String.format("Hello, %s!", args.checkString(0))};
    for (ILuaMethod m : luaMethods) {
        if (m.getMethodName().equals(method)) {
            return m.call(args.toArray());
        }
    }
    throw new IllegalArgumentException("Can't invoke method with name \"" + method + "\". not registered");
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:12,代码来源:TileEntityDroneInterface.java

示例10: invoke

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Override
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
    if ("greet".equals(method)) {
        return new Object[]{String.format("Hello, %s!", args.checkString(0))};
    }
    List<ILuaMethod> luaMethods = tile.getLuaMethods();
    for (ILuaMethod m : luaMethods) {
        if (m.getMethodName().equals(method)) {
            return m.call(args.toArray());
        }
    }
    throw new IllegalArgumentException("Can't invoke method with name \"" + method + "\". not registered");
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:14,代码来源:DriverPneumaticCraft.java

示例11: disposeValue

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
public void disposeValue(byte handle, Context ctx) {
	Value v = handleToValue.get(handle);
	if(v != null) {
		handleToValue.remove(handle);
		valueToHandle.remove(v);
		v.dispose(ctx);
	}
}
 
开发者ID:SolraBizna,项目名称:j6502,代码行数:9,代码来源:OCMOS.java

示例12: disposeAllValues

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
public void disposeAllValues(Context ctx) {
	for(Value v : valueToHandle.keySet()) {
		v.dispose(ctx);
	}
	handleToValue.clear();
	valueToHandle.clear();
}
 
开发者ID:SolraBizna,项目名称:j6502,代码行数:8,代码来源:OCMOS.java

示例13: getMass

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
@Method(modid = "opencomputers")
public Object[] getMass(Context context, Arguments args) {
	if(ValkyrienWarfareHooks.isBlockPartOfShip(worldObj, pos)) {
		return new Object[] { ValkyrienWarfareHooks.getShipMass(ValkyrienWarfareHooks.getShipEntityManagingPos(worldObj, pos)) };
	}
	return new Object[] { null };
}
 
开发者ID:djeezuss,项目名称:Valkyrien-Warfare-Drivers-for-OpenComputers,代码行数:9,代码来源:TileEntityShipInterface.java

示例14: getPosition

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
@Method(modid = "opencomputers")
public Object[] getPosition(Context context, Arguments args) {
	if(ValkyrienWarfareHooks.isBlockPartOfShip(worldObj, pos)) {
		Vector ship = new Vector(ValkyrienWarfareHooks.getShipEntityManagingPos(worldObj, pos));
		return new Object[] { ship.X, ship.Y, ship.Z };
	}
	return new Object[] { null };
}
 
开发者ID:djeezuss,项目名称:Valkyrien-Warfare-Drivers-for-OpenComputers,代码行数:10,代码来源:TileEntityShipInterface.java

示例15: getPitch

import li.cil.oc.api.machine.Context; //导入依赖的package包/类
@Callback
@Method(modid = "opencomputers")
public Object[] getPitch(Context context, Arguments args) {
	if(ValkyrienWarfareHooks.isBlockPartOfShip(worldObj, pos)) {
		return new Object[] { ValkyrienWarfareHooks.getShipEntityManagingPos(worldObj, pos).pitch };
	}
	return new Object[] { null };
}
 
开发者ID:djeezuss,项目名称:Valkyrien-Warfare-Drivers-for-OpenComputers,代码行数:9,代码来源:TileEntityShipInterface.java


注:本文中的li.cil.oc.api.machine.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。