net.fabricmc.loader.api.ModContainer Java Examples
The following examples show how to use
net.fabricmc.loader.api.ModContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SandboxHooks.java From Sandbox with GNU Lesser General Public License v3.0 | 6 votes |
public static void setupGlobal() { Set<String> supportedMods = Sets.newHashSet("minecraft", "sandbox", "sandboxapi", "fabricloader"); Sandbox.unsupportedModsLoaded = FabricLoader.getInstance().getAllMods().stream() .map(ModContainer::getMetadata) .map(ModMetadata::getId) .anyMatch(((Predicate<String>) supportedMods::contains).negate()); Policy.setPolicy(new AddonSecurityPolicy()); Registry.REGISTRIES.add(new Identifier("sandbox", "container"), SandboxRegistries.CONTAINER_FACTORIES); ((SandboxInternal.Registry) Registry.BLOCK).set(new BasicRegistry<>(Registry.BLOCK, Block.class, WrappingUtil::convert, WrappingUtil::convert)); ((SandboxInternal.Registry) Registry.ITEM).set(new BasicRegistry<>(Registry.ITEM, Item.class, WrappingUtil::convert, WrappingUtil::convert)); ((SandboxInternal.Registry) Registry.ENCHANTMENT).set(new BasicRegistry<>((SimpleRegistry<net.minecraft.enchantment.Enchantment>) Registry.ENCHANTMENT, Enchantment.class, WrappingUtil::convert, b -> (Enchantment) b)); ((SandboxInternal.Registry) Registry.FLUID).set(new BasicRegistry<>(Registry.FLUID, Fluid.class, WrappingUtil::convert, WrappingUtil::convert)); ((SandboxInternal.Registry) Registry.ENTITY_TYPE).set(new BasicRegistry<>(Registry.ENTITY_TYPE, Entity.Type.class, WrappingUtil::convert, WrappingUtil::convert)); ((SandboxInternal.Registry) Registry.BLOCK_ENTITY).set(new BasicRegistry((SimpleRegistry) Registry.BLOCK_ENTITY, BlockEntity.Type.class, (Function<BlockEntity.Type, BlockEntityType>) WrappingUtil::convert, (Function<BlockEntityType, BlockEntity.Type>) WrappingUtil::convert, true)); // DONT TOUCH THIS FOR HEAVENS SAKE PLEASE GOD NO ((SandboxInternal.Registry) SandboxRegistries.CONTAINER_FACTORIES).set(new BasicRegistry<>(SandboxRegistries.CONTAINER_FACTORIES, ContainerFactory.class, a -> a, a -> a)); }
Example #2
Source File: VRPlatform.java From ViaFabric with MIT License | 6 votes |
@Override public JsonObject getDump() { JsonObject platformSpecific = new JsonObject(); List<PluginInfo> mods = new ArrayList<>(); for (ModContainer mod : FabricLoader.getInstance().getAllMods()) { mods.add(new PluginInfo(true, mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")", mod.getMetadata().getVersion().getFriendlyString(), null, mod.getMetadata().getAuthors().stream() .map(info -> info.getName() + (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap())) .collect(Collectors.toList()) )); } platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods)); return platformSpecific; }
Example #3
Source File: AccessWidener.java From fabric-loader with Apache License 2.0 | 6 votes |
public void loadFromMods() { for (ModContainer modContainer : fabricLoader.getAllMods()) { LoaderModMetadata modMetadata = (LoaderModMetadata) modContainer.getMetadata(); String accessWidener = modMetadata.getAccessWidener(); if (accessWidener != null) { Path path = modContainer.getPath(accessWidener); try (BufferedReader reader = Files.newBufferedReader(path)) { read(reader, fabricLoader.getMappingResolver().getCurrentRuntimeNamespace()); } catch (Exception e) { throw new RuntimeException("Failed to read accessWidener file from mod " + modMetadata.getId(), e); } } } }
Example #4
Source File: LibGuiTest.java From LibGui with MIT License | 5 votes |
@Override public void onInitialize() { Registry.register(Registry.ITEM, new Identifier(MODID, "client_gui"), new GuiItem()); GUI_BLOCK = new GuiBlock(); Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK); GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC)); Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM); GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null); Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE); GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> { return new TestDescription(GUI_SCREEN_HANDLER_TYPE, syncId, inventory, ScreenHandlerContext.EMPTY); }); Optional<ModContainer> containerOpt = FabricLoader.getInstance().getModContainer("jankson"); if (containerOpt.isPresent()) { ModContainer jankson = containerOpt.get(); System.out.println("Jankson root path: "+jankson.getRootPath()); try { Files.list(jankson.getRootPath()).forEach((path)->{ path.getFileSystem().getFileStores().forEach((store)->{ System.out.println(" Filestore: "+store.name()); }); System.out.println(" "+path.toAbsolutePath()); }); } catch (IOException e) { e.printStackTrace(); } Path modJson = jankson.getPath("/fabric.mod.json"); System.out.println("Jankson fabric.mod.json path: "+modJson); System.out.println(Files.exists(modJson) ? "Exists" : "Does Not Exist"); } else { System.out.println("Container isn't present!"); } }
Example #5
Source File: ModList.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
public ModFileInfo getModFileById(String modId) { ModContainer modContainer = FabricLoader.getInstance().getModContainer(modId).orElse(null); if (modContainer == null) { return null; } return getModFileByContainer(modContainer); }
Example #6
Source File: ModList.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
private ModFileInfo createModFileInfo(ModContainer modContainer) { ModMetadata metadata = modContainer.getMetadata(); // First try to find a patchwork:annotations entry for this file. If it exists, then this is the "primary" mod // for a given JAR file. CustomValue annotations = metadata.getCustomValue("patchwork:annotations"); if (annotations != null) { String annotationJsonLocation = annotations.getAsString(); return new ModFileInfo(modContainer, annotationJsonLocation); } // If there is no annotation data indicative of a primary mod file, try to then find the parent (primary) mod ID. // This indicates that this is a dummy JiJ mod created by Patchwork Patcher. CustomValue parent = metadata.getCustomValue("patchwork:parent"); if (parent != null) { return getModFileById(parent.getAsString()); } // This mod lacks annotation data or a parent mod ID. // Check to see if it was run through an old version of Patcher (if it lacks both the parent and annotations // attributes but has the source attribute) CustomValue source = modContainer.getMetadata().getCustomValue("patchwork:source"); if (source != null) { CustomValue.CvObject object = source.getAsObject(); String loader = object.get("loader").getAsString(); if (loader.equals("forge")) { LOGGER.warn("A mod was patched with an old version of Patchwork Patcher, please re-patch it! " + "No annotation data is available for " + metadata.getId() + " (loaded from " + modContainer.getRootPath() + ")"); } } // Either a patchwork mod missing annotation data, or a normal Fabric mod. return new ModFileInfo(); }
Example #7
Source File: FabricMixinBootstrap.java From fabric-loader with Apache License 2.0 | 5 votes |
static Set<String> getMixinConfigs(FabricLoader loader, EnvType type) { return loader.getAllMods().stream() .map(ModContainer::getMetadata) .filter((m) -> m instanceof LoaderModMetadata) .flatMap((m) -> ((LoaderModMetadata) m).getMixinConfigs(type).stream()) .filter(s -> s != null && !s.isEmpty()) .collect(Collectors.toSet()); }
Example #8
Source File: OptifabricSetup.java From OptiFabric with Mozilla Public License 2.0 | 4 votes |
private ModMetadata getModMetaData(String modId) { Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer(modId); return modContainer.map(ModContainer::getMetadata).orElse(null); }
Example #9
Source File: ModFileScanData.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public ModFileScanData(ModContainer modContainer, String annotationJsonLocation) { this.modContainer = modContainer; this.annotationJsonLocation = annotationJsonLocation; }
Example #10
Source File: ModList.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
private ModFileInfo getModFileByContainer(ModContainer modContainer) { return modFileInfoMap.computeIfAbsent(modContainer, this::createModFileInfo); }
Example #11
Source File: ModFile.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public ModFile(ModContainer fabricModContainer, String annotationJsonLocation) { modFileScanData = new ModFileScanData(fabricModContainer, annotationJsonLocation); }
Example #12
Source File: ModFileInfo.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public ModFileInfo(ModContainer modContainer, String annotationJsonLocation) { modFile = new ModFile(modContainer, annotationJsonLocation); }
Example #13
Source File: EntrypointContainer.java From fabric-loader with Apache License 2.0 | 2 votes |
/** * Returns the mod that provided this entrypoint. */ ModContainer getProvider();