mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Fix config to use new system properly, without exploding the server.
Separates server specific config into the server config file. Signed-off-by: cpw <[email protected]>
This commit is contained in:
12 files changed
+134
-103
No files matched your search
@@ -23,7 +23,6 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
@@ -395,7 +394,7 @@ public class DimensionManager
|
||||
{
|
||||
int id = queueIterator.nextInt();
|
||||
DimensionData dimension = dimensions.get(id);
|
||||
if (dimension.ticksWaited < ForgeConfig.GENERAL.dimensionUnloadQueueDelay.get())
|
||||
if (dimension.ticksWaited < ForgeConfig.SERVER.dimensionUnloadQueueDelay.get())
|
||||
{
|
||||
dimension.ticksWaited++;
|
||||
continue;
|
||||
|
||||
@@ -22,43 +22,30 @@ package net.minecraftforge.common;
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.loading.LogMarkers.FORGEMOD;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ForgeConfig
|
||||
{
|
||||
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
||||
|
||||
public static final General GENERAL = new General(BUILDER);
|
||||
public static final Client CLIENT = new Client(BUILDER);
|
||||
|
||||
public static class General {
|
||||
|
||||
public final BooleanValue disableVersionCheck;
|
||||
|
||||
public final BooleanValue removeErroringEntities;
|
||||
{
|
||||
public static class Server {
|
||||
public final BooleanValue removeErroringEntities;
|
||||
public final BooleanValue removeErroringTileEntities;
|
||||
|
||||
public final BooleanValue fullBoundingBoxLadders;
|
||||
|
||||
public final DoubleValue zombieBaseSummonChance;
|
||||
public final DoubleValue zombieBabyChance ;
|
||||
public final DoubleValue zombieBabyChance;
|
||||
|
||||
public final BooleanValue logCascadingWorldGeneration;
|
||||
public final BooleanValue fixVanillaCascading;
|
||||
@@ -67,14 +54,9 @@ public class ForgeConfig
|
||||
|
||||
public final IntValue clumpingThreshold;
|
||||
|
||||
General(ForgeConfigSpec.Builder builder) {
|
||||
builder.comment("General settings that effect both the client and server")
|
||||
.push("general");
|
||||
|
||||
disableVersionCheck = builder
|
||||
.comment("Set to true to disable Forge's version check mechanics. Forge queries a small json file on our server for version information. For more details see the ForgeVersion class in our github.")
|
||||
.translation("forge.configgui.disableVersionCheck")
|
||||
.define("disableVersionCheck", false);
|
||||
Server(ForgeConfigSpec.Builder builder) {
|
||||
builder.comment("Server configuration settings")
|
||||
.push("server");
|
||||
|
||||
removeErroringEntities = builder
|
||||
.comment("Set this to true to remove any Entity that throws an error in its update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES.")
|
||||
@@ -130,7 +112,10 @@ public class ForgeConfig
|
||||
builder.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Client specific configuration - only loaded clientside from forge-client.toml
|
||||
*/
|
||||
public static class Client {
|
||||
public final BooleanValue zoomInMissingModelTextInGui;
|
||||
|
||||
@@ -184,14 +169,31 @@ public class ForgeConfig
|
||||
}
|
||||
}
|
||||
|
||||
static final ForgeConfigSpec spec = BUILDER.build();
|
||||
|
||||
static final ForgeConfigSpec clientSpec;
|
||||
public static final Client CLIENT;
|
||||
static {
|
||||
final Pair<Client, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Client::new);
|
||||
clientSpec = specPair.getRight();
|
||||
CLIENT = specPair.getLeft();
|
||||
}
|
||||
|
||||
|
||||
static final ForgeConfigSpec serverSpec;
|
||||
public static final Server SERVER;
|
||||
static {
|
||||
final Pair<Server, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Server::new);
|
||||
serverSpec = specPair.getRight();
|
||||
SERVER = specPair.getLeft();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final ForgeConfigSpec.Builder CHUNK_BUILDER = new ForgeConfigSpec.Builder();
|
||||
|
||||
|
||||
public static final Chunk CHUNK = new Chunk(CHUNK_BUILDER);
|
||||
|
||||
|
||||
public static class Chunk {
|
||||
|
||||
|
||||
public final BooleanValue enable;
|
||||
|
||||
public final IntValue chunksPerTicket;
|
||||
@@ -209,61 +211,61 @@ public class ForgeConfig
|
||||
.defineInRange("maxTickets", 200, 0, Integer.MAX_VALUE).next()
|
||||
.defineInRange("chunksPerTicket", 25, 0, Integer.MAX_VALUE).next()
|
||||
.build();
|
||||
|
||||
|
||||
private final CommentedConfig modCfgDefault = CommentedConfig.inMemory();
|
||||
|
||||
|
||||
|
||||
Chunk(ForgeConfigSpec.Builder builder) {
|
||||
builder.comment("Default configuration for Forge chunk loading control")
|
||||
.push("defaults");
|
||||
|
||||
.push("defaults");
|
||||
|
||||
enable = builder
|
||||
.comment("Allow mod overrides, false will use default for everything.")
|
||||
.translation("forge.configgui.enableModOverrides")
|
||||
.define("enable", true);
|
||||
|
||||
.comment("Allow mod overrides, false will use default for everything.")
|
||||
.translation("forge.configgui.enableModOverrides")
|
||||
.define("enable", true);
|
||||
|
||||
chunksPerTicket = builder
|
||||
.comment("The default maximum number of chunks a mod can force, per ticket,",
|
||||
"for a mod without an override. This is the maximum number of chunks a single ticket can force.")
|
||||
.translation("forge.configgui.maximumChunksPerTicket")
|
||||
.defineInRange("chunksPerTicket", 25, 0, Integer.MAX_VALUE);
|
||||
|
||||
.comment("The default maximum number of chunks a mod can force, per ticket,",
|
||||
"for a mod without an override. This is the maximum number of chunks a single ticket can force.")
|
||||
.translation("forge.configgui.maximumChunksPerTicket")
|
||||
.defineInRange("chunksPerTicket", 25, 0, Integer.MAX_VALUE);
|
||||
|
||||
maxTickets = builder
|
||||
.comment("The default maximum ticket count for a mod which does not have an override",
|
||||
"in this file. This is the number of chunk loading requests a mod is allowed to make.")
|
||||
.translation("forge.configgui.maximumTicketCount")
|
||||
.defineInRange("maxTickets", 200, 0, Integer.MAX_VALUE);
|
||||
|
||||
.comment("The default maximum ticket count for a mod which does not have an override",
|
||||
"in this file. This is the number of chunk loading requests a mod is allowed to make.")
|
||||
.translation("forge.configgui.maximumTicketCount")
|
||||
.defineInRange("maxTickets", 200, 0, Integer.MAX_VALUE);
|
||||
|
||||
playerTicketCount = builder
|
||||
.comment("The number of tickets a player can be assigned instead of a mod. This is shared across all mods and it is up to the mods to use it.")
|
||||
.translation("forge.configgui.playerTicketCount")
|
||||
.defineInRange("playerTicketCount", 500, 0, Integer.MAX_VALUE);
|
||||
|
||||
.comment("The number of tickets a player can be assigned instead of a mod. This is shared across all mods and it is up to the mods to use it.")
|
||||
.translation("forge.configgui.playerTicketCount")
|
||||
.defineInRange("playerTicketCount", 500, 0, Integer.MAX_VALUE);
|
||||
|
||||
dormantChunkCacheSize = builder
|
||||
.comment("Unloaded chunks can first be kept in a dormant cache for quicker loading times. Specify the size (in chunks) of that cache here")
|
||||
.translation("forge.configgui.dormantChunkCacheSize")
|
||||
.defineInRange("dormantChunkCacheSize", 0, 0, Integer.MAX_VALUE);
|
||||
|
||||
.comment("Unloaded chunks can first be kept in a dormant cache for quicker loading times. Specify the size (in chunks) of that cache here")
|
||||
.translation("forge.configgui.dormantChunkCacheSize")
|
||||
.defineInRange("dormantChunkCacheSize", 0, 0, Integer.MAX_VALUE);
|
||||
|
||||
asyncChunkLoading = builder
|
||||
.comment("Load chunks asynchronously for players, reducing load on the server thread.",
|
||||
"Can be disabled to help troubleshoot chunk loading issues.")
|
||||
.translation("forge.configgui.asyncChunkLoading")
|
||||
.define("asyncChunkLoading", true);
|
||||
|
||||
.comment("Load chunks asynchronously for players, reducing load on the server thread.",
|
||||
"Can be disabled to help troubleshoot chunk loading issues.")
|
||||
.translation("forge.configgui.asyncChunkLoading")
|
||||
.define("asyncChunkLoading", true);
|
||||
|
||||
chunkSpec.correct(modCfgDefault);
|
||||
builder.pop();
|
||||
}
|
||||
|
||||
private final ConfigValue<List<? extends CommentedConfig>> mods = CHUNK_BUILDER
|
||||
|
||||
private final ForgeConfigSpec.ConfigValue<List<? extends CommentedConfig>> mods = CHUNK_BUILDER
|
||||
.defineList("mods", Lists.newArrayList(modCfgDefault), o -> {
|
||||
if (!(o instanceof CommentedConfig)) return false;
|
||||
return chunkSpec.isCorrect((CommentedConfig) o);
|
||||
});
|
||||
|
||||
private int getByMod(ConfigValue<Integer> def, String name, String modid) {
|
||||
|
||||
private int getByMod(ForgeConfigSpec.ConfigValue<Integer> def, String name, String modid) {
|
||||
if (!enable.get() || modid == null)
|
||||
return def.get();
|
||||
|
||||
|
||||
return mods.get().stream().filter(c -> modid.equals(c.get("modid"))).findFirst()
|
||||
.map(c -> c.<Integer>get(name))
|
||||
.orElseGet(def::get);
|
||||
@@ -272,12 +274,12 @@ public class ForgeConfig
|
||||
public int maxTickets(@Nullable String modid) {
|
||||
return getByMod(maxTickets, "maxTickets", modid);
|
||||
}
|
||||
|
||||
|
||||
public int chunksPerTicket(@Nullable String modid) {
|
||||
return getByMod(chunksPerTicket, "chunksPerTicket", modid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final ForgeConfigSpec chunk_spec = CHUNK_BUILDER.build();
|
||||
|
||||
|
||||
|
||||
@@ -36,9 +36,12 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
@@ -434,6 +437,11 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Pair<T, ForgeConfigSpec> configure(Function<Builder, T> consumer) {
|
||||
T o = consumer.apply(this);
|
||||
return Pair.of(o, this.build());
|
||||
}
|
||||
|
||||
public ForgeConfigSpec build()
|
||||
{
|
||||
context.ensureEmpty();
|
||||
@@ -441,6 +449,10 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
|
||||
values.forEach(v -> v.spec = ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public interface BuilderConsumer {
|
||||
void accept(Builder builder);
|
||||
}
|
||||
}
|
||||
|
||||
private static class BuilderContext
|
||||
|
||||
@@ -401,7 +401,7 @@ public class ForgeHooks
|
||||
{
|
||||
boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator());
|
||||
if (isSpectator) return false;
|
||||
if (!ForgeConfig.GENERAL.fullBoundingBoxLadders.get())
|
||||
if (!ForgeConfig.SERVER.fullBoundingBoxLadders.get())
|
||||
{
|
||||
return state.getBlock().isLadder(state, world, pos, entity);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.common;
|
||||
import net.minecraftforge.fml.FMLWorldPersistenceHook;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.WorldPersistenceHooks;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent;
|
||||
@@ -91,14 +92,10 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
|
||||
MinecraftForge.EVENT_BUS.addListener(this::serverStarting);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::playerLogin);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
|
||||
/*
|
||||
FMLModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.spec);
|
||||
FMLModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ForgeConfig.chunk_spec);
|
||||
FMLModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
|
||||
FMLModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ForgeConfig.serverSpec);
|
||||
FMLModLoadingContext.get().getModEventBus().register(ForgeConfig.class);
|
||||
*/
|
||||
//Temporary, until I can talk to CPW about how certian types of config setups
|
||||
loadConfig(ForgeConfig.spec, FMLPaths.CONFIGDIR.get().resolve("forge.toml"));
|
||||
loadConfig(ForgeConfig.chunk_spec, FMLPaths.CONFIGDIR.get().resolve("forge_chunk.toml"));
|
||||
loadConfig(ForgeConfig.chunk_spec, FMLPaths.CONFIGDIR.get().resolve("forge_chunks.toml"));
|
||||
}
|
||||
|
||||
private void loadConfig(ForgeConfigSpec spec, Path path) {
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.fml;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import net.minecraftforge.versions.mcp.MCPVersion;
|
||||
@@ -131,16 +132,13 @@ public class VersionChecker
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (ForgeConfig.GENERAL.disableVersionCheck.get())
|
||||
if (!FMLConfig.runVersionCheck())
|
||||
{
|
||||
LOGGER.info("Global Forge version check system disabled, no further processing.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (IModInfo entry : gatherMods())
|
||||
{
|
||||
process(entry);
|
||||
}
|
||||
gatherMods().forEach(this::process);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,8 +86,19 @@ public class ModConfig
|
||||
|
||||
public enum Type {
|
||||
/**
|
||||
* Client type config is exclusively for configuration affecting the client state.
|
||||
* Graphical options, for example.
|
||||
* Common mod config for configuration that needs to be loaded on both environments.
|
||||
* Loaded on both servers and clients.
|
||||
* Stored in the global config directory.
|
||||
* Not synced.
|
||||
* Suffix is "-common" by default.
|
||||
*/
|
||||
COMMON,
|
||||
/**
|
||||
* Client config is for configuration affecting the ONLY client state such as graphical options.
|
||||
* Only loaded on the client side.
|
||||
* Stored in the global config directory.
|
||||
* Not synced.
|
||||
* Suffix is "-client" by default.
|
||||
*/
|
||||
CLIENT,
|
||||
// /**
|
||||
@@ -97,7 +108,10 @@ public class ModConfig
|
||||
// PLAYER,
|
||||
/**
|
||||
* Server type config is configuration that is associated with a server instance.
|
||||
* It will be synced from a server to the client on connection.
|
||||
* Only loaded during server startup.
|
||||
* Stored in a server/save specific "serverconfig" directory.
|
||||
* Synced to clients during connection.
|
||||
* Suffix is "-server" by default.
|
||||
*/
|
||||
SERVER;
|
||||
|
||||
|
||||
Reference in new issue
Block a user