@@ -0,0 +1,2554 @@
+package org.squiddev.plethora.integration;%0A%0Aimport com.google.common.collect.Sets;%0Aimport dan200.computercraft.api.lua.LuaException;%0Aimport net.minecraft.util.ResourceLocation;%0Aimport org.squiddev.plethora.api.method.BasicObjectMethod;%0Aimport org.squiddev.plethora.api.method.IContext;%0Aimport org.squiddev.plethora.api.method.IUnbakedContext;%0Aimport org.squiddev.plethora.api.module.IModuleContainer;%0Aimport org.squiddev.plethora.api.reference.Reference;%0A%0Aimport javax.annotation.Nonnull;%0Aimport java.util.Set;%0A%0Aimport static org.squiddev.plethora.api.method.ArgumentHelper.getString;%0A%0Apublic class MethodsModules %7B%0A%09@BasicObjectMethod.Inject(%0A%09%09value = IModuleContainer.class, worldThread = true,%0A%09%09doc = %22function():table -- Lists all modules available%22%0A%09)%0A%09public static Object%5B%5D listModules(@Nonnull IContext%3CIModuleContainer%3E context, @Nonnull Object%5B%5D args) throws LuaException %7B%0A%09%09return new Object%5B%5D%7Bcontext.getModules().toArray()%7D;%0A%09%7D%0A%0A%09@BasicObjectMethod.Inject(%0A%09%09value = IModuleContainer.class, worldThread = true,%0A%09%09doc = %22function():boolean -- Checks whether a module is available%22%0A%09)%0A%09public static Object%5B%5D hasModules(@Nonnull IContext%3CIModuleContainer%3E context, @Nonnull Object%5B%5D args) throws LuaException %7B%0A%09%09ResourceLocation module = new ResourceLocation(getString(args, 0));%0A%09%09return new Object%5B%5D%7Bcontext.hasModule(module)%7D;%0A%09%7D%0A%0A%09/*@BasicObjectMethod.Inject(%0A%09%09value = IModuleContainer.class, worldThread = true,%0A%09%09doc = %22function(names:string...):table -- Gets the methods which require these modules%22%0A%09)*/%0A%09public static Object%5B%5D filterModules(@Nonnull IContext%3CIModuleContainer%3E context, @Nonnull Object%5B%5D args) throws LuaException %7B%0A%09%09final ResourceLocation%5B%5D modules = new ResourceLocation%5Bargs.length%5D;%0A%09%09for (int i = 0; i %3C args.length; i++) %7B%0A%09%09%09modules%5Bi%5D = new ResourceLocation(getString(args, i));%0A%09%09%7D%0A%0A%09%09final IModuleContainer container = context.getTarget();%0A%09%09IModuleContainer filteredContainer = new IModuleContainer() %7B%0A%09%09%09@Nonnull%0A%09%09%09@Override%0A%09%09%09public Set%3CResourceLocation%3E get() throws LuaException %7B%0A%09%09%09%09Set%3CResourceLocation%3E existing = container.get();%0A%09%09%09%09Set%3CResourceLocation%3E out = Sets.newHashSetWithExpectedSize(modules.length);%0A%09%09%09%09for (ResourceLocation module : modules) %7B%0A%09%09%09%09%09if (existing.contains(module)) out.add(module);%0A%09%09%09%09%7D%0A%09%09%09%09return out;%0A%09%09%09%7D%0A%09%09%7D;%0A%0A%09%09// FIXME: This doesn't actually work, we need to pass it to the primary module reference too.%0A%09%09IUnbakedContext%3CIModuleContainer%3E selected = context.makeChild(Reference.id(filteredContainer));%0A%0A%09%09return new Object%5B%5D%7Bselected.getObject()%7D;%0A%09%7D%0A%7D%0A

Add some basic methods to list modules