From 39603e2edb3891cd8bf8a5e81ca2ac7a43b55166 Mon Sep 17 00:00:00 2001 From: George Paton Date: Tue, 7 Oct 2025 15:33:40 +1100 Subject: [PATCH] bedrock oil spots --- src/main/java/com/hbm/lib/HbmWorld.java | 9 +- src/main/java/com/hbm/lib/HbmWorldGen.java | 22 ---- .../com/hbm/world/gen/MapGenBaseMeta.java | 13 +++ .../com/hbm/world/gen/MapGenChainloader.java | 17 +++ .../world/gen/terrain/MapGenBedrockOil.java | 101 ++++++++++++++++++ .../hbm/world/gen/terrain/MapGenBubble.java | 10 +- .../hbm/world/gen/terrain/MapGenCrater.java | 2 +- 7 files changed, 144 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/hbm/world/gen/MapGenBaseMeta.java create mode 100644 src/main/java/com/hbm/world/gen/terrain/MapGenBedrockOil.java diff --git a/src/main/java/com/hbm/lib/HbmWorld.java b/src/main/java/com/hbm/lib/HbmWorld.java index b8d60ca8a..f563e7bb1 100644 --- a/src/main/java/com/hbm/lib/HbmWorld.java +++ b/src/main/java/com/hbm/lib/HbmWorld.java @@ -1,6 +1,5 @@ package com.hbm.lib; -import com.hbm.world.gen.MapGenChainloader.MapGenEventHandler; import com.hbm.blocks.ModBlocks; import com.hbm.config.GeneralConfig; import com.hbm.config.WorldConfig; @@ -10,6 +9,7 @@ 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.MapGenBedrockOil; import com.hbm.world.gen.terrain.MapGenBubble; import com.hbm.world.gen.terrain.MapGenCrater; @@ -41,7 +41,7 @@ public class HbmWorld { NBTStructure.register(); - MinecraftForge.TERRAIN_GEN_BUS.register(new MapGenEventHandler()); + MapGenChainloader.register(); registerNTMTerrain(); } @@ -74,6 +74,11 @@ public class HbmWorld { MapGenChainloader.addOverworldGenerator(oilBubble); } + if(WorldConfig.bedrockOilSpawn > 0) { + MapGenBedrockOil bedrockBubble = new MapGenBedrockOil(WorldConfig.bedrockOilSpawn); + MapGenChainloader.addOverworldGenerator(bedrockBubble); + } + int sandBubbleSpawn = 200; if(sandBubbleSpawn > 0) { MapGenBubble sandOilBubble = new MapGenBubble(sandBubbleSpawn); diff --git a/src/main/java/com/hbm/lib/HbmWorldGen.java b/src/main/java/com/hbm/lib/HbmWorldGen.java index 8fec93b01..b5dac1bcd 100644 --- a/src/main/java/com/hbm/lib/HbmWorldGen.java +++ b/src/main/java/com/hbm/lib/HbmWorldGen.java @@ -495,28 +495,6 @@ public class HbmWorldGen implements IWorldGenerator { } } - if(WorldConfig.bedrockOilSpawn > 0 && rand.nextInt(WorldConfig.bedrockOilSpawn) == 0) { - int randPosX = i + rand.nextInt(16); - int randPosZ = j + rand.nextInt(16); - - for(int x = -4; x <= 4; x++) { - for(int y = 0; y <= 4; y++) { - for(int z = -4; z <= 4; z++) { - - if(Math.abs(x) + Math.abs(y) + Math.abs(z) <= 6) { - Block b = world.getBlock(randPosX + x, y, randPosZ + z); - if(b.isReplaceableOreGen(world, randPosX + x, y, randPosZ + z, Blocks.stone) || b.isReplaceableOreGen(world, randPosX + x, y, randPosZ + z, Blocks.bedrock)) { - world.setBlock(randPosX + x, y, randPosZ + z, ModBlocks.ore_bedrock_oil); - } - } - } - } - } - - DungeonToolbox.generateOre(world, rand, i, j, 16, 8, 10, 50, ModBlocks.stone_porous); - OilSpot.generateOilSpot(world, randPosX, randPosZ, 5, 50, true); - } - if(WorldConfig.meteoriteSpawn > 0 && rand.nextInt(WorldConfig.meteoriteSpawn) == 0) { int x = i + rand.nextInt(16) + 8; int z = j + rand.nextInt(16) + 8; diff --git a/src/main/java/com/hbm/world/gen/MapGenBaseMeta.java b/src/main/java/com/hbm/world/gen/MapGenBaseMeta.java new file mode 100644 index 000000000..fe2aaf728 --- /dev/null +++ b/src/main/java/com/hbm/world/gen/MapGenBaseMeta.java @@ -0,0 +1,13 @@ +package com.hbm.world.gen; + +import net.minecraft.world.gen.MapGenBase; + +public class MapGenBaseMeta extends MapGenBase { + + protected byte[] metas; + + public void setMetas(byte[] metas) { + this.metas = metas; + } + +} diff --git a/src/main/java/com/hbm/world/gen/MapGenChainloader.java b/src/main/java/com/hbm/world/gen/MapGenChainloader.java index 3f9c96018..93dbc96e5 100644 --- a/src/main/java/com/hbm/world/gen/MapGenChainloader.java +++ b/src/main/java/com/hbm/world/gen/MapGenChainloader.java @@ -10,6 +10,8 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.MapGenBase; import net.minecraftforge.event.terraingen.InitMapGenEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.terraingen.ChunkProviderEvent.ReplaceBiomeBlocks; import net.minecraftforge.event.terraingen.InitMapGenEvent.EventType; public class MapGenChainloader extends MapGenBase { @@ -27,6 +29,9 @@ public class MapGenChainloader extends MapGenBase { private static List overworldGenerators = new ArrayList<>(); private static List netherGenerators = new ArrayList<>(); + // Hack to provide the current generating chunk's block metas to the generation function + private static byte[] blockMetas; + // Executes our chainloaded parent, and all our child generators @Override public void func_151539_a(IChunkProvider chunk, World world, int chunkX, int chunkZ, Block[] blocks) { @@ -36,10 +41,17 @@ public class MapGenChainloader extends MapGenBase { if(world.provider.dimensionId != 0 && world.provider.dimensionId != -1) return; for(MapGenBase generator : generators) { + if(generator instanceof MapGenBaseMeta) ((MapGenBaseMeta)generator).setMetas(blockMetas); generator.func_151539_a(chunk, world, chunkX, chunkZ, blocks); } } + public static void register() { + MapGenEventHandler handler = new MapGenEventHandler(); + MinecraftForge.TERRAIN_GEN_BUS.register(handler); + MinecraftForge.EVENT_BUS.register(handler); + } + public static void addOverworldGenerator(MapGenBase generator) { if(overworldGenerators.contains(generator)) return; overworldGenerators.add(generator); @@ -70,6 +82,11 @@ public class MapGenChainloader extends MapGenBase { } } + @SubscribeEvent + public void storeLatestBlockMeta(ReplaceBiomeBlocks event) { + blockMetas = event.metaArray; + } + } } diff --git a/src/main/java/com/hbm/world/gen/terrain/MapGenBedrockOil.java b/src/main/java/com/hbm/world/gen/terrain/MapGenBedrockOil.java new file mode 100644 index 000000000..05e3128ff --- /dev/null +++ b/src/main/java/com/hbm/world/gen/terrain/MapGenBedrockOil.java @@ -0,0 +1,101 @@ +package com.hbm.world.gen.terrain; + +import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.generic.BlockNTMFlower.EnumFlowerType; +import com.hbm.world.gen.MapGenBaseMeta; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +public class MapGenBedrockOil extends MapGenBaseMeta { + + /** + * Similar to oil bubbles, but with a few more behaviours, like adding oily dirt and porous stone + */ + + private final int frequency; + + public Block block = ModBlocks.ore_bedrock_oil; + public Block replace = Blocks.stone; + + public int spotWidth = 5; + public int spotCount = 50; + public boolean addWillows = true; + + public MapGenBedrockOil(int frequency) { + this.frequency = frequency; + this.range = 4; + } + + @Override + protected void func_151538_a(World world, int offsetX, int offsetZ, int chunkX, int chunkZ, Block[] blocks) { + if(rand.nextInt(frequency) == frequency - 2) { + int xCoord = (chunkX - offsetX) * 16; + int zCoord = (chunkZ - offsetZ) * 16; + + // Add the bedrock oil spot + for(int bx = 15; bx >= 0; bx--) + for(int bz = 15; bz >= 0; bz--) + for(int y = 0; y < 5; y++) { + int index = (bx * 16 + bz) * 256 + y; + + if(blocks[index] == replace || blocks[index] == Blocks.bedrock) { + // x, z are the coordinates relative to the target virtual chunk origin + int x = xCoord + bx; + int z = zCoord + bz; + + if(Math.abs(x) < 5 && Math.abs(z) < 5 && Math.abs(x) + Math.abs(y) + Math.abs(z) <= 6) { + blocks[index] = block; + } + } + } + + // Add oil spot damage + for(int i = 0; i < spotCount; i++) { + int rx = xCoord + (int)(world.rand.nextGaussian() * spotWidth); + int rz = zCoord + (int)(world.rand.nextGaussian() * spotWidth); + + if(rx >= 0 && rx < 16 && rz >= 0 && rz < 16) { + // find ground level + for(int y = 127; y >= 0; y--) { + int index = (rx * 16 + rz) * 256 + y; + + if(blocks[index] != null && blocks[index].isOpaqueCube()) { + for(int oy = 1; oy > -3; oy--) { + int subIndex = index + oy; + + // this generation occurs BEFORE decoration, so we have no plants to modify + + if(blocks[subIndex] == Blocks.grass || blocks[subIndex] == Blocks.dirt) { + blocks[subIndex] = rand.nextInt(10) == 0 ? ModBlocks.dirt_oily : ModBlocks.dirt_dead; + + if(addWillows && oy == 0 && rand.nextInt(50) == 0) { + blocks[subIndex + 1] = ModBlocks.plant_flower; + metas[subIndex + 1] = (byte)EnumFlowerType.CD0.ordinal(); + } + + break; + } else if(blocks[subIndex] == Blocks.sand || blocks[subIndex] == ModBlocks.ore_oil_sand) { + if(metas[subIndex] == 1) { + blocks[subIndex] = ModBlocks.sand_dirty_red; + } else { + blocks[subIndex] = ModBlocks.sand_dirty; + } + break; + } else if(blocks[subIndex] == Blocks.stone) { + blocks[subIndex] = ModBlocks.stone_cracked; + break; + } + } + + break; + } + } + } + } + } + } + + +} diff --git a/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java b/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java index 2d5cbde80..5562090cd 100644 --- a/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java +++ b/src/main/java/com/hbm/world/gen/terrain/MapGenBubble.java @@ -43,9 +43,9 @@ public class MapGenBubble extends MapGenBase { @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; + if(rand.nextInt(frequency) == frequency - 1 && (canSpawn == null || canSpawn.test(world.getBiomeGenForCoords(offsetX * 16, offsetZ * 16)))) { + int xCoord = (chunkX - offsetX) * 16 + rand.nextInt(16); + int zCoord = (chunkZ - offsetZ) * 16 + rand.nextInt(16); int yCoord = rand.nextInt(rangeY) + minY; @@ -62,8 +62,8 @@ public class MapGenBubble extends MapGenBase { 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 x = xCoord + bx; + int z = zCoord + bz; int y = yCoord - by; double rSqr = x * x + z * z + y * y * 3; diff --git a/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java b/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java index eb593b65d..9a1efd7e9 100644 --- a/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java +++ b/src/main/java/com/hbm/world/gen/terrain/MapGenCrater.java @@ -44,7 +44,7 @@ public class MapGenCrater extends MapGenBase { 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 y = 254; y >= 0; y--) { + for(int y = 127; y >= 0; y--) { int index = (bx * 16 + bz) * 256 + y; if(blocks[index] != null && (blocks[index].isOpaqueCube() || blocks[index].getMaterial().isLiquid())) {