0

我正在开发一个允许使用 Lua 创建 mod 的 Minecraft mod。我希望用户能够使用他们想要的界面创建 TileEntities。目前我正在使用一个调用已注册 Lua 文件函数的 Base TE,但这不允许他们制作库存和外围设备。

4

1 回答 1

5

是的。您可以通过ClassLoader.html#loadClass(...)加载接口并使用Proxy#newProxyInstance(...)实现它

例子:

ClassLoader cl = getClass().getClassLoader();
Class<?> desiredInterface = cl.loadClass("SomeInterface");
Object proxy = Proxy.newProxyInstance(
                 cl, 
                 new Class<?>[]{desiredInterface},
                 new InvocationHandler() {
                      @Override
                      Object invoke(Object proxy, Method method, Object[] args) {
                        //call Lua with method name and args, return answer
                      }
                 });
于 2013-03-16T11:34:59.223 回答