Search in sources :

Example 1 with ModContainer

use of net.fabricmc.loader.api.ModContainer in project fabric by FabricMC.

the class MixinCrashReport method fillSystemDetails.

@Inject(at = @At("RETURN"), method = "fillSystemDetails")
private void fillSystemDetails(CallbackInfo info) {
    getSystemDetailsSection().add("Fabric Mods", () -> {
        Map<String, String> mods = new TreeMap<>();
        for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
            mods.put(container.getMetadata().getId(), container.getMetadata().getName() + " " + container.getMetadata().getVersion().getFriendlyString());
        }
        StringBuilder modString = new StringBuilder();
        for (String id : mods.keySet()) {
            modString.append("\n\t\t");
            modString.append(id);
            modString.append(": ");
            modString.append(mods.get(id));
        }
        return modString.toString();
    });
}
Also used : ModContainer(net.fabricmc.loader.api.ModContainer) TreeMap(java.util.TreeMap) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ModContainer

use of net.fabricmc.loader.api.ModContainer in project fabric by FabricMC.

the class ModResourcePackUtil method appendModResourcePacks.

public static void appendModResourcePacks(List<ResourcePack> packList, ResourceType type) {
    for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
        Path path = container.getRootPath();
        ResourcePack pack = new ModNioResourcePack(container.getMetadata(), path, null);
        if (!pack.getNamespaces(type).isEmpty()) {
            packList.add(pack);
        }
    }
}
Also used : Path(java.nio.file.Path) ModContainer(net.fabricmc.loader.api.ModContainer) ResourcePack(net.minecraft.resource.ResourcePack)

Example 3 with ModContainer

use of net.fabricmc.loader.api.ModContainer in project StationAPI by ModificationStation.

the class MixinSoundHelper method loadModAudio.

@Environment(EnvType.CLIENT)
private static void loadModAudio(SoundMap array, String channel) {
    try {
        for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
            ModMetadata stationMod = modContainer.getMetadata();
            Path basePath = Paths.get("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel);
            if (MixinSoundHelper.class.getResource(basePath.toString().replace("\\", "/")) != null) {
                RecursiveReader recursiveReader = new RecursiveReader("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel, (filepath) -> filepath.endsWith(".ogg") || filepath.endsWith(".mp3") || filepath.endsWith(".wav"));
                for (URL audioUrl : recursiveReader.read()) {
                    String audioID = audioUrl.toString().replace("\\", "/").split("/stationapi/sounds/" + channel)[1].replaceFirst("/", "");
                    ((CustomSoundMap) array).putSound(stationMod.getId() + ":" + audioID, audioUrl);
                }
            }
        }
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}
Also used : RecursiveReader(net.modificationstation.stationapi.api.resource.RecursiveReader) ModContainer(net.fabricmc.loader.api.ModContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) CustomSoundMap(net.modificationstation.stationapi.api.client.resource.CustomSoundMap) Environment(net.fabricmc.api.Environment)

Example 4 with ModContainer

use of net.fabricmc.loader.api.ModContainer in project meteor-client by MeteorDevelopment.

the class MixinPlugin method onLoad.

@Override
public void onLoad(String mixinPackage) {
    if (loaded)
        return;
    try {
        // Get class loader
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?> classLoaderClass = classLoader.getClass();
        // Get delegate
        Field delegateField = classLoaderClass.getDeclaredField("delegate");
        delegateField.setAccessible(true);
        Object delegate = delegateField.get(classLoader);
        Class<?> delegateClass = delegate.getClass();
        // Get mixinTransformer field
        Field mixinTransformerField = delegateClass.getDeclaredField("mixinTransformer");
        mixinTransformerField.setAccessible(true);
        // Get unsafe
        Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
        unsafeField.setAccessible(true);
        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        // Create Asm
        Asm.init();
        // Change delegate
        Asm.Transformer mixinTransformer = (Asm.Transformer) unsafe.allocateInstance(Asm.Transformer.class);
        mixinTransformer.delegate = (IMixinTransformer) mixinTransformerField.get(delegate);
        mixinTransformerField.set(delegate, mixinTransformer);
    } catch (NoSuchFieldException | IllegalAccessException | InstantiationException e) {
        e.printStackTrace();
    }
    for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
        isResourceLoaderPresent = isResourceLoaderPresent || mod.getMetadata().getId().startsWith("fabric-resource-loader");
        isIndigoPresent = isIndigoPresent || mod.getMetadata().getId().startsWith("fabric-renderer-indigo");
    }
    isOriginsPresent = FabricLoader.getInstance().isModLoaded("origins");
    isSodiumPresent = FabricLoader.getInstance().isModLoaded("sodium");
    isCanvasPresent = FabricLoader.getInstance().isModLoaded("canvas");
    loaded = true;
}
Also used : IMixinTransformer(org.spongepowered.asm.mixin.transformer.IMixinTransformer) ModContainer(net.fabricmc.loader.api.ModContainer) Unsafe(sun.misc.Unsafe) Field(java.lang.reflect.Field) Asm(meteordevelopment.meteorclient.asm.Asm)

Example 5 with ModContainer

use of net.fabricmc.loader.api.ModContainer in project Geyser-Fabric by GeyserMC.

the class GeyserFabricMod method startGeyser.

/**
 * Initialize core Geyser.
 * A function, as it needs to be called in different places depending on if Geyser is being reloaded or not.
 *
 * @param server The minecraft server.
 */
public void startGeyser(MinecraftServer server) {
    this.server = server;
    if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
        this.geyserConfig.setAutoconfiguredRemote(true);
        String ip = server.getServerIp();
        int port = ((GeyserServerPortGetter) server).geyser$getServerPort();
        if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
            this.geyserConfig.getRemote().setAddress(ip);
        }
        this.geyserConfig.getRemote().setPort(port);
    }
    if (geyserConfig.getBedrock().isCloneRemotePort()) {
        geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort());
    }
    Optional<ModContainer> floodgate = FabricLoader.getInstance().getModContainer("floodgate");
    boolean floodgatePresent = floodgate.isPresent();
    if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && !floodgatePresent) {
        geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
        return;
    } else if (geyserConfig.isAutoconfiguredRemote() && floodgatePresent) {
        // Floodgate installed means that the user wants Floodgate authentication
        geyserLogger.debug("Auto-setting to Floodgate authentication.");
        geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
    }
    geyserConfig.loadFloodgate(this, floodgate.orElse(null));
    this.connector = GeyserImpl.start(PlatformType.FABRIC, this);
    this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
    this.geyserCommandManager = new GeyserFabricCommandManager(connector);
    this.geyserWorldManager = new GeyserFabricWorldManager(server);
    // Start command building
    // Set just "geyser" as the help command
    GeyserFabricCommandExecutor helpExecutor = new GeyserFabricCommandExecutor(connector, connector.getCommandManager().getCommands().get("help"), !playerCommands.contains("help"));
    commandExecutors.add(helpExecutor);
    LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser").executes(helpExecutor);
    // Register all subcommands as valid
    for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) {
        GeyserFabricCommandExecutor executor = new GeyserFabricCommandExecutor(connector, command.getValue(), !playerCommands.contains(command.getKey()));
        commandExecutors.add(executor);
        builder.then(net.minecraft.server.command.CommandManager.literal(command.getKey()).executes(executor));
    }
    server.getCommandManager().getDispatcher().register(builder);
}
Also used : GeyserCommand(org.geysermc.geyser.command.GeyserCommand) ModContainer(net.fabricmc.loader.api.ModContainer) GeyserFabricCommandManager(org.geysermc.platform.fabric.command.GeyserFabricCommandManager) GeyserFabricWorldManager(org.geysermc.platform.fabric.world.GeyserFabricWorldManager) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) GeyserFabricCommandExecutor(org.geysermc.platform.fabric.command.GeyserFabricCommandExecutor)

Aggregations

ModContainer (net.fabricmc.loader.api.ModContainer)19 ModMetadata (net.fabricmc.loader.api.metadata.ModMetadata)3 Field (java.lang.reflect.Field)2 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 Version (net.fabricmc.loader.api.Version)2 I18n (net.minecraft.client.resource.language.I18n)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 IMixinTransformer (org.spongepowered.asm.mixin.transformer.IMixinTransformer)2 Unsafe (sun.misc.Unsafe)2 InternalExpressionException (carpet.script.exception.InternalExpressionException)1 LoadException (carpet.script.exception.LoadException)1 EntityValue (carpet.script.value.EntityValue)1 FunctionValue (carpet.script.value.FunctionValue)1 ListValue (carpet.script.value.ListValue)1 MapValue (carpet.script.value.MapValue)1 NumericValue (carpet.script.value.NumericValue)1 StringValue (carpet.script.value.StringValue)1 Value (carpet.script.value.Value)1 ImmutableMap (com.google.common.collect.ImmutableMap)1