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


Java Callback类代码示例

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


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

示例1: getEnergyToTeleport

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例2: hardwareInvoke

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
private Object[] hardwareInvoke(String address, String method, Object[] params) throws Exception {
	if(method.equals("_getMethods")) {
		Node node = machine.node().network().node(address);
		if(node == null || !(node instanceof Component)) return new Object[]{null, "node disappeared?"};
		Component component = (Component)node;
		TreeMap<Object, Object> ret = new TreeMap<Object, Object>();
		for(String name : component.methods()) {
			Callback cb = component.annotation(name);
			if(cb != null) {
				TreeMap<Object, Object> map = new TreeMap<Object, Object>();
				map.put("direct", cb.direct());
				map.put("getter", cb.getter());
				map.put("setter", cb.setter());
				ret.put(name, map);
			}
		}
		return new Object[]{ret};
	}
	else return machine.invoke(address, method, params);
}
 
开发者ID:SolraBizna,项目名称:jarm,代码行数:21,代码来源:CP3.java

示例3: beep

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例4: transfer

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例5: getActiveEffects

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
@Callback(doc="function(player:string); get current potion effects.")
public Object[] getActiveEffects(Context context, Arguments arguments) throws Exception{
    String name = arguments.checkString(0);
    EntityPlayer player = Utils.findPlayer(name);
    if(player != null){
        List<HashMap<Object, Object>> outEffects = new ArrayList<HashMap<Object, Object>>();
        Collection collection = player.getActivePotionEffects();
        Iterator iterator = collection.iterator();
        while(iterator.hasNext()){
            PotionEffect potionEffect = (PotionEffect) iterator.next();
            HashMap<Object, Object> values2 = new HashMap<Object, Object>();
            values2.put("potionId", potionEffect.getPotionID());
            values2.put("duration", potionEffect.getDuration());
            values2.put("amplifier", potionEffect.getAmplifier());
            values2.put("name", potionEffect.getEffectName());
            outEffects.add(values2);
        }
        return new Object[]{outEffects.toArray()};
    }
    return new Object[]{false, "player not found"};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:22,代码来源:TileEntityWorldInterface.java

示例6: seek

import li.cil.oc.api.machine.Callback; //导入依赖的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: getStackInSlot

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
@Callback(doc="function(slot:int):table, get itemstack in player inventory slot.")
public Object[] getStackInSlot(Context context, Arguments arguments) throws Exception{
    if(checkPlayer())
        return new Object[]{false};

    int slot = arguments.checkInteger(0) - 1;
    ItemStack itemStack = player.inventory.getStackInSlot(slot);

    if(itemStack != null){
        Map<String, Object> entry = new HashMap<String, Object>();
        entry.put("name", Item.itemRegistry.getNameForObject(itemStack));
        entry.put("damage", itemStack.getItemDamage());
        entry.put("hasTag", itemStack.hasTagCompound());
        entry.put("size", itemStack.stackSize);
        entry.put("label", itemStack.getDisplayName());
        return new Object[]{entry};
    }
    return new Object[]{null};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:20,代码来源:TileEntityPIM.java

示例8: setData

import li.cil.oc.api.machine.Callback; //导入依赖的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: gatherCallbacks

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
private void gatherCallbacks() {
	callbacks = new HashMap<String, CallbackBlob>();
	Class<? extends SimComponent> klaso = this.getClass();
	for (Method m : klaso.getDeclaredMethods()) {
		AnnotatedElement ae = m;
		Callback cb = ae.getAnnotation(Callback.class);
		if (cb == null) {
			continue;
		}
		String name = cb.value();
		if (name == null || name.isEmpty()) {
			name = m.getName();
		}
		callbacks.put(name, new CallbackBlob(cb, m));
	}
}
 
开发者ID:SolraBizna,项目名称:jarm,代码行数:17,代码来源:SimComponent.java

示例10: insert

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
@Callback(doc="")
public Object[] insert(Context context, Arguments arguments) throws Exception{
    if(isEmpty){
        Agent agent = (Agent) container;
        ItemStack itemStack = agent.mainInventory().getStackInSlot(agent.selectedSlot());
        if(itemStack.getItem() == Items.uranCell){
            int f = itemStack.getMaxDamage() - itemStack.getItemDamage();
            f = f <= 0 ? 1 : f;

            float per = (f) / (itemStack.getMaxDamage() / 100f);
            fuel = (int) ((Config.NRFuelCount / 100f) * per);
            itemStack.stackSize--;
            if(itemStack.stackSize <= 0){
                agent.mainInventory().setInventorySlotContents(agent.selectedSlot(), null);
            }
            isEmpty = false;
            return new Object[]{true};
        }else{
            return new Object[]{false, "selected slot does not contain fuel"};
        }
    }
    return new Object[]{false, "is full"};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:24,代码来源:EnvNRUpgrade.java

示例11: destroyStackInSlot

import li.cil.oc.api.machine.Callback; //导入依赖的package包/类
@Callback(doc = "function(name:string, slot:integer); destroy stack.")
public Object[] destroyStackInSlot(Context context, Arguments arguments) throws Exception{
    String name = arguments.checkString(0);
    int slot = arguments.checkInteger(1);
    EntityPlayer player = Utils.findPlayer(name);
    if(player != null){
        if(player.getCommandSenderName().equals(name)) {
            if (slot > 0 && slot < player.inventory.getSizeInventory()) {
                player.inventory.setInventorySlotContents(slot - 1, null);
                return new Object[]{true};
            }else{
                return new Object[]{false, "invalid slot"};
            }
        }
    }
    return new Object[]{false, "player not found"};
}
 
开发者ID:Avaja,项目名称:OpenTechnology,代码行数:18,代码来源:TileEntityWorldInterface.java

示例12: getMass

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例13: getPosition

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例14: getPitch

import li.cil.oc.api.machine.Callback; //导入依赖的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

示例15: getYaw

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


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