mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Some tweaks around the code base. A functional consumer for networking - return a bool from your consumer function, rather than setPacketHandled.
Tweak the server modloading behaviour to try and be a bit clearer that a mod errored. Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
7 files changed
+80
-15
No files matched your search
@@ -60,6 +60,7 @@ import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.event.world.RegisterDimensionsEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.StartupQuery;
|
||||
import net.minecraftforge.fml.server.ServerModLoader;
|
||||
import net.minecraftforge.registries.ClearableRegistry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@@ -160,6 +161,9 @@ public class DimensionManager
|
||||
Validate.notNull(server, "Must provide server when creating world");
|
||||
Validate.notNull(dim, "Dimension type must not be null");
|
||||
|
||||
if (ServerModLoader.hasErrors()) {
|
||||
throw new RuntimeException("The server has failed to initialize correctly due to mod loading errors. Examine the crash report for more details.");
|
||||
}
|
||||
// If we're in the early stages of loading, we need to return null so CommandSource can work properly for command function
|
||||
if (StartupQuery.pendingQuery()) {
|
||||
return null;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package net.minecraftforge.fml;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LoadingFailedException extends RuntimeException {
|
||||
private final List<ModLoadingException> loadingExceptions;
|
||||
@@ -31,4 +32,9 @@ public class LoadingFailedException extends RuntimeException {
|
||||
public List<ModLoadingException> getErrors() {
|
||||
return this.loadingExceptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Loading errors encountered: " + this.loadingExceptions.stream().map(ModLoadingException::getMessage).collect(Collectors.joining(",\n\t", "[\n\t", "\n]"));
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,23 @@ public class SimpleChannel
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface ToBooleanBiFunction<T, U> {
|
||||
boolean applyAsBool(T first, U second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function returning a boolean "packet handled" indication, for simpler channel building.
|
||||
* @param handler a handler
|
||||
* @return this
|
||||
*/
|
||||
public MessageBuilder<MSG> consumer(ToBooleanBiFunction<MSG, Supplier<NetworkEvent.Context>> handler) {
|
||||
this.consumer = (msg, ctx) -> {
|
||||
boolean handled = handler.applyAsBool(msg, ctx);
|
||||
ctx.get().setPacketHandled(handled);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
final IndexedMessageCodec.MessageHandler<MSG> message = this.channel.registerMessage(this.id, this.type, this.encoder, this.decoder, this.consumer);
|
||||
if (this.loginIndexSetter != null) {
|
||||
|
||||
@@ -21,10 +21,7 @@ package net.minecraftforge.fml.server;
|
||||
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.LogicalSidedProvider;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.ModLoadingWarning;
|
||||
import net.minecraftforge.fml.SidedProvider;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.network.FMLStatusPing;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -37,17 +34,31 @@ public class ServerModLoader
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static DedicatedServer server;
|
||||
private static boolean hasErrors = false;
|
||||
|
||||
public static void begin(DedicatedServer dedicatedServer) {
|
||||
ServerModLoader.server = dedicatedServer;
|
||||
SidedProvider.setServer(()->dedicatedServer);
|
||||
LogicalSidedProvider.setServer(()->dedicatedServer);
|
||||
LanguageHook.loadForgeAndMCLangs();
|
||||
ModLoader.get().gatherAndInitializeMods(null);
|
||||
ModLoader.get().loadMods(Runnable::run, (a)->{}, (a)->{});
|
||||
try {
|
||||
ModLoader.get().gatherAndInitializeMods(null);
|
||||
ModLoader.get().loadMods(Runnable::run, (a)->{}, (a)->{});
|
||||
} catch (LoadingFailedException e) {
|
||||
ServerModLoader.hasErrors = true;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void end() {
|
||||
ModLoader.get().finishMods(Runnable::run);
|
||||
try {
|
||||
ModLoader.get().finishMods(Runnable::run);
|
||||
} catch (LoadingFailedException e) {
|
||||
ServerModLoader.hasErrors = true;
|
||||
throw e;
|
||||
|
||||
}
|
||||
List<ModLoadingWarning> warnings = ModLoader.get().getWarnings();
|
||||
if (!warnings.isEmpty()) {
|
||||
LOGGER.warn(LOADING, "Mods loaded with {} warnings", warnings.size());
|
||||
@@ -56,4 +67,8 @@ public class ServerModLoader
|
||||
MinecraftForge.EVENT_BUS.start();
|
||||
server.getServerStatusResponse().setForgeData(new FMLStatusPing()); //gathers NetworkRegistry data
|
||||
}
|
||||
|
||||
public static boolean hasErrors() {
|
||||
return ServerModLoader.hasErrors;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user