Ensure we load mod resources correctly on Geyser-NeoForge (#4651)

* correctly load jar resource files on neoforge

* also add support for neoforge-floodgate
This commit is contained in:
chris 2024-05-12 10:49:08 +02:00 committed by GitHub
parent 7801e357fb
commit 86dafbc108
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 6 deletions

View file

@ -31,7 +31,9 @@ dependencies {
// Let's shade in our own api // Let's shade in our own api
shadow(projects.api) { isTransitive = false } 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 // Include all transitive deps of core via JiJ
includeTransitive(projects.core) includeTransitive(projects.core)

View file

@ -27,6 +27,7 @@ package org.geysermc.geyser.platform.neoforge;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod; import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader; import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.NeoForge;
@ -43,8 +44,8 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
private final GeyserNeoForgePermissionHandler permissionHandler = new GeyserNeoForgePermissionHandler(); private final GeyserNeoForgePermissionHandler permissionHandler = new GeyserNeoForgePermissionHandler();
public GeyserNeoForgeBootstrap() { public GeyserNeoForgeBootstrap(ModContainer container) {
super(new GeyserNeoForgePlatform()); super(new GeyserNeoForgePlatform(container));
if (isServer()) { if (isServer()) {
// Set as an event so we can get the proper IP and port if needed // Set as an event so we can get the proper IP and port if needed

View file

@ -26,20 +26,29 @@
package org.geysermc.geyser.platform.neoforge; package org.geysermc.geyser.platform.neoforge;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.FMLPaths; import net.neoforged.fml.loading.FMLPaths;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.platform.mod.GeyserModBootstrap; import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
import org.geysermc.geyser.platform.mod.platform.GeyserModPlatform; import org.geysermc.geyser.platform.mod.platform.GeyserModPlatform;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
public class GeyserNeoForgePlatform implements GeyserModPlatform { public class GeyserNeoForgePlatform implements GeyserModPlatform {
private final ModContainer container;
public GeyserNeoForgePlatform(ModContainer container) {
this.container = container;
}
@Override @Override
public @NonNull PlatformType platformType() { public @NonNull PlatformType platformType() {
return PlatformType.NEOFORGE; return PlatformType.NEOFORGE;
@ -62,11 +71,21 @@ public class GeyserNeoForgePlatform implements GeyserModPlatform {
@Override @Override
public boolean testFloodgatePluginPresent(@NonNull GeyserModBootstrap bootstrap) { 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 @Override
public @Nullable InputStream resolveResource(@NonNull String resource) { 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;
}
} }
} }