From edbc062da06a955dbcf0a7df058f02ccb6102991 Mon Sep 17 00:00:00 2001 From: George Paton Date: Tue, 7 Oct 2025 12:56:14 +1100 Subject: [PATCH] reimplement oil (regular + sand) bubbles as MapGenBase --- src/main/java/com/hbm/lib/HbmWorld.java | 24 +++++- src/main/java/com/hbm/lib/HbmWorldGen.java | 40 ---------- .../java/com/hbm/world/feature/OilBubble.java | 33 -------- .../com/hbm/world/feature/OilSandBubble.java | 37 --------- .../hbm/world/gen/terrain/MapGenBubble.java | 79 +++++++++++++++++++ .../world/gen/{ => terrain}/MapGenCrater.java | 2 +- 6 files changed, 103 insertions(+), 112 deletions(-) delete mode 100644 src/main/java/com/hbm/world/feature/OilBubble.java delete mode 100644 src/main/java/com/hbm/world/feature/OilSandBubble.java create mode 100644 src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java rename src/main/java/com/hbm/world/gen/{ => terrain}/MapGenCrater.java (98%) diff --git a/src/main/java/com/hbm/lib/HbmWorld.java b/src/main/java/com/hbm/lib/HbmWorld.java index ca4732b70..b8d60ca8a 100644 --- a/src/main/java/com/hbm/lib/HbmWorld.java +++ b/src/main/java/com/hbm/lib/HbmWorld.java @@ -1,7 +1,6 @@ package com.hbm.lib; import com.hbm.world.gen.MapGenChainloader.MapGenEventHandler; -import com.hbm.world.gen.MapGenCrater; import com.hbm.blocks.ModBlocks; import com.hbm.config.GeneralConfig; import com.hbm.config.WorldConfig; @@ -11,9 +10,12 @@ import com.hbm.world.gen.NTMWorldGenerator; import com.hbm.world.gen.component.*; import com.hbm.world.gen.component.BunkerComponents.BunkerStart; import com.hbm.world.gen.nbt.NBTStructure; +import com.hbm.world.gen.terrain.MapGenBubble; +import com.hbm.world.gen.terrain.MapGenCrater; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.init.Blocks; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.structure.MapGenStructureIO; import net.minecraftforge.common.MinecraftForge; @@ -64,6 +66,26 @@ public class HbmWorld { sellafieldCrater.targetBiome = BiomeGenBase.desert; MapGenChainloader.addOverworldGenerator(sellafieldCrater); } + + if(WorldConfig.oilSpawn > 0) { + MapGenBubble oilBubble = new MapGenBubble(WorldConfig.oilSpawn); + oilBubble.block = ModBlocks.ore_oil; + oilBubble.setSize(8, 16); + MapGenChainloader.addOverworldGenerator(oilBubble); + } + + int sandBubbleSpawn = 200; + if(sandBubbleSpawn > 0) { + MapGenBubble sandOilBubble = new MapGenBubble(sandBubbleSpawn); + sandOilBubble.replace = Blocks.sand; + sandOilBubble.block = ModBlocks.ore_oil_sand; + sandOilBubble.canSpawn = biome -> !biome.canSpawnLightningBolt() && biome.temperature >= 1.5F; + sandOilBubble.minY = 56; + sandOilBubble.rangeY = 16; + sandOilBubble.setSize(16, 48); + sandOilBubble.fuzzy = true; + MapGenChainloader.addOverworldGenerator(sandOilBubble); + } } } diff --git a/src/main/java/com/hbm/lib/HbmWorldGen.java b/src/main/java/com/hbm/lib/HbmWorldGen.java index 6d004cbf9..8fec93b01 100644 --- a/src/main/java/com/hbm/lib/HbmWorldGen.java +++ b/src/main/java/com/hbm/lib/HbmWorldGen.java @@ -223,18 +223,6 @@ public class HbmWorldGen implements IWorldGenerator { } } -// if(biome == BiomeGenBase.plains || biome == BiomeGenBase.desert) { -// if(WorldConfig.radioStructure > 0 && rand.nextInt(WorldConfig.radioStructure) == 0) { -// for(int a = 0; a < 1; a++) { -// int x = i + rand.nextInt(16); -// int z = j + rand.nextInt(16); -// int y = world.getHeightValue(x, z); -// -// new Radio01().generate(world, rand, x, y, z); -// } -// } -// } - if(biome.temperature >= 0.4F && biome.rainfall <= 0.6F) { if(WorldConfig.antennaStructure > 0 && rand.nextInt(WorldConfig.antennaStructure) == 0) { for(int a = 0; a < 1; a++) { @@ -278,26 +266,6 @@ public class HbmWorldGen implements IWorldGenerator { } } - if(!biome.canSpawnLightningBolt() && biome.temperature >= 1.5F) { - if(rand.nextInt(200) == 0) { - for(int a = 0; a < 1; a++) { - int x = i + rand.nextInt(16); - int z = j + rand.nextInt(16); - int y = world.getHeightValue(x, z); - - OilSandBubble.spawnOil(world, x, y, z, 15 + rand.nextInt(31)); - } - } - } - -// if(WorldConfig.factoryStructure > 0 && rand.nextInt(WorldConfig.factoryStructure) == 0) { -// int x = i + rand.nextInt(16); -// int z = j + rand.nextInt(16); -// int y = world.getHeightValue(x, z); -// -// new Factory().generate(world, rand, x, y, z); -// } - if(WorldConfig.dudStructure > 0 && rand.nextInt(WorldConfig.dudStructure) == 0) { int x = i + 8 + rand.nextInt(16); int z = j + 8 + rand.nextInt(16); @@ -527,14 +495,6 @@ public class HbmWorldGen implements IWorldGenerator { } } - if(WorldConfig.oilSpawn > 0 && rand.nextInt(WorldConfig.oilSpawn) == 0) { - int randPosX = i + rand.nextInt(16); - int randPosY = rand.nextInt(25); - int randPosZ = j + rand.nextInt(16); - - OilBubble.spawnOil(world, randPosX, randPosY, randPosZ, 10 + rand.nextInt(7)); - } - if(WorldConfig.bedrockOilSpawn > 0 && rand.nextInt(WorldConfig.bedrockOilSpawn) == 0) { int randPosX = i + rand.nextInt(16); int randPosZ = j + rand.nextInt(16); diff --git a/src/main/java/com/hbm/world/feature/OilBubble.java b/src/main/java/com/hbm/world/feature/OilBubble.java deleted file mode 100644 index e122d9d98..000000000 --- a/src/main/java/com/hbm/world/feature/OilBubble.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hbm.world.feature; - -import com.hbm.blocks.ModBlocks; - -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -public class OilBubble { - - public static void spawnOil(World world, int x, int y, int z, int radius) { - int r = radius; - int r2 = r * r; - int r22 = r2 / 2; - - for (int xx = -r; xx < r; xx++) { - int X = xx + x; - int XX = xx * xx; - for (int yy = -r; yy < r; yy++) { - int Y = yy + y; - int YY = XX + yy * yy * 3; - for (int zz = -r; zz < r; zz++) { - int Z = zz + z; - int ZZ = YY + zz * zz; - if (ZZ < r22) { - if(world.getBlock(X, Y, Z) == Blocks.stone) - world.setBlock(X, Y, Z, ModBlocks.ore_oil); - } - } - } - } - } - -} diff --git a/src/main/java/com/hbm/world/feature/OilSandBubble.java b/src/main/java/com/hbm/world/feature/OilSandBubble.java deleted file mode 100644 index 45e5c804f..000000000 --- a/src/main/java/com/hbm/world/feature/OilSandBubble.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.hbm.world.feature; - -import java.util.Random; - -import com.hbm.blocks.ModBlocks; - -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -public class OilSandBubble { - - private final static Random field_149933_a = new Random(); - - public static void spawnOil(World world, int x, int y, int z, int radius) { - int r = radius; - int r2 = r * r; - int r22 = r2 / 2; - - for (int xx = -r; xx < r; xx++) { - int X = xx + x; - int XX = xx * xx; - for (int yy = -r; yy < r; yy++) { - int Y = yy + y; - int YY = XX + yy * yy * 3; - for (int zz = -r; zz < r; zz++) { - int Z = zz + z; - int ZZ = YY + zz * zz; - if (ZZ < r22 + field_149933_a.nextInt(r22 / 3)) { - if(world.getBlock(X, Y, Z) == Blocks.sand) - world.setBlock(X, Y, Z, ModBlocks.ore_oil_sand); - } - } - } - } - } - -} diff --git a/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java b/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java new file mode 100644 index 000000000..2d5cbde80 --- /dev/null +++ b/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java @@ -0,0 +1,79 @@ +package com.hbm.world.gen.terrain; + +import java.util.function.Predicate; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.gen.MapGenBase; + +public class MapGenBubble extends MapGenBase { + + /** + * Generates oil bubbles, which are generally wider than a chunk, in a safe + cascadeless manner + * Pretty much just an oblate sphere generator (dimensions: 3 x 1 x 3) + */ + + private final int frequency; + private int minSize = 8; + private int maxSize = 64; + + public int minY = 0; + public int rangeY = 25; + + public boolean fuzzy; + + public Block block; + public Block replace = Blocks.stone; + + public Predicate canSpawn; + + public MapGenBubble(int frequency) { + this.frequency = frequency; + } + + public void setSize(int minSize, int maxSize) { + this.minSize = minSize; + this.maxSize = maxSize; + + this.range = (maxSize / 8) + 1; + } + + @Override + protected void func_151538_a(World world, int offsetX, int offsetZ, int chunkX, int chunkZ, Block[] blocks) { + if(rand.nextInt(frequency) == 0 && (canSpawn == null || canSpawn.test(world.getBiomeGenForCoords(offsetX * 16, offsetZ * 16)))) { + int xCoord = chunkX - offsetX; + int zCoord = chunkZ - offsetZ; + + int yCoord = rand.nextInt(rangeY) + minY; + + double radius = rand.nextInt(maxSize - minSize) + minSize; + double radiusSqr = (radius * radius) / 2; // original OilBubble implementation divided the square by 2 for some reason + + int yMin = Math.max(1, MathHelper.floor_double(yCoord - radius)); + int yMax = MathHelper.ceiling_double_int(yCoord + radius); + + for(int bx = 15; bx >= 0; bx--) // bx, bz is the coordinate of the block we're modifying, relative to the generating chunk origin + for(int bz = 15; bz >= 0; bz--) + for(int by = yMin; by < yMax; by++) { + int index = (bx * 16 + bz) * 256 + by; + + if(blocks[index] == replace) { + // x, z are the coordinates relative to the target virtual chunk origin + int x = xCoord * 16 + bx; + int z = zCoord * 16 + bz; + int y = yCoord - by; + + double rSqr = x * x + z * z + y * y * 3; + if(fuzzy) rSqr -= rand.nextDouble() * radiusSqr / 3; + if(rSqr < radiusSqr) { + blocks[index] = block; + } + } + } + } + } + +} diff --git a/src/main/java/com/hbm/world/gen/MapGenCrater.java b/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java similarity index 98% rename from src/main/java/com/hbm/world/gen/MapGenCrater.java rename to src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java index 7afc58735..eb593b65d 100644 --- a/src/main/java/com/hbm/world/gen/MapGenCrater.java +++ b/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java @@ -1,4 +1,4 @@ -package com.hbm.world.gen; +package com.hbm.world.gen.terrain; import net.minecraft.block.Block; import net.minecraft.util.MathHelper;