本文整理汇总了Java中openperipheral.api.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于openperipheral.api包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableItems
import openperipheral.api.Constants; //导入依赖的package包/类
@ScriptCallable(description = "Get a list of the stored and craftable items in the network.", returnTypes = ReturnType.TABLE)
public List<?> getAvailableItems(IGridHost host,
@Env(Constants.ARG_CONVERTER) IConverter converter,
@Optionals @Arg(name = "details", description = "Format of stored items details (defalt: none)") ItemDetails format) {
IStorageGrid storageGrid = getStorageGrid(host);
final IItemList<IAEItemStack> storageList = storageGrid.getItemInventory().getStorageList();
List<Object> result = Lists.newArrayList();
for (IAEItemStack stack : storageList) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>)converter.fromJava(stack);
if (format != null && format != ItemDetails.NONE) {
final ItemStack itemStack = stack.getItemStack();
if (format == ItemDetails.PROXY) map.put("item", OpcAccess.itemStackMetaBuilder.createProxy(itemStack));
else if (format == ItemDetails.ALL) map.put("item", itemStack);
}
result.add(map);
}
return result;
}
示例2: setupApis
import openperipheral.api.Constants; //导入依赖的package包/类
public void setupApis() {
registry.registerClass(AdapterRegistryWrapper.Peripherals.class);
registry.registerClass(AdapterRegistryWrapper.Objects.class);
registry.registerClass(EntityMetadataBuilder.class);
registry.registerClass(ItemStackMetadataBuilder.class);
registry.registerInstance(TypeConvertersProvider.INSTANCE);
registry.registerInstance(TileEntityBlacklist.INSTANCE);
registry.registerInstance(PeripheralTypeProvider.INSTANCE);
registry.registerInstance(TypeClassifier.INSTANCE);
registry.registerInstance(ArchitectureChecker.INSTANCE);
registry.registerInstance(FeatureGroupManager.INSTANCE);
if (ArchitectureChecker.INSTANCE.isEnabled(Constants.ARCH_COMPUTER_CRAFT)) ModuleComputerCraft.installAPI(registry);
if (ArchitectureChecker.INSTANCE.isEnabled(Constants.ARCH_OPEN_COMPUTERS)) ModuleOpenComputers.installAPI(registry);
registry.freeze();
}
示例3: startCall
import openperipheral.api.Constants; //导入依赖的package包/类
@Override
public IMethodCall startCall(final Object target) {
return new IMethodCall() {
private IConverter converter;
@Override
public IMethodCall setEnv(String name, Object value) {
if (Constants.ARG_CONVERTER.equals(name)) this.converter = (IConverter)value;
return this;
}
@Override
public Object[] call(Object... args) {
Preconditions.checkNotNull(converter, "Converter not provided");
return caller.call(converter, target, args);
}
};
}
示例4: processMessage
import openperipheral.api.Constants; //导入依赖的package包/类
@EventHandler
public void processMessage(FMLInterModComms.IMCEvent event) {
for (FMLInterModComms.IMCMessage m : event.getMessages()) {
if (m.isStringMessage()) {
if (Constants.IMC_IGNORE.equalsIgnoreCase(m.key)) {
TileEntityBlacklist.INSTANCE.addToBlacklist(m.getStringValue());
} else if (Constants.IMC_NAME_CLASS.equalsIgnoreCase(m.key)) {
String value = m.getStringValue();
String[] fields = value.split("\\s+");
if (fields.length != 2) {
Log.warn("Invalid IMC from %s: can't decode type '%s'", m.getSender(), value);
} else {
PeripheralTypeProvider.INSTANCE.setType(fields[0], fields[1]);
}
}
}
}
}
示例5: verifySingleGetterExecution
import openperipheral.api.Constants; //导入依赖的package包/类
private static void verifySingleGetterExecution(IMethodExecutor executor, Field targetField) {
final IPropertyCallback target = mock(SingleCallbackSource.class);
final IConverter converter = mock(IConverter.class);
final IMethodCall call = executor.startCall(target);
call.setEnv(Constants.ARG_CONVERTER, converter);
final Value markerValue = new Value();
when(target.getField(any(Field.class))).thenReturn(markerValue);
final ConvertedValue markerConvertedValue = new ConvertedValue();
when(converter.fromJava(any())).thenReturn(markerConvertedValue);
try {
final Object[] result = call.call();
Assert.assertArrayEquals(new Object[] { markerConvertedValue }, result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
verify(target).getField(targetField);
verify(converter).fromJava(markerValue);
}
示例6: verifySingleSetterExecution
import openperipheral.api.Constants; //导入依赖的package包/类
private static void verifySingleSetterExecution(IMethodExecutor executor, Field targetField, Type targetTypeField) {
final IPropertyCallback target = mock(SingleCallbackSource.class);
final IConverter converter = Mockito.mock(IConverter.class);
final IMethodCall call = executor.startCall(target);
call.setEnv(Constants.ARG_CONVERTER, converter);
final ConvertedValue markerConvertedValue = new ConvertedValue();
when(converter.toJava(any(), any(Type.class))).thenReturn(markerConvertedValue);
final Value markerValue = new Value();
try {
final Object[] result = call.call(markerValue);
Assert.assertArrayEquals(new Object[0], result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
verify(converter).toJava(markerValue, targetTypeField);
verify(target).setField(targetField, markerConvertedValue);
}
示例7: verifySingleNullableSetterExecution
import openperipheral.api.Constants; //导入依赖的package包/类
private static void verifySingleNullableSetterExecution(IMethodExecutor executor, Field targetField) {
final IPropertyCallback target = mock(SingleCallbackSource.class);
final IConverter converter = Mockito.mock(IConverter.class);
final IMethodCall call = executor.startCall(target);
call.setEnv(Constants.ARG_CONVERTER, converter);
try {
final Object[] result = call.call((Object)null);
Assert.assertArrayEquals(new Object[0], result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
verifyNoMoreInteractions(converter);
verify(target).setField(targetField, null);
}
示例8: verifyIndexedSetterExecution
import openperipheral.api.Constants; //导入依赖的package包/类
private static void verifyIndexedSetterExecution(IMethodExecutor executor, Field targetField, Type keyType, Type valueType) {
final IIndexedPropertyCallback target = mock(IndexedCallbackSource.class);
final IConverter converter = Mockito.mock(IConverter.class);
final IMethodCall call = executor.startCall(target);
call.setEnv(Constants.ARG_CONVERTER, converter);
final ConvertedKey markerConvertedKey = new ConvertedKey();
when(converter.toJava(any(), eq(keyType))).thenReturn(markerConvertedKey);
final ConvertedValue markerConvertedValue = new ConvertedValue();
when(converter.toJava(any(), eq(valueType))).thenReturn(markerConvertedValue);
final Value markerValue = new Value();
final Key markerKey = new Key();
try {
final Object[] result = call.call(markerValue, markerKey);
Assert.assertArrayEquals(new Object[0], result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
verify(converter).toJava(markerValue, valueType);
verify(converter).toJava(markerKey, keyType);
verify(target).setField(targetField, markerConvertedKey, markerConvertedValue);
}
示例9: verifyIndexedNullableSetterExecution
import openperipheral.api.Constants; //导入依赖的package包/类
private static void verifyIndexedNullableSetterExecution(IMethodExecutor executor, Field targetField, Type keyType) {
final IIndexedPropertyCallback target = mock(IndexedCallbackSource.class);
final IConverter converter = Mockito.mock(IConverter.class);
final IMethodCall call = executor.startCall(target);
call.setEnv(Constants.ARG_CONVERTER, converter);
final ConvertedKey markerConvertedKey = new ConvertedKey();
when(converter.toJava(any(), eq(keyType))).thenReturn(markerConvertedKey);
final Key markerKey = new Key();
try {
final Object[] result = call.call(null, markerKey);
Assert.assertArrayEquals(new Object[0], result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
verify(converter).toJava(markerKey, keyType);
verify(target).setField(targetField, markerConvertedKey, null);
}
示例10: requestCrafting
import openperipheral.api.Constants; //导入依赖的package包/类
@ScriptCallable(description = "Requests the specified item to get crafted.")
public void requestCrafting(IActionHost host,
@Env(Constants.ARG_ACCESS) IArchitectureAccess access,
@Env(Constants.ARG_CONVERTER) IConverter converter,
@Arg(name = "fingerprint", description = "Details of the item you want to craft. Can be found with .getStackInSlot on inventory and .getAvailableItems on AE network") ItemFingerprint needle,
@Optionals @Arg(name = "qty", description = "The quantity of items you want to craft") Long quantity,
@Arg(name = "cpu", description = "The name of the CPU you want to use") String wantedCpuName) {
ICraftingGrid craftingGrid = getCraftingGrid(host);
if (quantity == null) quantity = 1L;
ICraftingCPU wantedCpu = findCpu(craftingGrid, wantedCpuName);
IStorageGrid storageGrid = getStorageGrid(host);
IMEMonitor<IAEItemStack> monitor = storageGrid.getItemInventory();
IAEItemStack stack = findCraftableStack(storageGrid.getItemInventory().getStorageList(), needle);
Preconditions.checkArgument(stack != null, "Can't find craftable item fingerprint %s", needle);
final IAEItemStack toCraft = stack.copy();
toCraft.setStackSize(quantity);
// Create a new CraftingCallback. This callback is called when
// the network finished calculating the required items. It can do two things for us:
// a) It sends an event when items are missing to complete the request
// b) Otherwise it starts the crafting job, which itself is a CraftingRequester OSsending more events to the computer.
final CraftingCallback craftingCallback = new CraftingCallback(access, converter, craftingGrid, monitor, host, wantedCpu, toCraft);
// We will need access to the worldObj of the ME Interface -> cast to TileEntity
final TileEntity tileEntity = (TileEntity)host;
// Tell the craftingGrid to begin calculating and to report everything to the CraftingCallback
craftingGrid.beginCraftingJob(tileEntity.getWorldObj(), getGrid(host), new MachineSource(host), toCraft, craftingCallback);
}
示例11: getAllStacks
import openperipheral.api.Constants; //导入依赖的package包/类
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a table with all the items of the chest")
public Map<Index, Object> getAllStacks(IInventory target,
@Env(Constants.ARG_ARCHITECTURE) IArchitecture access,
@Optionals @Arg(name = "proxy", description = "If false, method will compute whole table, instead of returning proxy") Boolean proxy) {
final IInventory inventory = InventoryUtils.getInventory(target);
Map<Index, Object> result = Maps.newHashMap();
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack != null) result.put(access.createIndex(i), (proxy != Boolean.FALSE)? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack);
}
return result;
}
示例12: setSlots
import openperipheral.api.Constants; //导入依赖的package包/类
@ScriptCallable(description = "Set the items being displayed in all slots")
public void setSlots(
@Env(Constants.ARG_ARCHITECTURE) IArchitecture access,
@Arg(name = "items", description = "A table containing itemstacks") Map<Index, ItemStack> stacks) {
for (int slot = 0; slot < 9; slot++) {
final ItemStack value = stacks.get(access.wrapObject(slot));
if (value != null) value.stackSize = 1;
this.slots[slot].set(value);
}
sync();
}
示例13: init
import openperipheral.api.Constants; //导入依赖的package包/类
public static void init() {
final MethodSelector peripheralSelector = new MethodSelector(Constants.ARCH_OPEN_COMPUTERS)
.allowReturnSignal()
.addDefaultEnv()
.addProvidedEnv(Constants.ARG_ACCESS, IArchitectureAccess.class)
.addProvidedEnv(Constants.ARG_CONTEXT, Context.class)
.addProvidedEnv(Constants.ARG_NODE, Node.class);
PERIPHERAL_METHODS_FACTORY = new EnvironmentMethodsFactory<ManagedEnvironment>(
AdapterRegistry.PERIPHERAL_ADAPTERS,
peripheralSelector,
PERIPHERAL_CLASS_PREFIX,
new PeripheralCodeGenerator());
InjectedClassesManager.instance.registerProvider(PERIPHERAL_CLASS_PREFIX, new EnvironmentClassBytesProvider<ManagedEnvironment>(PERIPHERAL_METHODS_FACTORY));
final MethodSelector objectSelector = new MethodSelector(Constants.ARCH_OPEN_COMPUTERS)
// .allowReturnSignal() // for symmetry with CC
.addDefaultEnv()
.addProvidedEnv(Constants.ARG_CONTEXT, Context.class);
OBJECT_METHODS_FACTORY = new EnvironmentMethodsFactory<Value>(
AdapterRegistry.OBJECT_ADAPTERS,
objectSelector,
OBJECT_CLASS_PREFIX,
new ObjectCodeGenerator());
InjectedClassesManager.instance.registerProvider(OBJECT_CLASS_PREFIX, new EnvironmentClassBytesProvider<Value>(OBJECT_METHODS_FACTORY));
CommandDump.addArchSerializer("OpenComputers", "peripheral", DocBuilder.TILE_ENTITY_DECORATOR, PERIPHERAL_METHODS_FACTORY);
CommandDump.addArchSerializer("OpenComputers", "object", DocBuilder.SCRIPT_OBJECT_DECORATOR, OBJECT_METHODS_FACTORY);
final IConverter converter = new TypeConversionRegistryOC();
TypeConvertersProvider.INSTANCE.registerConverter(Constants.ARCH_OPEN_COMPUTERS, converter);
TypeClassifier.INSTANCE.registerType(Value.class, SingleArgType.OBJECT);
ENV = new OpenComputersEnv(converter);
}
示例14: addPeripheralArgs
import openperipheral.api.Constants; //导入依赖的package包/类
public IMethodCall addPeripheralArgs(IMethodCall call, Node node, Context context) {
final OCArchitectureAccess wrapper = new OCArchitectureAccess(node, context, converter);
return addCommonArgs(call, context)
.setEnv(Constants.ARG_ARCHITECTURE, wrapper)
.setEnv(Constants.ARG_ACCESS, wrapper)
.setEnv(Constants.ARG_NODE, node);
}
示例15: init
import openperipheral.api.Constants; //导入依赖的package包/类
public static void init() {
final MethodSelector peripheralSelector = new MethodSelector(Constants.ARCH_COMPUTER_CRAFT)
.allowReturnSignal()
.addDefaultEnv()
.addProvidedEnv(Constants.ARG_ACCESS, IArchitectureAccess.class)
.addProvidedEnv(Constants.ARG_COMPUTER, IComputerAccess.class)
.addProvidedEnv(Constants.ARG_CONTEXT, ILuaContext.class);
PERIPHERAL_METHODS_FACTORY = new ComposedMethodsFactory<IndexedMethodMap>(AdapterRegistry.PERIPHERAL_ADAPTERS, peripheralSelector) {
@Override
protected IndexedMethodMap wrapMethods(Class<?> targetCls, Map<String, IMethodExecutor> methods) {
return new IndexedMethodMap(methods);
}
};
// can't push events, so not allowing return signals
final MethodSelector objectSelector = new MethodSelector(Constants.ARCH_COMPUTER_CRAFT)
.addDefaultEnv()
.addProvidedEnv(Constants.ARG_CONTEXT, ILuaContext.class);
OBJECT_METHODS_FACTORY = new ComposedMethodsFactory<IndexedMethodMap>(AdapterRegistry.OBJECT_ADAPTERS, objectSelector) {
@Override
protected IndexedMethodMap wrapMethods(Class<?> targetCls, Map<String, IMethodExecutor> methods) {
return new IndexedMethodMap(methods);
}
};
CommandDump.addArchSerializer("ComputerCraft", "peripheral", DocBuilder.TILE_ENTITY_DECORATOR, PERIPHERAL_METHODS_FACTORY);
CommandDump.addArchSerializer("ComputerCraft", "object", DocBuilder.SCRIPT_OBJECT_DECORATOR, OBJECT_METHODS_FACTORY);
final IConverter converter = new TypeConversionRegistryCC();
// CC converter is default one (legacy behaviour)
TypeConvertersProvider.INSTANCE.registerConverter(Constants.ARCH_COMPUTER_CRAFT, converter);
TypeClassifier.INSTANCE.registerType(ILuaObject.class, SingleArgType.OBJECT);
ENV = new ComputerCraftEnv(converter);
}