From 86dafbc108fbc86a5d100b84804321a30f438883 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 12 May 2024 10:49:08 +0200 Subject: [PATCH] Ensure we load mod resources correctly on Geyser-NeoForge (#4651) * correctly load jar resource files on neoforge * also add support for neoforge-floodgate --- bootstrap/mod/neoforge/build.gradle.kts | 4 ++- .../neoforge/GeyserNeoForgeBootstrap.java | 5 ++-- .../neoforge/GeyserNeoForgePlatform.java | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bootstrap/mod/neoforge/build.gradle.kts b/bootstrap/mod/neoforge/build.gradle.kts index ff77bcc5c..92ffae7e5 100644 --- a/bootstrap/mod/neoforge/build.gradle.kts +++ b/bootstrap/mod/neoforge/build.gradle.kts @@ -31,7 +31,9 @@ dependencies { // Let's shade in our own api shadow(projects.api) { isTransitive = false } - shadow(projects.common) { isTransitive = false } + + // cannot be shaded, since neoforge will complain if floodgate-neoforge tries to provide this + include(projects.common) // Include all transitive deps of core via JiJ includeTransitive(projects.core) diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java index 1655dea91..b97e42389 100644 --- a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java +++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.platform.neoforge; import net.minecraft.commands.CommandSourceStack; import net.minecraft.world.entity.player.Player; +import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.neoforge.common.NeoForge; @@ -43,8 +44,8 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap { private final GeyserNeoForgePermissionHandler permissionHandler = new GeyserNeoForgePermissionHandler(); - public GeyserNeoForgeBootstrap() { - super(new GeyserNeoForgePlatform()); + public GeyserNeoForgeBootstrap(ModContainer container) { + super(new GeyserNeoForgePlatform(container)); if (isServer()) { // Set as an event so we can get the proper IP and port if needed diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePlatform.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePlatform.java index 63abe4a4a..41562baf3 100644 --- a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePlatform.java +++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePlatform.java @@ -26,20 +26,29 @@ package org.geysermc.geyser.platform.neoforge; import net.minecraft.server.MinecraftServer; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLPaths; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.platform.mod.GeyserModBootstrap; import org.geysermc.geyser.platform.mod.platform.GeyserModPlatform; +import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.nio.file.Path; public class GeyserNeoForgePlatform implements GeyserModPlatform { + private final ModContainer container; + + public GeyserNeoForgePlatform(ModContainer container) { + this.container = container; + } + @Override public @NonNull PlatformType platformType() { return PlatformType.NEOFORGE; @@ -62,11 +71,21 @@ public class GeyserNeoForgePlatform implements GeyserModPlatform { @Override public boolean testFloodgatePluginPresent(@NonNull GeyserModBootstrap bootstrap) { - return false; // No Floodgate mod for NeoForge yet + if (ModList.get().isLoaded("floodgate")) { + Path floodgateDataFolder = FMLPaths.CONFIGDIR.get().resolve("floodgate"); + bootstrap.getGeyserConfig().loadFloodgate(bootstrap, floodgateDataFolder); + return true; + } + return false; } @Override public @Nullable InputStream resolveResource(@NonNull String resource) { - return GeyserBootstrap.class.getClassLoader().getResourceAsStream(resource); + try { + Path path = container.getModInfo().getOwningFile().getFile().findResource(resource); + return Files.newInputStream(path); + } catch (IOException e) { + return null; + } } }