本文整理汇总了Java中li.cil.oc.api.machine.Arguments类的典型用法代码示例。如果您正苦于以下问题:Java Arguments类的具体用法?Java Arguments怎么用?Java Arguments使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Arguments类属于li.cil.oc.api.machine包,在下文中一共展示了Arguments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntitiesId
import li.cil.oc.api.machine.Arguments; //导入依赖的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;
}
示例2: getEnergyToTeleport
import li.cil.oc.api.machine.Arguments; //导入依赖的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;
}
示例3: insert
import li.cil.oc.api.machine.Arguments; //导入依赖的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"};
}
示例4: destroyStackInSlot
import li.cil.oc.api.machine.Arguments; //导入依赖的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"};
}
示例5: getActiveEffects
import li.cil.oc.api.machine.Arguments; //导入依赖的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"};
}
示例6: getStackInSlot
import li.cil.oc.api.machine.Arguments; //导入依赖的package包/类
@Callback(doc="function(slot:int):table, get itemstack in player inventory slot.")
public Object[] getStackInSlot(Context context, Arguments arguments) throws Exception{
if(!isConnected())
return new Object[]{false};
int slot = arguments.checkInteger(0) - 1;
ItemStack itemStack = target.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};
}
示例7: send
import li.cil.oc.api.machine.Arguments; //导入依赖的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};
}
示例8: say
import li.cil.oc.api.machine.Arguments; //导入依赖的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[]{};
}
示例9: transfer
import li.cil.oc.api.machine.Arguments; //导入依赖的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};
}
示例10: getStackInSlot
import li.cil.oc.api.machine.Arguments; //导入依赖的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};
}
示例11: set
import li.cil.oc.api.machine.Arguments; //导入依赖的package包/类
@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 };
}
示例12: executeSignallingTask
import li.cil.oc.api.machine.Arguments; //导入依赖的package包/类
protected Object[] executeSignallingTask(ITaskSink taskSink, Object target, IMethodExecutor executor, final String signal, final Context context, Arguments arguments) {
final Object[] args = arguments.toArray();
final IMethodCall preparedCall = prepareCall(target, executor, context);
final int callbackId = SignallingGlobals.instance.nextCallbackId();
taskSink.accept(new Runnable() {
@Override
public void run() {
if (context.isRunning() || context.isPaused()) {
Object[] result = callForSignal(args, preparedCall, callbackId);
context.signal(signal, result);
}
}
});
return new Object[] { callbackId };
}
示例13: testMethod
import li.cil.oc.api.machine.Arguments; //导入依赖的package包/类
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);
}
示例14: invoke
import li.cil.oc.api.machine.Arguments; //导入依赖的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");
}
示例15: invoke
import li.cil.oc.api.machine.Arguments; //导入依赖的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");
}