diff --git a/build.gradle b/build.gradle index b60adcccc..ab4a5cdc9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' } -version = '2.1.0' +version = '2.1.5' group = 'com.aulyrius.custom_ore_gen' archivesBaseName = 'custom_ore_gen' diff --git a/src/main/java/net/mcreator/customoregen/KubeJSIntegration.java b/src/main/java/net/mcreator/customoregen/KubeJSIntegration.java new file mode 100644 index 000000000..41d1fecd4 --- /dev/null +++ b/src/main/java/net/mcreator/customoregen/KubeJSIntegration.java @@ -0,0 +1,91 @@ +package net.mcreator.customoregen; + +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.event.level.LevelEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.LogicalSide; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.storage.LevelResource; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +@Mod.EventBusSubscriber(modid = CustomOreGenMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) +public class KubeJSIntegration { + + private static final String SCRIPT_FILE_NAME = "custom_ore_gen_remove_vanilla_ores.js"; + private static boolean hasCreatedScript = false; + + @SubscribeEvent + public static void onServerLoad(LevelEvent.Load event) { + // Only run on server side and only once + if (event.getLevel().isClientSide() || hasCreatedScript) { + return; + } + + if (!(event.getLevel() instanceof ServerLevel serverLevel)) { + return; + } + + hasCreatedScript = true; + + // Get the server's kubejs directory + File kubeJsDir = new File(serverLevel.getServer().getServerDirectory(), "kubejs/startup_scripts"); + + if (!kubeJsDir.exists()) { + CustomOreGenMod.LOGGER.info("KubeJS directory not found. Skipping script creation."); + return; + } + + File scriptFile = new File(kubeJsDir, SCRIPT_FILE_NAME); + + // Only create if it doesn't exist + if (scriptFile.exists()) { + CustomOreGenMod.LOGGER.info("KubeJS script already exists: " + scriptFile.getPath()); + return; + } + + try { + createKubeJSScript(scriptFile.toPath()); + CustomOreGenMod.LOGGER.info("Successfully created KubeJS script: " + scriptFile.getPath()); + } catch (IOException e) { + CustomOreGenMod.LOGGER.error("Failed to create KubeJS script", e); + } + } + + private static void createKubeJSScript(Path scriptPath) throws IOException { + String scriptContent = """ +// priority: 0 + +WorldgenEvents.remove(event => { + var minecraftOreList = [ + 'minecraft:coal_ore', + 'minecraft:deepslate_coal_ore', + 'minecraft:copper_ore', + 'minecraft:deepslate_copper_ore', + 'minecraft:iron_ore', + 'minecraft:deepslate_iron_ore', + 'minecraft:gold_ore', + 'minecraft:deepslate_gold_ore', + 'minecraft:redstone_ore', + 'minecraft:deepslate_redstone_ore', + 'minecraft:emerald_ore', + 'minecraft:deepslate_emerald_ore', + 'minecraft:diamond_ore', + 'minecraft:deepslate_diamond_ore', + 'minecraft:lapis_ore', + 'minecraft:deepslate_lapis_ore' + ]; + + event.removeOres(props => { + props.blocks = minecraftOreList + }); +}); +"""; + + Files.writeString(scriptPath, scriptContent, StandardOpenOption.CREATE_NEW); + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index a8e82ee7e..19ebd68d5 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -4,8 +4,8 @@ license="Not specified" [[mods]] modId="custom_ore_gen" -version="2.0.8-forge" -displayName="Custom Ore Gem" +version="2.1.5-forge" +displayName="Custom Ore Gen" displayURL="https://lanro.eu" credits="Created using mod maker MCreator - https://mcreator.net/about" authors="Aulyrius cr\u00E9e via MCreator" @@ -21,7 +21,12 @@ description="Changement de la distribution des ressources sur Minecraft, ne pas ordering="AFTER" side="BOTH" - +[[dependencies.custom_ore_gen]] + modId="kubejs" + mandatory=true + versionRange="[1902.6.2-build.359,)" + ordering="AFTER" + side="BOTH" # Start of user code block dependencies configuration