bedrock oil spots

This commit is contained in:
George Paton 2025-10-07 15:33:40 +11:00
parent edbc062da0
commit 39603e2edb
7 changed files with 144 additions and 30 deletions

View File

@ -1,6 +1,5 @@
package com.hbm.lib; package com.hbm.lib;
import com.hbm.world.gen.MapGenChainloader.MapGenEventHandler;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.config.GeneralConfig; import com.hbm.config.GeneralConfig;
import com.hbm.config.WorldConfig; 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.*;
import com.hbm.world.gen.component.BunkerComponents.BunkerStart; import com.hbm.world.gen.component.BunkerComponents.BunkerStart;
import com.hbm.world.gen.nbt.NBTStructure; 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.MapGenBubble;
import com.hbm.world.gen.terrain.MapGenCrater; import com.hbm.world.gen.terrain.MapGenCrater;
@ -41,7 +41,7 @@ public class HbmWorld {
NBTStructure.register(); NBTStructure.register();
MinecraftForge.TERRAIN_GEN_BUS.register(new MapGenEventHandler()); MapGenChainloader.register();
registerNTMTerrain(); registerNTMTerrain();
} }
@ -74,6 +74,11 @@ public class HbmWorld {
MapGenChainloader.addOverworldGenerator(oilBubble); MapGenChainloader.addOverworldGenerator(oilBubble);
} }
if(WorldConfig.bedrockOilSpawn > 0) {
MapGenBedrockOil bedrockBubble = new MapGenBedrockOil(WorldConfig.bedrockOilSpawn);
MapGenChainloader.addOverworldGenerator(bedrockBubble);
}
int sandBubbleSpawn = 200; int sandBubbleSpawn = 200;
if(sandBubbleSpawn > 0) { if(sandBubbleSpawn > 0) {
MapGenBubble sandOilBubble = new MapGenBubble(sandBubbleSpawn); MapGenBubble sandOilBubble = new MapGenBubble(sandBubbleSpawn);

View File

@ -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) { if(WorldConfig.meteoriteSpawn > 0 && rand.nextInt(WorldConfig.meteoriteSpawn) == 0) {
int x = i + rand.nextInt(16) + 8; int x = i + rand.nextInt(16) + 8;
int z = j + rand.nextInt(16) + 8; int z = j + rand.nextInt(16) + 8;

View File

@ -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;
}
}

View File

@ -10,6 +10,8 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.MapGenBase; import net.minecraft.world.gen.MapGenBase;
import net.minecraftforge.event.terraingen.InitMapGenEvent; 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; import net.minecraftforge.event.terraingen.InitMapGenEvent.EventType;
public class MapGenChainloader extends MapGenBase { public class MapGenChainloader extends MapGenBase {
@ -27,6 +29,9 @@ public class MapGenChainloader extends MapGenBase {
private static List<MapGenBase> overworldGenerators = new ArrayList<>(); private static List<MapGenBase> overworldGenerators = new ArrayList<>();
private static List<MapGenBase> netherGenerators = new ArrayList<>(); private static List<MapGenBase> 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 // Executes our chainloaded parent, and all our child generators
@Override @Override
public void func_151539_a(IChunkProvider chunk, World world, int chunkX, int chunkZ, Block[] blocks) { 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; if(world.provider.dimensionId != 0 && world.provider.dimensionId != -1) return;
for(MapGenBase generator : generators) { for(MapGenBase generator : generators) {
if(generator instanceof MapGenBaseMeta) ((MapGenBaseMeta)generator).setMetas(blockMetas);
generator.func_151539_a(chunk, world, chunkX, chunkZ, blocks); 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) { public static void addOverworldGenerator(MapGenBase generator) {
if(overworldGenerators.contains(generator)) return; if(overworldGenerators.contains(generator)) return;
overworldGenerators.add(generator); overworldGenerators.add(generator);
@ -70,6 +82,11 @@ public class MapGenChainloader extends MapGenBase {
} }
} }
@SubscribeEvent
public void storeLatestBlockMeta(ReplaceBiomeBlocks event) {
blockMetas = event.metaArray;
}
} }
} }

View File

@ -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;
}
}
}
}
}
}
}

View File

@ -43,9 +43,9 @@ public class MapGenBubble extends MapGenBase {
@Override @Override
protected void func_151538_a(World world, int offsetX, int offsetZ, int chunkX, int chunkZ, Block[] blocks) { 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)))) { if(rand.nextInt(frequency) == frequency - 1 && (canSpawn == null || canSpawn.test(world.getBiomeGenForCoords(offsetX * 16, offsetZ * 16)))) {
int xCoord = chunkX - offsetX; int xCoord = (chunkX - offsetX) * 16 + rand.nextInt(16);
int zCoord = chunkZ - offsetZ; int zCoord = (chunkZ - offsetZ) * 16 + rand.nextInt(16);
int yCoord = rand.nextInt(rangeY) + minY; int yCoord = rand.nextInt(rangeY) + minY;
@ -62,8 +62,8 @@ public class MapGenBubble extends MapGenBase {
if(blocks[index] == replace) { if(blocks[index] == replace) {
// x, z are the coordinates relative to the target virtual chunk origin // x, z are the coordinates relative to the target virtual chunk origin
int x = xCoord * 16 + bx; int x = xCoord + bx;
int z = zCoord * 16 + bz; int z = zCoord + bz;
int y = yCoord - by; int y = yCoord - by;
double rSqr = x * x + z * z + y * y * 3; double rSqr = x * x + z * z + y * y * 3;

View File

@ -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 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 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; int index = (bx * 16 + bz) * 256 + y;
if(blocks[index] != null && (blocks[index].isOpaqueCube() || blocks[index].getMaterial().isLiquid())) { if(blocks[index] != null && (blocks[index].isOpaqueCube() || blocks[index].getMaterial().isLiquid())) {