本文整理汇总了Java中li.cil.oc.api.network.ManagedEnvironment类的典型用法代码示例。如果您正苦于以下问题:Java ManagedEnvironment类的具体用法?Java ManagedEnvironment怎么用?Java ManagedEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagedEnvironment类属于li.cil.oc.api.network包,在下文中一共展示了ManagedEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSignallingPeripheral
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test
public void testSignallingPeripheral() throws Exception {
setupEnvMocks();
Map<String, Pair<IMethodExecutor, IMethodCall>> mocks = Maps.newHashMap();
addMethod(mocks, "async", true, Optional.of("hello"), "desc1");
addMethod(mocks, "sync", false, Optional.of("hello"), "desc2");
Map<String, IMethodExecutor> methods = extractExecutors(mocks);
ICodeGenerator generator = new PeripheralCodeGenerator();
Class<?> cls = generateClass("TestClass\u2659", TargetClass.class, methods, generator);
final TargetClass target = mock(TargetClass.class);
Object o = cls.getConstructor(TargetClass.class).newInstance(target);
Assert.assertTrue(o instanceof ISignallingCallerBase);
Assert.assertTrue(o instanceof ManagedEnvironment);
ManagedEnvironment e = (ManagedEnvironment)o;
Assert.assertTrue(e.canUpdate());
testSignallingMethod(cls, "async");
testSignallingMethod(cls, "sync");
}
示例2: testNodeConnectivity
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test
public void testNodeConnectivity() throws Exception {
setupOpenComputersApiMock();
ICodeGenerator generator = new PeripheralCodeGenerator();
Map<String, IMethodExecutor> methods = Maps.newHashMap();
Class<? extends ManagedEnvironment> cls = generateClass("TestClass\u2654", SemiAwareTargetClass.class, ImmutableSet.<Class<?>> of(), methods, generator);
final SemiAwareTargetClass target = mock(SemiAwareTargetClass.class);
ManagedEnvironment o = cls.getConstructor(SemiAwareTargetClass.class).newInstance(target);
Node node = mock(Node.class);
o.onConnect(node);
verifyOcSpecificConnectCall(target, node);
o.onDisconnect(node);
verifyOcSpecificDisconnectCall(target, node);
}
示例3: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileMotor)
return new EnvironmentMotor((TileMotor) te);
return null;
}
示例4: init
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的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);
}
示例5: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te == null) {
Log.warn("Trying to provide environment for %d,%d,%d in world %d, but TE not found", x, y, z, world.provider.dimensionId);
return null;
}
final IEnviromentInstanceWrapper<ManagedEnvironment> adaptedClass = ModuleOpenComputers.PERIPHERAL_METHODS_FACTORY.getAdaptedClass(te.getClass());
return adaptedClass.createEnvironment(te);
}
示例6: createPeripheral
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createPeripheral(Object target) {
try {
return wrap(target, ModuleOpenComputers.PERIPHERAL_METHODS_FACTORY);
} catch (Throwable t) {
throw new GenerationFailedException(String.format("%s (%s)", target, target.getClass()), t);
}
}
示例7: testPeripheral
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test
public void testPeripheral() throws Exception {
setupEnvMocks();
final Node node = setupOpenComputersApiMock();
Map<String, Pair<IMethodExecutor, IMethodCall>> mocks = Maps.newHashMap();
addDefaultMethods(mocks);
Map<String, IMethodExecutor> methods = extractExecutors(mocks);
ICodeGenerator generator = new PeripheralCodeGenerator();
Class<?> cls = generateClass("TestClass\u2652", TargetClass.class, ImmutableSet.of(InterfaceA.class, InterfaceB.class), methods, generator);
final TargetClass target = mock(TargetClass.class);
Object o = cls.getConstructor(TargetClass.class).newInstance(target);
Assert.assertTrue(o instanceof ICallerBase);
Assert.assertTrue(o instanceof ManagedEnvironment);
Assert.assertTrue(o instanceof InterfaceA);
Assert.assertTrue(o instanceof InterfaceB);
ManagedEnvironment e = (ManagedEnvironment)o;
Assert.assertFalse(e.canUpdate());
verifyCallThrough(target, o);
testMethods(mocks, cls, target, o, new ArgVerifier() {
@Override
public void verifyCall(IMethodCall call, Context context) {
verify(ModuleOpenComputers.ENV).addPeripheralArgs(call, node, context);
}
});
}
示例8: testPeripheralNullTarget
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testPeripheralNullTarget() throws Throwable {
setupEnvMocks();
setupOpenComputersApiMock();
Map<String, Pair<IMethodExecutor, IMethodCall>> mocks = Maps.newHashMap();
addMethod(mocks, "a1", true, "desc1");
Map<String, IMethodExecutor> methods = extractExecutors(mocks);
ICodeGenerator generator = new PeripheralCodeGenerator();
Class<?> cls = generateClass("TestClass\u2655", TargetClass.class, ImmutableSet.<Class<?>> of(), methods, generator);
Object o = cls.getConstructor(TargetClass.class).newInstance(new Object[] { null });
Assert.assertTrue(o instanceof ManagedEnvironment);
Method m = getMethod(cls, "a1");
Arguments args = mock(Arguments.class);
Context context = mock(Context.class);
try {
m.invoke(o, context, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
示例9: testConnectivity
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test
public void testConnectivity() throws Exception {
final Node node = setupOpenComputersApiMock();
ICodeGenerator generator = new PeripheralCodeGenerator();
Map<String, IMethodExecutor> methods = Maps.newHashMap();
Class<? extends ManagedEnvironment> cls = generateClass("TestClass\u2653", AwareTargetClass.class, ImmutableSet.<Class<?>> of(), methods, generator);
final AwareTargetClass target = mock(AwareTargetClass.class);
ManagedEnvironment o = cls.getConstructor(AwareTargetClass.class).newInstance(target);
ContextEnvironment environment = mock(ContextEnvironment.class);
final String nodeAddress = "node_11";
when(node.address()).thenReturn(nodeAddress);
when(node.host()).thenReturn(environment);
when(environment.node()).thenReturn(node);
final OpenComputersEnv env = mock(OpenComputersEnv.class);
final IArchitectureAccess access = mock(IArchitectureAccess.class);
when(env.createAccess(node, environment)).thenReturn(access);
ModuleOpenComputers.ENV = env;
o.onConnect(node);
verify(target).addComputer(access);
verifyOcSpecificConnectCall(target, node);
o.onDisconnect(node);
verify(target).removeComputer(access);
verifyOcSpecificDisconnectCall(target, node);
}
示例10: testCommonConnectivity
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Test
public void testCommonConnectivity() throws Exception {
final Node node = setupOpenComputersApiMock();
ICodeGenerator generator = new PeripheralCodeGenerator();
Map<String, IMethodExecutor> methods = Maps.newHashMap();
Class<? extends ManagedEnvironment> cls = generateClass("TestClass\u2658", CommonAwareTargetClass.class, ImmutableSet.<Class<?>> of(), methods, generator);
final CommonAwareTargetClass target = mock(CommonAwareTargetClass.class);
ManagedEnvironment o = cls.getConstructor(CommonAwareTargetClass.class).newInstance(target);
ContextEnvironment environment = mock(ContextEnvironment.class);
final String nodeAddress = "node_13";
when(node.address()).thenReturn(nodeAddress);
when(node.host()).thenReturn(environment);
when(environment.node()).thenReturn(node);
final OpenComputersEnv env = mock(OpenComputersEnv.class);
final IArchitectureAccess access = mock(IArchitectureAccess.class);
when(env.createAccess(node, environment)).thenReturn(access);
ModuleOpenComputers.ENV = env;
o.onConnect(node);
verify(target).addComputer(access);
o.onDisconnect(node);
verify(target).removeComputer(access);
}
示例11: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(World world, BlockPos blockPos, EnumFacing enumFacing) {
return new InternalManagedEnvironment((TileEntityBase) world.getTileEntity(blockPos));
}
示例12: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(ItemStack stack, EnvironmentHost host)
{
return new Environment(host);
}
示例13: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(ItemStack stack, EnvironmentHost host) {
return new EnvTeslaUpgrade(host);
}
示例14: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(ItemStack stack, EnvironmentHost host) {
return new EnvNRUpgrade(host);
}
示例15: createEnvironment
import li.cil.oc.api.network.ManagedEnvironment; //导入依赖的package包/类
@Override
public ManagedEnvironment createEnvironment(ItemStack stack, EnvironmentHost host) {
return new EnvRadarUpgrade(host);
}