From b8ef1d3d049574c74f426443ddd7e32f6e9fdff0 Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Sun, 14 Jan 2024 22:14:55 +0500 Subject: [PATCH 1/9] More balance settings --- .../twilightforest/GT_Integration_Utils.java | 119 ++++++++++++++++++ src/main/java/twilightforest/TFFeature.java | 16 ++- .../twilightforest/TwilightForestMod.java | 65 ++++++++++ .../biomes/TFBiomeDecorator.java | 17 +-- .../world/TFGenCaveStalactite.java | 51 +++++++- 5 files changed, 257 insertions(+), 11 deletions(-) create mode 100644 src/main/java/twilightforest/GT_Integration_Utils.java diff --git a/src/main/java/twilightforest/GT_Integration_Utils.java b/src/main/java/twilightforest/GT_Integration_Utils.java new file mode 100644 index 0000000000..2b8f9b5c6c --- /dev/null +++ b/src/main/java/twilightforest/GT_Integration_Utils.java @@ -0,0 +1,119 @@ +package twilightforest; + +import java.lang.reflect.Method; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +public class GT_Integration_Utils { + + /// + + static Class GT_TileEntity_OresClass; + static Method methodSetOreBlock; + // + + static boolean isFailed; + + public static void init() { + + try { + // Try GetNeededClass + extractClasses(); + + extractMhetods(); + + } catch (Exception e) { + isFailed = true; + e.printStackTrace(); + } + } + + public static boolean isIntegrationFailed() { + return isFailed; + } + + static void extractClasses() throws ClassNotFoundException { + GT_TileEntity_OresClass = Class.forName("gregtech.common.blocks.GT_TileEntity_Ores"); + } + + static void extractMhetods() throws NoSuchMethodException { + // Extract Method + + methodSetOreBlock = GT_TileEntity_OresClass.getDeclaredMethod( + "setOreBlock", + World.class, + int.class, + int.class, + int.class, + int.class, + boolean.class); + + } + + public static int getMappedGTMetaForOre(Block mOre) { + + if (mOre == Blocks.coal_ore) { + return TwilightForestMod.GT_coalOreMeta; + } + + if (mOre == Blocks.iron_ore) { + return TwilightForestMod.GT_ironOreMeta; + + } + if (mOre == Blocks.gold_ore) { + return TwilightForestMod.GT_goldOreMeta; + } + + if (mOre == Blocks.redstone_ore) { + return TwilightForestMod.GT_redstoneOreMeta; + } + + if (mOre == Blocks.lapis_ore) { + return TwilightForestMod.GT_lapisOreMeta; + } + + if (mOre == Blocks.emerald_ore) { + return TwilightForestMod.GT_emeraldOreMeta; + } + if (mOre == Blocks.diamond_ore) { + return TwilightForestMod.GT_diamondOreMeta; + } + + return -1; + } + + public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock, boolean isSmallOre) { + + if (isIntegrationFailed()) { + return false; + } + int mappedMeta = getMappedGTMetaForOre(mcOreBlock); + // Something wrong + if (mappedMeta <= 0) { + return false; + } + + return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, isSmallOre); + + } + + public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { + + if (isIntegrationFailed()) { + return false; + } + + try { + return (boolean) methodSetOreBlock.invoke(null, aWorld, aX, aY, aZ, aMetaData, isSmallOre); + + } catch (Exception e) { + e.printStackTrace(); + isFailed = true; + } + + return false; + } + +} diff --git a/src/main/java/twilightforest/TFFeature.java b/src/main/java/twilightforest/TFFeature.java index 243a2725c1..18efbb7fd1 100644 --- a/src/main/java/twilightforest/TFFeature.java +++ b/src/main/java/twilightforest/TFFeature.java @@ -378,6 +378,15 @@ public static TFFeature generateFeatureForOldMapGen(int chunkX, int chunkZ, Worl } public static TFFeature generateFeatureFor1Point7(int chunkX, int chunkZ, World world) { + + // get random value + Random hillRNG = new Random(world.getSeed() + chunkX * 25117L + chunkZ * 151121L); + + // Balance major features chance + if (!getRandom(hillRNG, TwilightForestMod.majorFeatureGenChance)) { + return nothing; + } + if (TwilightForestMod.oldMapGen) { return generateFeatureForOldMapGen(chunkX, chunkZ, world); } @@ -389,8 +398,6 @@ public static TFFeature generateFeatureFor1Point7(int chunkX, int chunkZ, World // what biome is at the center of the chunk? BiomeGenBase biomeAt = world.getBiomeGenForCoords((chunkX << 4) + 8, (chunkZ << 4) + 8); - // get random value - Random hillRNG = new Random(world.getSeed() + chunkX * 25117L + chunkZ * 151121L); int randnum = hillRNG.nextInt(16); // glaciers have ice towers @@ -547,7 +554,6 @@ public static TFFeature getFeatureForRegion(int chunkX, int chunkZ, World world) * * @param cx * @param cz - * @param seed * @return */ public static int[] getNearestCenter(int cx, int cz, World world) { @@ -895,4 +901,8 @@ public ItemStack createHintBook() { return book; } + public static boolean getRandom(Random r, double chanceMul) { + return ((r.nextDouble() * 100d) < chanceMul); + + } } diff --git a/src/main/java/twilightforest/TwilightForestMod.java b/src/main/java/twilightforest/TwilightForestMod.java index 8eefc34dc3..07d961fd8a 100644 --- a/src/main/java/twilightforest/TwilightForestMod.java +++ b/src/main/java/twilightforest/TwilightForestMod.java @@ -53,6 +53,7 @@ import twilightforest.tileentity.TileEntityTFTowerBossSpawner; import twilightforest.tileentity.TileEntityTFTowerBuilder; import twilightforest.tileentity.TileEntityTFTrophy; +import twilightforest.world.TFGenCaveStalactite; import twilightforest.world.WorldProviderTwilightForest; @Mod(modid = TwilightForestMod.ID, name = "The Twilight Forest", version = TwilightForestMod.VERSION) @@ -89,6 +90,34 @@ public class TwilightForestMod { public static float canopyCoverage; public static int twilightOakChance; + // Ore Balance + + public static double stalactiteOrePopulationDensity = 75; + public static boolean gregifyStalactiteOres; + + public static boolean diamondOreStal; + public static boolean lapisOreStal; + public static boolean emeraldOreStal; + public static boolean goldOreStal; + public static boolean redstoneOreStal; + public static boolean ironOreStal; + public static boolean coalOreStal; + public static boolean glowstoneStal; + + boolean GT_useSmallOres; + + public static int GT_diamondOreMeta; + public static int GT_lapisOreMeta; + public static int GT_emeraldOreMeta; + public static int GT_goldOreMeta; + public static int GT_redstoneOreMeta; + public static int GT_ironOreMeta; + public static int GT_coalOreMeta; + + // Major feature spawn chance + public static double majorFeatureGenChance = 100; + public static double minorFeatureGenChance = 100; + public static int idMobWildBoar; public static int idMobBighornSheep; public static int idMobWildDeer; @@ -320,6 +349,11 @@ public void postInit(FMLPostInitializationEvent evt) { FMLLog.info("[TwilightForest] Did not find Thaumcraft, did not load ThaumcraftApi integration."); } + // GT Ore + if (gregifyStalactiteOres) { + GT_Integration_Utils.init(); + } + // final check for biome ID conflicts TwilightForestMod.hasBiomeIdConflicts = TFBiomeBase.areThereBiomeIdConflicts(); } @@ -926,6 +960,37 @@ private void loadConfiguration(Configuration configFile) { "TwilightOakChance", 48).comment = "Chance that a chunk in the Twilight Forest will contain a twilight oak tree. Higher numbers reduce the number of trees, increasing performance."; + // Ore in Stalactites + // Toggle gen + + diamondOreStal = configFile.get("Stalactites", "Diamond Ore Stalactites", true).getBoolean(true); + lapisOreStal = configFile.get("Stalactites", "Lapis Ore Stalactites", true).getBoolean(true); + emeraldOreStal = configFile.get("Stalactites", "Emerald Ore Stalactites", true).getBoolean(true); + goldOreStal = configFile.get("Stalactites", "Gold Ore Stalactites", true).getBoolean(true); + redstoneOreStal = configFile.get("Stalactites", "Redstone Ore Stalactites", true).getBoolean(true); + ironOreStal = configFile.get("Stalactites", "Iron Ore Stalactites", true).getBoolean(true); + coalOreStal = configFile.get("Stalactites", "Coal Ore Stalactites", true).getBoolean(true); + glowstoneStal = configFile.get("Stalactites", "Glowstone Stalactites", true).getBoolean(true); + + // Toggle ore + TFGenCaveStalactite.configStalactites(); + + gregifyStalactiteOres = configFile.get("Stalactites", "Use Gregified ores", true).getBoolean(true); + + // GT Ore Mapping + GT_coalOreMeta = configFile.get("GT_OreMapping", "GT_coalOreMeta", 535).getInt(); + GT_lapisOreMeta = configFile.get("GT_OreMapping", "GT_lapisOreMeta", 526).getInt(); + GT_redstoneOreMeta = configFile.get("GT_OreMapping", "GT_redstoneOreMeta", 810).getInt(); + GT_emeraldOreMeta = configFile.get("GT_OreMapping", "GT_emeraldOreMeta", 501).getInt(); + GT_diamondOreMeta = configFile.get("GT_OreMapping", "GT_diamondOreMeta", 500).getInt(); + GT_ironOreMeta = configFile.get("GT_OreMapping", "GT_ironOreMeta", 32).getInt(); + GT_goldOreMeta = configFile.get("GT_OreMapping", "GT_goldOreMeta", 86).getInt(); + + // Gen chance + majorFeatureGenChance = configFile.get("WorldGen", "Major Feature Generation Chance", 100).getDouble(100); + minorFeatureGenChance = configFile.get("WorldGen", "Minor Feature Generation Chance", 100).getDouble(100); + stalactiteOrePopulationDensity = configFile.get("WorldGen", "Ore density in stalactites", 100).getDouble(100); + // fixed values, don't even read the config idMobWildBoar = 177; idMobBighornSheep = 178; diff --git a/src/main/java/twilightforest/biomes/TFBiomeDecorator.java b/src/main/java/twilightforest/biomes/TFBiomeDecorator.java index 5942e4b3fb..ccbed6de91 100644 --- a/src/main/java/twilightforest/biomes/TFBiomeDecorator.java +++ b/src/main/java/twilightforest/biomes/TFBiomeDecorator.java @@ -158,13 +158,16 @@ protected void genDecorations(BiomeGenBase biome) { } // random features! - if (randomGenerator.nextInt(6) == 0) { - int rx = chunk_X + randomGenerator.nextInt(16) + 8; - int rz = chunk_Z + randomGenerator.nextInt(16) + 8; - int ry = currentWorld.getHeightValue(rx, rz); - if (ry < 75) { - TFGenerator rf = randomFeature(randomGenerator); - rf.generate(currentWorld, randomGenerator, rx, ry, rz); + // now with chance + if (TFFeature.getRandom(randomGenerator, TwilightForestMod.minorFeatureGenChance)) { + if (randomGenerator.nextInt(6) == 0) { + int rx = chunk_X + randomGenerator.nextInt(16) + 8; + int rz = chunk_Z + randomGenerator.nextInt(16) + 8; + int ry = currentWorld.getHeightValue(rx, rz); + if (ry < 75) { + TFGenerator rf = randomFeature(randomGenerator); + rf.generate(currentWorld, randomGenerator, rx, ry, rz); + } } } diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 673845f35d..4ab1b46715 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -7,6 +7,10 @@ import net.minecraft.init.Blocks; import net.minecraft.world.World; +import twilightforest.GT_Integration_Utils; +import twilightforest.TFFeature; +import twilightforest.TwilightForestMod; + public class TFGenCaveStalactite extends TFGenerator { public static TFGenCaveStalactite diamond = new TFGenCaveStalactite(Blocks.diamond_ore, 0.5F, 4, 16); @@ -24,6 +28,9 @@ public class TFGenCaveStalactite extends TFGenerator { public int maxLength; public int minHeight; + // Greg? + public boolean doOreGen; + /** * Initializes a stalactite builder. Actually also makes stalagmites * @@ -153,6 +160,11 @@ public boolean generate(World world, Random random, int x, int y, int z) { public boolean makeSpike(World world, Random random, int x, int y, int z, int maxLength) { + // Disable ore gen + if (!doOreGen) { + blockID = Blocks.stone; + } + int diameter = (int) (maxLength / 4.5); // diameter of the base // let's see... @@ -180,7 +192,27 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma } for (int dy = 0; dy != (spikeLength * dir); dy += dir) { - setBlock(world, x + dx, y + dy, z + dz, blockID); + + // Density + if (TFFeature.getRandom(random, TwilightForestMod.stalactiteOrePopulationDensity)) { + + // Just set mcOre + if (TwilightForestMod.gregifyStalactiteOres && doOreGen) { + // Stone block before place gtOre + setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); + // Place GT ore + GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID, false); + + } else { + // Place ore/stone + setBlock(world, x + dx, y + dy, z + dz, blockID); + } + + } else { + // No ore just place stone + setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); + } + } } } @@ -188,4 +220,21 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma return true; } + public static void configStalactites() { + + diamond.setDoOreGen(TwilightForestMod.diamondOreStal); + lapis.setDoOreGen(TwilightForestMod.lapisOreStal); + emerald.setDoOreGen(TwilightForestMod.emeraldOreStal); + gold.setDoOreGen(TwilightForestMod.goldOreStal); + redstone.setDoOreGen(TwilightForestMod.redstoneOreStal); + iron.setDoOreGen(TwilightForestMod.ironOreStal); + coal.setDoOreGen(TwilightForestMod.coalOreStal); + glowstone.setDoOreGen(TwilightForestMod.glowstoneStal); + + } + + public void setDoOreGen(boolean doGenOre) { + this.doOreGen = doGenOre; + } + } From e6bffc1c76749027ed52c155803477800b38008a Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Sun, 14 Jan 2024 22:21:04 +0500 Subject: [PATCH 2/9] tweaks --- src/main/java/twilightforest/GT_Integration_Utils.java | 4 ++-- src/main/java/twilightforest/world/TFGenCaveStalactite.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/twilightforest/GT_Integration_Utils.java b/src/main/java/twilightforest/GT_Integration_Utils.java index 2b8f9b5c6c..f08930731c 100644 --- a/src/main/java/twilightforest/GT_Integration_Utils.java +++ b/src/main/java/twilightforest/GT_Integration_Utils.java @@ -84,7 +84,7 @@ public static int getMappedGTMetaForOre(Block mOre) { return -1; } - public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock, boolean isSmallOre) { + public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) { if (isIntegrationFailed()) { return false; @@ -95,7 +95,7 @@ public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcO return false; } - return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, isSmallOre); + return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, false); } diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 4ab1b46715..8cfe09a89a 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -201,7 +201,7 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma // Stone block before place gtOre setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); // Place GT ore - GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID, false); + GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID); } else { // Place ore/stone From 0af54786f109d2232173b6bf3ed7e7063ec14cf9 Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Tue, 16 Jan 2024 13:31:06 +0500 Subject: [PATCH 3/9] Small ore and growstone fix --- .../twilightforest/GT_Integration_Utils.java | 2 +- .../twilightforest/TwilightForestMod.java | 29 ++++++++++++------- .../world/TFGenCaveStalactite.java | 18 ++++++++---- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/main/java/twilightforest/GT_Integration_Utils.java b/src/main/java/twilightforest/GT_Integration_Utils.java index f08930731c..2b9319a81a 100644 --- a/src/main/java/twilightforest/GT_Integration_Utils.java +++ b/src/main/java/twilightforest/GT_Integration_Utils.java @@ -95,7 +95,7 @@ public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcO return false; } - return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, false); + return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, TwilightForestMod.GT_useSmallOres); } diff --git a/src/main/java/twilightforest/TwilightForestMod.java b/src/main/java/twilightforest/TwilightForestMod.java index 07d961fd8a..1819694590 100644 --- a/src/main/java/twilightforest/TwilightForestMod.java +++ b/src/main/java/twilightforest/TwilightForestMod.java @@ -104,7 +104,7 @@ public class TwilightForestMod { public static boolean coalOreStal; public static boolean glowstoneStal; - boolean GT_useSmallOres; + public static boolean GT_useSmallOres; public static int GT_diamondOreMeta; public static int GT_lapisOreMeta; @@ -351,7 +351,11 @@ public void postInit(FMLPostInitializationEvent evt) { // GT Ore if (gregifyStalactiteOres) { + // Doing GT_Integration_Utils.init(); + if (GT_Integration_Utils.isIntegrationFailed()) { + FMLLog.warning("[TwilightForest] Integration error with Gregtech - reflection is broken."); + } } // final check for biome ID conflicts @@ -975,16 +979,21 @@ private void loadConfiguration(Configuration configFile) { // Toggle ore TFGenCaveStalactite.configStalactites(); - gregifyStalactiteOres = configFile.get("Stalactites", "Use Gregified ores", true).getBoolean(true); + gregifyStalactiteOres = configFile.get("Stalactites", "Use Gregified ores", false).getBoolean(false); + + if (gregifyStalactiteOres) { + // GT Ore Mapping + // Show More config + GT_useSmallOres = configFile.get("GT_OreMapping", "GT_UseSmallOres", false).getBoolean(false); + GT_coalOreMeta = configFile.get("GT_OreMapping", "GT_coalOreMeta", 535).getInt(); + GT_lapisOreMeta = configFile.get("GT_OreMapping", "GT_lapisOreMeta", 526).getInt(); + GT_redstoneOreMeta = configFile.get("GT_OreMapping", "GT_redstoneOreMeta", 810).getInt(); + GT_emeraldOreMeta = configFile.get("GT_OreMapping", "GT_emeraldOreMeta", 501).getInt(); + GT_diamondOreMeta = configFile.get("GT_OreMapping", "GT_diamondOreMeta", 500).getInt(); + GT_ironOreMeta = configFile.get("GT_OreMapping", "GT_ironOreMeta", 32).getInt(); + GT_goldOreMeta = configFile.get("GT_OreMapping", "GT_goldOreMeta", 86).getInt(); - // GT Ore Mapping - GT_coalOreMeta = configFile.get("GT_OreMapping", "GT_coalOreMeta", 535).getInt(); - GT_lapisOreMeta = configFile.get("GT_OreMapping", "GT_lapisOreMeta", 526).getInt(); - GT_redstoneOreMeta = configFile.get("GT_OreMapping", "GT_redstoneOreMeta", 810).getInt(); - GT_emeraldOreMeta = configFile.get("GT_OreMapping", "GT_emeraldOreMeta", 501).getInt(); - GT_diamondOreMeta = configFile.get("GT_OreMapping", "GT_diamondOreMeta", 500).getInt(); - GT_ironOreMeta = configFile.get("GT_OreMapping", "GT_ironOreMeta", 32).getInt(); - GT_goldOreMeta = configFile.get("GT_OreMapping", "GT_goldOreMeta", 86).getInt(); + } // Gen chance majorFeatureGenChance = configFile.get("WorldGen", "Major Feature Generation Chance", 100).getDouble(100); diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 8cfe09a89a..912b9c30b7 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -197,14 +197,22 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma if (TFFeature.getRandom(random, TwilightForestMod.stalactiteOrePopulationDensity)) { // Just set mcOre - if (TwilightForestMod.gregifyStalactiteOres && doOreGen) { + if (TwilightForestMod.gregifyStalactiteOres && !GT_Integration_Utils.isIntegrationFailed() + && doOreGen) { // Stone block before place gtOre - setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); - // Place GT ore - GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID); + + // Glowstone Stalactite + if (this.blockID == Blocks.glowstone) { + setBlock(world, x + dx, y + dy, z + dz, Blocks.glowstone); + + } else { + setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); + // Slap GT ore over + GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID); + } } else { - // Place ore/stone + // Place MC Ore setBlock(world, x + dx, y + dy, z + dz, blockID); } From a099f7cc2d0af52cc2f6d03de6f611f435774779 Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Mon, 29 Jan 2024 20:35:07 +0500 Subject: [PATCH 4/9] Change to direct call --- .../twilightforest/GT_Integration_Utils.java | 73 +++---------------- .../twilightforest/TwilightForestMod.java | 9 ++- .../world/TFGenCaveStalactite.java | 3 +- 3 files changed, 17 insertions(+), 68 deletions(-) diff --git a/src/main/java/twilightforest/GT_Integration_Utils.java b/src/main/java/twilightforest/GT_Integration_Utils.java index 2b9319a81a..d762034297 100644 --- a/src/main/java/twilightforest/GT_Integration_Utils.java +++ b/src/main/java/twilightforest/GT_Integration_Utils.java @@ -1,56 +1,14 @@ package twilightforest; -import java.lang.reflect.Method; - import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; -public class GT_Integration_Utils { - - /// - - static Class GT_TileEntity_OresClass; - static Method methodSetOreBlock; - // - - static boolean isFailed; - - public static void init() { - - try { - // Try GetNeededClass - extractClasses(); +import gregtech.common.blocks.GT_TileEntity_Ores; - extractMhetods(); - - } catch (Exception e) { - isFailed = true; - e.printStackTrace(); - } - } - - public static boolean isIntegrationFailed() { - return isFailed; - } - - static void extractClasses() throws ClassNotFoundException { - GT_TileEntity_OresClass = Class.forName("gregtech.common.blocks.GT_TileEntity_Ores"); - } - - static void extractMhetods() throws NoSuchMethodException { - // Extract Method - - methodSetOreBlock = GT_TileEntity_OresClass.getDeclaredMethod( - "setOreBlock", - World.class, - int.class, - int.class, - int.class, - int.class, - boolean.class); +public class GT_Integration_Utils { - } + public static boolean isIntegrationEnabled = false; public static int getMappedGTMetaForOre(Block mOre) { @@ -86,34 +44,25 @@ public static int getMappedGTMetaForOre(Block mOre) { public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) { - if (isIntegrationFailed()) { + if (!isIntegrationEnabled) { return false; } + int mappedMeta = getMappedGTMetaForOre(mcOreBlock); // Something wrong if (mappedMeta <= 0) { return false; } - return setOreBlock(aWorld, aX, aY, aZ, mappedMeta, TwilightForestMod.GT_useSmallOres); + return GT_TileEntity_Ores.setOreBlock(aWorld, aX, aY, aZ, mappedMeta, TwilightForestMod.GT_useSmallOres, true); } - public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { - - if (isIntegrationFailed()) { - return false; - } - - try { - return (boolean) methodSetOreBlock.invoke(null, aWorld, aX, aY, aZ, aMetaData, isSmallOre); - - } catch (Exception e) { - e.printStackTrace(); - isFailed = true; - } - - return false; + public static void init() { + isIntegrationEnabled = true; } + public static boolean isInit() { + return isIntegrationEnabled; + } } diff --git a/src/main/java/twilightforest/TwilightForestMod.java b/src/main/java/twilightforest/TwilightForestMod.java index 1819694590..be42f85c88 100644 --- a/src/main/java/twilightforest/TwilightForestMod.java +++ b/src/main/java/twilightforest/TwilightForestMod.java @@ -350,12 +350,13 @@ public void postInit(FMLPostInitializationEvent evt) { } // GT Ore - if (gregifyStalactiteOres) { + if (Loader.isModLoaded("gregtech") && gregifyStalactiteOres) { // Doing GT_Integration_Utils.init(); - if (GT_Integration_Utils.isIntegrationFailed()) { - FMLLog.warning("[TwilightForest] Integration error with Gregtech - reflection is broken."); - } + } else { + FMLLog.warning("[TwilightForest] Did not load Gregtech integration."); + // Disable + gregifyStalactiteOres = false; } // final check for biome ID conflicts diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 912b9c30b7..4c7b0e05c4 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -197,8 +197,7 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma if (TFFeature.getRandom(random, TwilightForestMod.stalactiteOrePopulationDensity)) { // Just set mcOre - if (TwilightForestMod.gregifyStalactiteOres && !GT_Integration_Utils.isIntegrationFailed() - && doOreGen) { + if (TwilightForestMod.gregifyStalactiteOres && doOreGen) { // Stone block before place gtOre // Glowstone Stalactite From 0b62035084f2c69a313ba18e213361035e2602c9 Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Mon, 29 Jan 2024 20:45:18 +0500 Subject: [PATCH 5/9] Deps and BS --- build.gradle | 29 ++++++++++++++++++++++++----- dependencies.gradle | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 952a3c59be..6274cb255e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1704650211 +//version: 1705357285 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -122,6 +122,7 @@ propertyDefaultIfUnset("modrinthProjectId", "") propertyDefaultIfUnset("modrinthRelations", "") propertyDefaultIfUnset("curseForgeProjectId", "") propertyDefaultIfUnset("curseForgeRelations", "") +propertyDefaultIfUnset("versionPattern", "") propertyDefaultIfUnset("minimizeShadowedDependencies", true) propertyDefaultIfUnset("relocateShadowedDependencies", true) // Deprecated properties (kept for backwards compat) @@ -370,6 +371,7 @@ catch (Exception ignored) { // Pulls version first from the VERSION env and then git tag String identifiedVersion String versionOverride = System.getenv("VERSION") ?: null +boolean checkVersion = false try { // Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty if (versionOverride == null) { @@ -388,6 +390,8 @@ try { } } else if (isDirty) { identifiedVersion += "-${branchName}+${gitDetails.gitHash}-dirty" + } else { + checkVersion = true } } else { identifiedVersion = versionOverride @@ -409,6 +413,8 @@ ext { if (identifiedVersion == versionOverride) { out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7') +} else if (checkVersion && versionPattern && !(identifiedVersion ==~ versionPattern)) { + throw new GradleException("Invalid version: '$identifiedVersion' does not match version pattern '$versionPattern'") } group = "com.github.GTNewHorizons" @@ -428,18 +434,31 @@ minecraft { for (f in replaceGradleTokenInFile.split(',')) { tagReplacementFiles.add f } + out.style(Style.Info).text('replaceGradleTokenInFile is deprecated! Consider using generateGradleTokenClass.').println() } if (gradleTokenModId) { - injectedTags.put gradleTokenModId, modId + if (replaceGradleTokenInFile) { + injectedTags.put gradleTokenModId, modId + } else { + out.style(Style.Failure).text('gradleTokenModId is deprecated! The field will no longer be generated.').println() + } } if (gradleTokenModName) { - injectedTags.put gradleTokenModName, modName + if (replaceGradleTokenInFile) { + injectedTags.put gradleTokenModName, modName + } else { + out.style(Style.Failure).text('gradleTokenModName is deprecated! The field will no longer be generated.').println() + } } if (gradleTokenVersion) { injectedTags.put gradleTokenVersion, modVersion } if (gradleTokenGroupName) { - injectedTags.put gradleTokenGroupName, modGroup + if (replaceGradleTokenInFile) { + injectedTags.put gradleTokenGroupName, modGroup + } else { + out.style(Style.Failure).text('gradleTokenGroupName is deprecated! The field will no longer be generated.').println() + } } if (enableGenericInjection.toBoolean()) { injectMissingGenerics.set(true) @@ -786,7 +805,7 @@ dependencies { java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}") } if (modId != 'hodgepodge') { - java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.35') + java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.4.4') } java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false} diff --git a/dependencies.gradle b/dependencies.gradle index 61b165cb48..3a00051f9a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false} - + api("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.53:dev") // For Thaumcraft runtime //runtimeOnlyNonPublishable("com.github.GTNewHorizons:Baubles:1.0.1.16:dev") } From 60cce95deabc87c9691c3f0789420b3390f76b0a Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Tue, 30 Jan 2024 15:56:03 +0500 Subject: [PATCH 6/9] code reorganization --- .gitignore | 3 +- .../twilightforest/TwilightForestMod.java | 1 + .../gt_integration/GT_Integration_Utils.java | 31 +++++++++++++++++++ .../GT_OrePlacer.java} | 24 +++----------- .../world/TFGenCaveStalactite.java | 5 +-- 5 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java rename src/main/java/twilightforest/{GT_Integration_Utils.java => gt_integration/GT_OrePlacer.java} (69%) diff --git a/.gitignore b/.gitignore index 27a8ae0f17..7a8ac8df91 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ addon.local.gradle addon.local.gradle.kts addon.late.local.gradle addon.late.local.gradle.kts -layout.json \ No newline at end of file +layout.json +dependencies.gradle diff --git a/src/main/java/twilightforest/TwilightForestMod.java b/src/main/java/twilightforest/TwilightForestMod.java index be42f85c88..5186daed08 100644 --- a/src/main/java/twilightforest/TwilightForestMod.java +++ b/src/main/java/twilightforest/TwilightForestMod.java @@ -28,6 +28,7 @@ import twilightforest.biomes.TFBiomeBase; import twilightforest.block.TFBlocks; import twilightforest.entity.TFCreatures; +import twilightforest.gt_integration.GT_Integration_Utils; import twilightforest.item.BehaviorTFMobEggDispense; import twilightforest.item.ItemTFMagicMap; import twilightforest.item.ItemTFMazeMap; diff --git a/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java b/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java new file mode 100644 index 0000000000..8179e0b6b0 --- /dev/null +++ b/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java @@ -0,0 +1,31 @@ +package twilightforest.gt_integration; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public class GT_Integration_Utils { + + static GT_OrePlacer orePlacer; + + public static void init() { + // Create worker obj + orePlacer = new GT_OrePlacer(); + + } + + public static boolean isInit() { + return orePlacer != null; + } + + public static boolean doPlaceGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) { + if (!isInit()) { + return false; + } + return orePlacer.placeGTOre(aWorld, aX, aY, aZ, mcOreBlock); + } + + public static GT_OrePlacer getOrePlacer() { + return orePlacer; + } + +} diff --git a/src/main/java/twilightforest/GT_Integration_Utils.java b/src/main/java/twilightforest/gt_integration/GT_OrePlacer.java similarity index 69% rename from src/main/java/twilightforest/GT_Integration_Utils.java rename to src/main/java/twilightforest/gt_integration/GT_OrePlacer.java index d762034297..e83e926cdd 100644 --- a/src/main/java/twilightforest/GT_Integration_Utils.java +++ b/src/main/java/twilightforest/gt_integration/GT_OrePlacer.java @@ -1,16 +1,15 @@ -package twilightforest; +package twilightforest.gt_integration; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import gregtech.common.blocks.GT_TileEntity_Ores; +import twilightforest.TwilightForestMod; -public class GT_Integration_Utils { +public class GT_OrePlacer { - public static boolean isIntegrationEnabled = false; - - public static int getMappedGTMetaForOre(Block mOre) { + public int getMappedGTMetaForOre(Block mOre) { if (mOre == Blocks.coal_ore) { return TwilightForestMod.GT_coalOreMeta; @@ -42,27 +41,14 @@ public static int getMappedGTMetaForOre(Block mOre) { return -1; } - public static boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) { - - if (!isIntegrationEnabled) { - return false; - } + public boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) { int mappedMeta = getMappedGTMetaForOre(mcOreBlock); - // Something wrong if (mappedMeta <= 0) { return false; } - return GT_TileEntity_Ores.setOreBlock(aWorld, aX, aY, aZ, mappedMeta, TwilightForestMod.GT_useSmallOres, true); } - public static void init() { - isIntegrationEnabled = true; - } - - public static boolean isInit() { - return isIntegrationEnabled; - } } diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 4c7b0e05c4..4bfebbe2fc 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -7,9 +7,9 @@ import net.minecraft.init.Blocks; import net.minecraft.world.World; -import twilightforest.GT_Integration_Utils; import twilightforest.TFFeature; import twilightforest.TwilightForestMod; +import twilightforest.gt_integration.GT_Integration_Utils; public class TFGenCaveStalactite extends TFGenerator { @@ -207,7 +207,8 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma } else { setBlock(world, x + dx, y + dy, z + dz, Blocks.stone); // Slap GT ore over - GT_Integration_Utils.placeGTOre(world, x + dx, y + dy, z + dz, blockID); + GT_Integration_Utils.doPlaceGTOre(world, x + dx, y + dy, z + dz, blockID); + } } else { From 11d94a23485ca1adf55292b8518a54852551493a Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Tue, 30 Jan 2024 15:56:16 +0500 Subject: [PATCH 7/9] compileOnly --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index 3a00051f9a..22d57b4b15 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false} - api("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.53:dev") + compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.53:dev") // For Thaumcraft runtime //runtimeOnlyNonPublishable("com.github.GTNewHorizons:Baubles:1.0.1.16:dev") } From 5dd9b5b3cb003ec642aea0a69ca3484a458bd3c3 Mon Sep 17 00:00:00 2001 From: Minepolz320 <42765118+Minepolz320@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:01:46 +0500 Subject: [PATCH 8/9] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7a8ac8df91..5e80e0ae57 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,3 @@ addon.local.gradle.kts addon.late.local.gradle addon.late.local.gradle.kts layout.json -dependencies.gradle From c4c3d009102214ec44a9e0524d3a6cec2056a59f Mon Sep 17 00:00:00 2001 From: Minepolz320 Date: Sun, 4 Feb 2024 16:21:45 +0500 Subject: [PATCH 9/9] Rev Code rework --- src/main/java/twilightforest/TFFeature.java | 5 ++++- .../java/twilightforest/TwilightForestMod.java | 11 ++++++++--- .../twilightforest/biomes/TFBiomeDecorator.java | 15 +++++++-------- .../gt_integration/GT_Integration_Utils.java | 6 +----- .../twilightforest/world/TFGenCaveStalactite.java | 1 - 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/twilightforest/TFFeature.java b/src/main/java/twilightforest/TFFeature.java index 18efbb7fd1..c3e6ce2143 100644 --- a/src/main/java/twilightforest/TFFeature.java +++ b/src/main/java/twilightforest/TFFeature.java @@ -382,7 +382,10 @@ public static TFFeature generateFeatureFor1Point7(int chunkX, int chunkZ, World // get random value Random hillRNG = new Random(world.getSeed() + chunkX * 25117L + chunkZ * 151121L); - // Balance major features chance + // Modify major features (Bosses) generation rate + // 100% = default + // 50% = only 50% generation chance from default chance + if (!getRandom(hillRNG, TwilightForestMod.majorFeatureGenChance)) { return nothing; } diff --git a/src/main/java/twilightforest/TwilightForestMod.java b/src/main/java/twilightforest/TwilightForestMod.java index 5186daed08..0f7a5517bd 100644 --- a/src/main/java/twilightforest/TwilightForestMod.java +++ b/src/main/java/twilightforest/TwilightForestMod.java @@ -9,6 +9,7 @@ import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; @@ -117,7 +118,7 @@ public class TwilightForestMod { // Major feature spawn chance public static double majorFeatureGenChance = 100; - public static double minorFeatureGenChance = 100; + public static double minorFeatureGenChance = 14; public static int idMobWildBoar; public static int idMobBighornSheep; @@ -998,8 +999,12 @@ private void loadConfiguration(Configuration configFile) { } // Gen chance - majorFeatureGenChance = configFile.get("WorldGen", "Major Feature Generation Chance", 100).getDouble(100); - minorFeatureGenChance = configFile.get("WorldGen", "Minor Feature Generation Chance", 100).getDouble(100); + Property majorGenChance = configFile.get("WorldGen", "Major Feature Generation Chance", 100); + majorGenChance.comment = "IT IS NOT RECOMMENDED TO CHANGE ON AN ALREADY CREATED WORLD! Since old dungeons can change/don't showing the icon on the magic map or will not be generated completely"; + majorFeatureGenChance = majorGenChance.getDouble(); + + minorFeatureGenChance = configFile.get("WorldGen", "Minor Feature Generation Chance", 14).getDouble(14); + stalactiteOrePopulationDensity = configFile.get("WorldGen", "Ore density in stalactites", 100).getDouble(100); // fixed values, don't even read the config diff --git a/src/main/java/twilightforest/biomes/TFBiomeDecorator.java b/src/main/java/twilightforest/biomes/TFBiomeDecorator.java index ccbed6de91..336ed355af 100644 --- a/src/main/java/twilightforest/biomes/TFBiomeDecorator.java +++ b/src/main/java/twilightforest/biomes/TFBiomeDecorator.java @@ -160,15 +160,14 @@ protected void genDecorations(BiomeGenBase biome) { // random features! // now with chance if (TFFeature.getRandom(randomGenerator, TwilightForestMod.minorFeatureGenChance)) { - if (randomGenerator.nextInt(6) == 0) { - int rx = chunk_X + randomGenerator.nextInt(16) + 8; - int rz = chunk_Z + randomGenerator.nextInt(16) + 8; - int ry = currentWorld.getHeightValue(rx, rz); - if (ry < 75) { - TFGenerator rf = randomFeature(randomGenerator); - rf.generate(currentWorld, randomGenerator, rx, ry, rz); - } + int rx = chunk_X + randomGenerator.nextInt(16) + 8; + int rz = chunk_Z + randomGenerator.nextInt(16) + 8; + int ry = currentWorld.getHeightValue(rx, rz); + if (ry < 75) { + TFGenerator rf = randomFeature(randomGenerator); + rf.generate(currentWorld, randomGenerator, rx, ry, rz); } + } // add canopy trees diff --git a/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java b/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java index 8179e0b6b0..527564c0a5 100644 --- a/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java +++ b/src/main/java/twilightforest/gt_integration/GT_Integration_Utils.java @@ -5,7 +5,7 @@ public class GT_Integration_Utils { - static GT_OrePlacer orePlacer; + private static GT_OrePlacer orePlacer; public static void init() { // Create worker obj @@ -24,8 +24,4 @@ public static boolean doPlaceGTOre(World aWorld, int aX, int aY, int aZ, Block m return orePlacer.placeGTOre(aWorld, aX, aY, aZ, mcOreBlock); } - public static GT_OrePlacer getOrePlacer() { - return orePlacer; - } - } diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 4bfebbe2fc..47317b6360 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -28,7 +28,6 @@ public class TFGenCaveStalactite extends TFGenerator { public int maxLength; public int minHeight; - // Greg? public boolean doOreGen; /**