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();
});
}
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);
}
}
}
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();
}
}
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;
}
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);
}
Aggregations