Skip to content

Commit

Permalink
Bump min neo version to 21.0.86-beta and adjust for changes to config…
Browse files Browse the repository at this point in the history
… system internals
  • Loading branch information
pupnewfster committed Jul 11, 2024
1 parent 23b7a68 commit 710f051
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 178 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ dependencies {
localRuntime(emi)
} else {
//We still need it to load in datagen regardless of if we are using emi or a different viewer so that we can access EMI related objects
datagenMainRuntimeOnly(emi)
//TODO - 1.21: Make a PR to EMI to bootstrap in datagen, and more importantly be able to somehow provide the registry access context
// rather than it trying to grab it from Minecraft.getInstance().level as Minecraft.getInstance() is null in datagen
// As https://github.com/emilyploszaj/emi/pull/600 broke it
//datagenMainRuntimeOnly(emi)
}

//TODO: Re-enable once it doesn't cause Datagen to fail
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ minecraft_version=1.21
previous_minecraft_version=1.20.4
previous_minor_minecraft_version=1.20.6
loader_version_range=[4,)
forge_version=21.0.78-beta
forge_version=21.0.86-beta
mod_version=10.6.4
#This determines the minimum version of forge required to use Mekanism
# Only bump it whenever we need access to a feature in forge that is not available in earlier versions
forge_version_range=[21.0.58-beta,)
forge_version_range=[21.0.86-beta,)
minecraft_version_range=[1.21]
#This specifies what type of release it will be uploaded to CurseForge and Modrinth as
# options are: alpha, beta, release
Expand All @@ -37,14 +37,14 @@ yamlops_version=1.2.0

#Mod dependencies
cc_tweaked_version=1.111.0
crafttweaker_version=20.0.15
crafttweaker_version=20.0.17
ctm_version=1.2.0+1
curios_version=9.0.4+1.21
emi_version=1.1.10
grand_power_version=3.0.0
jade_api_id=5427895
jade_id=5493270
jei_version=19.1.1.19
jei_version=19.5.0.30
json_things_version=0.12.0
top_version=1.21_neo-12.0.0-1
wthit_version=12.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import mekanism.additions.common.voice.VoiceServerManager;
import mekanism.common.Mekanism;
import mekanism.common.base.IModModule;
import mekanism.common.config.MekanismModConfig;
import mekanism.common.lib.Version;
import mekanism.common.registration.impl.ItemRegistryObject;
import net.minecraft.core.BlockPos;
Expand All @@ -32,8 +31,6 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
Expand Down Expand Up @@ -67,7 +64,7 @@ public MekanismAdditions(ModContainer modContainer, IEventBus modEventBus) {
NeoForge.EVENT_BUS.addListener(this::serverStopping);

modEventBus.addListener(this::commonSetup);
modEventBus.addListener(this::onConfigLoad);
modEventBus.addListener(MekanismAdditionsConfig::onConfigLoad);
AdditionsDataComponents.DATA_COMPONENTS.register(modEventBus);
AdditionsItems.ITEMS.register(modEventBus);
AdditionsBlocks.BLOCKS.register(modEventBus);
Expand Down Expand Up @@ -158,12 +155,4 @@ private void serverStopping(ServerStoppingEvent event) {
voiceManager = null;
}
}

private void onConfigLoad(ModConfigEvent configEvent) {
ModConfig config = configEvent.getConfig();
//Make sure it is for the same modid as us
if (config.getModId().equals(MODID) && config instanceof MekanismModConfig mekConfig) {
mekConfig.clearCache(configEvent);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package mekanism.additions.common.config;

import java.util.HashMap;
import java.util.Map;
import mekanism.additions.common.MekanismAdditions;
import mekanism.common.config.IMekanismConfig;
import mekanism.common.config.MekanismConfigHelper;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.event.config.ModConfigEvent;

public class MekanismAdditionsConfig {

private MekanismAdditionsConfig() {
}

private static final Map<IConfigSpec, IMekanismConfig> KNOWN_CONFIGS = new HashMap<>();
public static final AdditionsConfig additions = new AdditionsConfig();
public static final AdditionsClientConfig client = new AdditionsClientConfig();

public static void registerConfigs(ModContainer modContainer) {
MekanismConfigHelper.registerConfig(modContainer, client);
MekanismConfigHelper.registerConfig(modContainer, additions);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, client);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, additions);
}

public static void onConfigLoad(ModConfigEvent configEvent) {
MekanismConfigHelper.onConfigLoad(configEvent, MekanismAdditions.MODID, KNOWN_CONFIGS);
}
}
40 changes: 37 additions & 3 deletions src/datagen/main/java/mekanism/common/MekanismDataGenerator.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package mekanism.common;

import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.InMemoryCommentedFormat;
import com.electronwill.nightconfig.core.concurrent.SynchronizedConfig;
import com.google.common.hash.Hashing;
import com.google.common.hash.HashingOutputStream;
import com.google.gson.JsonElement;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import mekanism.client.lang.MekanismLangProvider;
import mekanism.client.model.MekanismItemModelProvider;
import mekanism.client.sound.MekanismSoundProvider;
Expand All @@ -18,6 +25,7 @@
import mekanism.client.texture.PrideRobitTextureProvider;
import mekanism.common.advancements.MekanismAdvancementProvider;
import mekanism.common.integration.computer.ComputerHelpProvider;
import mekanism.common.lib.FieldReflectionHelper;
import mekanism.common.loot.MekanismLootProvider;
import mekanism.common.recipe.impl.MekanismRecipeProvider;
import mekanism.common.registries.MekanismDatapackRegistryProvider;
Expand All @@ -32,12 +40,32 @@
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.config.ConfigTracker;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.data.event.GatherDataEvent;

@EventBusSubscriber(modid = Mekanism.MODID, bus = EventBusSubscriber.Bus.MOD)
public class MekanismDataGenerator {

@SuppressWarnings("UnstableApiUsage")
private static final FieldReflectionHelper<ConfigTracker, EnumMap<ModConfig.Type, Set<ModConfig>>> CONFIG_SETS =
new FieldReflectionHelper<>(ConfigTracker.class, "configSets", () -> new EnumMap<>(ModConfig.Type.class));
private static final Constructor<?> LOADED_CONFIG;
private static final Method SET_CONFIG;

static {
Class<?> loadedConfig;
try {
loadedConfig = Class.forName("net.neoforged.fml.config.LoadedConfig");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
LOADED_CONFIG = ObfuscationReflectionHelper.findConstructor(loadedConfig, CommentedConfig.class, Path.class, ModConfig.class);
SET_CONFIG = ObfuscationReflectionHelper.findMethod(ModConfig.class, "setConfig", loadedConfig, Function.class);
}


private MekanismDataGenerator() {
}

Expand Down Expand Up @@ -75,17 +103,23 @@ public static void gatherData(GatherDataEvent event) {
* Used to bootstrap configs to their default values so that if we are querying if things exist we don't have issues with it happening to early or in cases we have
* fake tiles.
*/
@SuppressWarnings("UnstableApiUsage")
public static void bootstrapConfigs(String modid) {
for (Set<ModConfig> configs : ConfigTracker.INSTANCE.configSets().values()) {
for (Set<ModConfig> configs : CONFIG_SETS.getValue(ConfigTracker.INSTANCE).values()) {
for (ModConfig config : configs) {
if (config.getModId().equals(modid)) {
//Similar to how ConfigTracker#loadDefaultServerConfigs works for loading default server configs on the client
// except we don't bother firing an event as it is private, and we are already at defaults if we had called earlier,
// and we also don't fully initialize the mod config as the spec is what we care about, and we can do so without having
// to reflect into package private methods
CommentedConfig commentedConfig = CommentedConfig.inMemory();
CommentedConfig commentedConfig = new SynchronizedConfig(InMemoryCommentedFormat.defaultInstance(), LinkedHashMap::new);
config.getSpec().correct(commentedConfig);
config.getSpec().acceptConfig(commentedConfig);
try {
SET_CONFIG.invoke(config, LOADED_CONFIG.newInstance(commentedConfig, null, config),
(Function<ModConfig, ModConfigEvent>) ModConfigEvent.Loading::new);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
}
Expand Down
15 changes: 1 addition & 14 deletions src/defense/java/mekanism/defense/common/MekanismDefense.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import mekanism.common.Mekanism;
import mekanism.common.base.IModModule;
import mekanism.common.config.MekanismModConfig;
import mekanism.common.lib.Version;
import mekanism.defense.common.config.MekanismDefenseConfig;
import mekanism.defense.common.registries.DefenseBlocks;
Expand All @@ -14,8 +13,6 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
Expand All @@ -40,7 +37,7 @@ public MekanismDefense(ModContainer modContainer, IEventBus modEventBus) {
NeoForge.EVENT_BUS.addListener(this::serverStopped);

modEventBus.addListener(this::commonSetup);
modEventBus.addListener(this::onConfigLoad);
modEventBus.addListener(MekanismDefenseConfig::onConfigLoad);
DefenseItems.ITEMS.register(modEventBus);
DefenseBlocks.BLOCKS.register(modEventBus);
DefenseCreativeTabs.CREATIVE_TABS.register(modEventBus);
Expand Down Expand Up @@ -73,14 +70,4 @@ public String getName() {
@Override
public void resetClient() {
}

private void onConfigLoad(ModConfigEvent configEvent) {
//Note: We listen to both the initial load and the reload, to make sure that we fix any accidentally
// cached values from calls before the initial loading
ModConfig config = configEvent.getConfig();
//Make sure it is for the same modid as us
if (config.getModId().equals(MODID) && config instanceof MekanismModConfig mekConfig) {
mekConfig.clearCache(configEvent);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package mekanism.defense.common.config;

import java.util.HashMap;
import java.util.Map;
import mekanism.common.config.IMekanismConfig;
import mekanism.common.config.MekanismConfigHelper;
import mekanism.defense.common.MekanismDefense;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.event.config.ModConfigEvent;

public class MekanismDefenseConfig {

private MekanismDefenseConfig() {
}

private static final Map<IConfigSpec, IMekanismConfig> KNOWN_CONFIGS = new HashMap<>();
public static final DefenseConfig defense = new DefenseConfig();

public static void registerConfigs(ModContainer modContainer) {
MekanismConfigHelper.registerConfig(modContainer, defense);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, defense);
}

public static void onConfigLoad(ModConfigEvent configEvent) {
MekanismConfigHelper.onConfigLoad(configEvent, MekanismDefense.MODID, KNOWN_CONFIGS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import mekanism.common.base.IModModule;
import mekanism.common.command.builders.BuildCommand;
import mekanism.common.config.MekanismConfig;
import mekanism.common.config.MekanismModConfig;
import mekanism.common.config.listener.ConfigBasedCachedFLSupplier;
import mekanism.common.lib.Version;
import mekanism.common.lib.multiblock.MultiblockManager;
Expand Down Expand Up @@ -41,8 +40,6 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent;

Expand Down Expand Up @@ -77,7 +74,7 @@ public MekanismGenerators(ModContainer modContainer, IEventBus modEventBus) {
versionNumber = new Version(modContainer);
MekanismGeneratorsConfig.registerConfigs(modContainer);
modEventBus.addListener(this::commonSetup);
modEventBus.addListener(this::onConfigLoad);
modEventBus.addListener(MekanismGeneratorsConfig::onConfigLoad);
modEventBus.addListener(this::imcQueue);

GeneratorsDataComponents.DATA_COMPONENTS.register(modEventBus);
Expand Down Expand Up @@ -138,14 +135,4 @@ public String getName() {
public void resetClient() {
TurbineMultiblockData.clientRotationMap.clear();
}

private void onConfigLoad(ModConfigEvent configEvent) {
//Note: We listen to both the initial load and the reload, to make sure that we fix any accidentally
// cached values from calls before the initial loading
ModConfig config = configEvent.getConfig();
//Make sure it is for the same modid as us
if (config.getModId().equals(MODID) && config instanceof MekanismModConfig mekConfig) {
mekConfig.clearCache(configEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class GeneratorsConfig extends BaseMekanismConfig {
heatTankCapacity = CachedIntValue.wrap(this, builder.comment("The capacity in mB of the fluid tank in the Heat Generator.")
.defineInRange("tankCapacity", 24 * FluidType.BUCKET_VOLUME, 1, Integer.MAX_VALUE));
heatGenerationFluidRate = CachedIntValue.wrap(this, builder.comment("The amount of lava in mB that gets consumed to transfer heatGeneration Joules to the Heat Generator.")
.define("heatGenerationFluidRate", 10, value -> value instanceof Integer i && i > 0 && i <= heatTankCapacity.get()));
.define("heatGenerationFluidRate", 10, value -> value instanceof Integer i && i > 0 && i <= heatTankCapacity.getOrDefault()));
builder.pop();

builder.comment("Gas-Burning Generator Settings").push(GAS_CATEGORY);
Expand Down Expand Up @@ -155,7 +155,7 @@ public class GeneratorsConfig extends BaseMekanismConfig {
//Note: We just require that the maxY is greater than the minY, nothing goes badly if it is set above the max y of the world though
// as it is just used for range clamping
windGenerationMaxY = CachedIntValue.wrap(this, builder.comment("The maximum Y value that affects the Wind Generators Power generation. This value gets clamped at the world's logical height.")
.define("maxY", DimensionType.MAX_Y, value -> value instanceof Integer && (Integer) value > windGenerationMinY.get()));
.define("maxY", DimensionType.MAX_Y, value -> value instanceof Integer && (Integer) value > windGenerationMinY.getOrDefault()));
//Note: We cannot verify the dimension exists as dimensions are dynamic so may not actually exist when we are validating
windGenerationDimBlacklist = CachedResourceLocationListValue.define(this, builder.comment("The list of dimension ids that the Wind Generator will not generate power in."),
"windGenerationDimBlacklist", ConstantPredicates.alwaysTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,4 @@ public ModConfigSpec getConfigSpec() {
public Type getConfigType() {
return Type.SERVER;
}

@Override
public boolean addToContainer() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ public ModConfigSpec getConfigSpec() {
public Type getConfigType() {
return Type.SERVER;
}

@Override
public boolean addToContainer() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package mekanism.generators.common.config;

import java.util.HashMap;
import java.util.Map;
import mekanism.common.config.IMekanismConfig;
import mekanism.common.config.MekanismConfigHelper;
import mekanism.generators.common.MekanismGenerators;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.event.config.ModConfigEvent;

public class MekanismGeneratorsConfig {

private MekanismGeneratorsConfig() {
}

private static final Map<IConfigSpec, IMekanismConfig> KNOWN_CONFIGS = new HashMap<>();
public static final GeneratorsConfig generators = new GeneratorsConfig();
public static final GeneratorsGearConfig gear = new GeneratorsGearConfig();
public static final GeneratorsStorageConfig storageConfig = new GeneratorsStorageConfig();

public static void registerConfigs(ModContainer modContainer) {
MekanismConfigHelper.registerConfig(modContainer, generators);
MekanismConfigHelper.registerConfig(modContainer, gear);
MekanismConfigHelper.registerConfig(modContainer, storageConfig);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, generators);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, gear);
MekanismConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, storageConfig);
}

public static void onConfigLoad(ModConfigEvent configEvent) {
MekanismConfigHelper.onConfigLoad(configEvent, MekanismGenerators.MODID, KNOWN_CONFIGS);
}
}
Loading

0 comments on commit 710f051

Please sign in to comment.