This commit is contained in:
Shadows_of_Fire 2019-02-06 15:01:33 -05:00
parent 81a988811b
commit 7fe79f09be
2 changed files with 59 additions and 51 deletions

View file

@ -57,7 +57,9 @@ public enum ConfigBoolValues{
MOST_BLAND_PERSON_EVER("No Colored Item Names", ConfigCategories.OTHER, false, "If you want to be really boring and lame, you can turn on this setting to disable colored names on Actually Additions items. Because why would you want things to look pretty anyways, right?"), MOST_BLAND_PERSON_EVER("No Colored Item Names", ConfigCategories.OTHER, false, "If you want to be really boring and lame, you can turn on this setting to disable colored names on Actually Additions items. Because why would you want things to look pretty anyways, right?"),
COLOR_LENS_USES_OREDICT("Color Lens Oredict", ConfigCategories.OTHER, false, "If true, the Lens of Color will attempt to pull from the oredict instead of only using vanilla dyes."), COLOR_LENS_USES_OREDICT("Color Lens Oredict", ConfigCategories.OTHER, false, "If true, the Lens of Color will attempt to pull from the oredict instead of only using vanilla dyes."),
SOLID_XP_ALWAYS_ORBS("Solid XP Orbs", ConfigCategories.OTHER, false, "If true, Solidified Experience will always spawn orbs, even for regular players."); SOLID_XP_ALWAYS_ORBS("Solid XP Orbs", ConfigCategories.OTHER, false, "If true, Solidified Experience will always spawn orbs, even for regular players."),
ORE_GEN_DIM_WHITELIST("Ore Gen Whitelist", ConfigCategories.WORLD_GEN, false, "If true, the ore gen dimension blacklist will be treated as a whitelist.");
public final String name; public final String name;

View file

@ -10,6 +10,11 @@
package de.ellpeck.actuallyadditions.mod.gen; package de.ellpeck.actuallyadditions.mod.gen;
import java.util.ArrayList;
import java.util.Random;
import org.apache.commons.lang3.ArrayUtils;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.BlockMisc; import de.ellpeck.actuallyadditions.mod.blocks.BlockMisc;
import de.ellpeck.actuallyadditions.mod.blocks.BlockWildPlant; import de.ellpeck.actuallyadditions.mod.blocks.BlockWildPlant;
@ -43,68 +48,69 @@ import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList; public class OreGen implements IWorldGenerator {
import java.util.Random;
public class OreGen implements IWorldGenerator{
public static final int QUARTZ_MIN = 0; public static final int QUARTZ_MIN = 0;
public static final int QUARTZ_MAX = 45; public static final int QUARTZ_MAX = 45;
private final WorldGenLushCaves caveGen = new WorldGenLushCaves(); private final WorldGenLushCaves caveGen = new WorldGenLushCaves();
public OreGen(){ public OreGen() {
ActuallyAdditions.LOGGER.info("Registering World Generator..."); ActuallyAdditions.LOGGER.info("Registering World Generator...");
GameRegistry.registerWorldGenerator(this, 10000); GameRegistry.registerWorldGenerator(this, 10000);
MinecraftForge.TERRAIN_GEN_BUS.register(this); MinecraftForge.TERRAIN_GEN_BUS.register(this);
} }
@Override @Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
int dimension = world.provider.getDimension(); int dimension = world.provider.getDimension();
if(dimension != -1 && dimension != 1){ if (dimension != -1 && dimension != 1) {
if(world.getWorldType() != WorldType.FLAT && !ArrayUtils.contains(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue(), world.provider.getDimension())){ if (world.getWorldType() != WorldType.FLAT && canGen(world.provider.getDimension())) {
this.generateDefault(world, random, chunkX, chunkZ); this.generateDefault(world, random, chunkX, chunkZ);
} }
} }
} }
private void generateDefault(World world, Random random, int x, int z){ private boolean canGen(int dimension) {
if(ConfigBoolValues.GENERATE_QUARTZ.isEnabled()){ boolean inList = ArrayUtils.contains(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue(), dimension);
this.addOreSpawn(InitBlocks.blockMisc.getDefaultState().withProperty(BlockMisc.TYPE, TheMiscBlocks.ORE_QUARTZ), Blocks.STONE, world, random, x*16, z*16, MathHelper.getInt(random, 5, 8), 10, QUARTZ_MIN, QUARTZ_MAX); return (inList && ConfigBoolValues.ORE_GEN_DIM_WHITELIST.isEnabled()) || (!inList && !ConfigBoolValues.ORE_GEN_DIM_WHITELIST.isEnabled());
}
private void generateDefault(World world, Random random, int x, int z) {
if (ConfigBoolValues.GENERATE_QUARTZ.isEnabled()) {
this.addOreSpawn(InitBlocks.blockMisc.getDefaultState().withProperty(BlockMisc.TYPE, TheMiscBlocks.ORE_QUARTZ), Blocks.STONE, world, random, x * 16, z * 16, MathHelper.getInt(random, 5, 8), 10, QUARTZ_MIN, QUARTZ_MAX);
} }
if(ConfigBoolValues.GEN_LUSH_CAVES.isEnabled()){ if (ConfigBoolValues.GEN_LUSH_CAVES.isEnabled()) {
int randConst = 0x969ce69d;//so that it won't generate the same numbers as other mod that does the same thing int randConst = 0x969ce69d;//so that it won't generate the same numbers as other mod that does the same thing
Random chunkRand = new Random(randConst ^ world.getSeed() ^ (x*29+z*31)); Random chunkRand = new Random(randConst ^ world.getSeed() ^ (x * 29 + z * 31));
StructureBoundingBox box = new StructureBoundingBox(x*16+8, 0, z*16+8, x*16+8+15, 255, z*16+8+15); StructureBoundingBox box = new StructureBoundingBox(x * 16 + 8, 0, z * 16 + 8, x * 16 + 8 + 15, 255, z * 16 + 8 + 15);
if(chunkRand.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0){ if (chunkRand.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0) {
BlockPos randPos = world.getTopSolidOrLiquidBlock(new BlockPos(x*16+chunkRand.nextInt(16)+8, 0, z*16+chunkRand.nextInt(16)+8)); BlockPos randPos = world.getTopSolidOrLiquidBlock(new BlockPos(x * 16 + chunkRand.nextInt(16) + 8, 0, z * 16 + chunkRand.nextInt(16) + 8));
BlockPos pos = randPos.down(MathHelper.getInt(chunkRand, 15, randPos.getY()-15)); BlockPos pos = randPos.down(MathHelper.getInt(chunkRand, 15, randPos.getY() - 15));
this.caveGen.generate(world, chunkRand, pos, box); this.caveGen.generate(world, chunkRand, pos, box);
} }
} }
} }
public void addOreSpawn(IBlockState state, Block blockIn, World world, Random random, int blockXPos, int blockZPos, int maxVeinSize, int chancesToSpawn, int minY, int maxY){ public void addOreSpawn(IBlockState state, Block blockIn, World world, Random random, int blockXPos, int blockZPos, int maxVeinSize, int chancesToSpawn, int minY, int maxY) {
for(int i = 0; i < chancesToSpawn; i++){ for (int i = 0; i < chancesToSpawn; i++) {
int posX = blockXPos+random.nextInt(16); int posX = blockXPos + random.nextInt(16);
int posY = minY+random.nextInt(maxY-minY); int posY = minY + random.nextInt(maxY - minY);
int posZ = blockZPos+random.nextInt(16); int posZ = blockZPos + random.nextInt(16);
new WorldGenMinable(state, maxVeinSize, BlockMatcher.forBlock(blockIn)).generate(world, random, new BlockPos(posX, posY, posZ)); new WorldGenMinable(state, maxVeinSize, BlockMatcher.forBlock(blockIn)).generate(world, random, new BlockPos(posX, posY, posZ));
} }
} }
@SubscribeEvent @SubscribeEvent
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){ public void onWorldDecoration(DecorateBiomeEvent.Decorate event) {
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){ if ((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)) {
if(event.getType() == EventType.FLOWERS){ if (event.getType() == EventType.FLOWERS) {
if(!ArrayUtils.contains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension())){ if (!ArrayUtils.contains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension())) {
this.generateRice(event); this.generateRice(event);
IBlockState plantDefault = InitBlocks.blockWildPlant.getDefaultState(); IBlockState plantDefault = InitBlocks.blockWildPlant.getDefaultState();
this.genPlantNormally(plantDefault.withProperty(BlockWildPlant.TYPE, TheWildPlants.CANOLA), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event); this.genPlantNormally(plantDefault.withProperty(BlockWildPlant.TYPE, TheWildPlants.CANOLA), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event);
@ -114,17 +120,17 @@ public class OreGen implements IWorldGenerator{
} }
} }
if(event.getType() == EventType.LILYPAD){ if (event.getType() == EventType.LILYPAD) {
//Generate Treasure Chests //Generate Treasure Chests
if(ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()){ if (ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()) {
if(event.getRand().nextInt(40) == 0){ if (event.getRand().nextInt(40) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16)+8, 0, event.getRand().nextInt(16)+8); BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos); randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(event.getWorld().getBiome(randomPos) instanceof BiomeOcean){ if (event.getWorld().getBiome(randomPos) instanceof BiomeOcean) {
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){ if (randomPos.getY() >= 25 && randomPos.getY() <= 45) {
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){ if (event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER) {
if(event.getWorld().getBlockState(randomPos.down()).getMaterial().isSolid()){ if (event.getWorld().getBlockState(randomPos.down()).getMaterial().isSolid()) {
event.getWorld().setBlockState(randomPos, InitBlocks.blockTreasureChest.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(event.getRand().nextInt(4))), 2); event.getWorld().setBlockState(randomPos, InitBlocks.blockTreasureChest.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(event.getRand().nextInt(4))), 2);
} }
} }
@ -136,18 +142,18 @@ public class OreGen implements IWorldGenerator{
} }
} }
private void generateRice(DecorateBiomeEvent event){ private void generateRice(DecorateBiomeEvent event) {
if(ConfigBoolValues.DO_RICE_GEN.isEnabled()){ if (ConfigBoolValues.DO_RICE_GEN.isEnabled()) {
for(int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++){ for (int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++) {
if(event.getRand().nextInt(3) == 0){ if (event.getRand().nextInt(3) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16)+8, 0, event.getRand().nextInt(16)+8); BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos); randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){ if (event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER) {
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos); ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos);
BlockPos posToGenAt = randomPos.up(); BlockPos posToGenAt = randomPos.up();
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt); ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt);
if(blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)){ if (blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)) {
if(!blocksAroundTop.contains(Material.WATER) && event.getWorld().getBlockState(posToGenAt).getMaterial() == Material.AIR){ if (!blocksAroundTop.contains(Material.WATER) && event.getWorld().getBlockState(posToGenAt).getMaterial() == Material.AIR) {
event.getWorld().setBlockState(posToGenAt, InitBlocks.blockWildPlant.getDefaultState().withProperty(BlockWildPlant.TYPE, TheWildPlants.RICE), 2); event.getWorld().setBlockState(posToGenAt, InitBlocks.blockWildPlant.getDefaultState().withProperty(BlockWildPlant.TYPE, TheWildPlants.RICE), 2);
} }
} }
@ -157,15 +163,15 @@ public class OreGen implements IWorldGenerator{
} }
} }
private void genPlantNormally(IBlockState plant, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event){ private void genPlantNormally(IBlockState plant, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event) {
if(doIt){ if (doIt) {
for(int i = 0; i < amount; i++){ for (int i = 0; i < amount; i++) {
if(event.getRand().nextInt(100) == 0){ if (event.getRand().nextInt(100) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16)+8, 0, event.getRand().nextInt(16)+8); BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos); randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(event.getWorld().getBlockState(randomPos.down()).getMaterial() == blockBelow){ if (event.getWorld().getBlockState(randomPos.down()).getMaterial() == blockBelow) {
if(plant.getBlock().canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)){ if (plant.getBlock().canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)) {
event.getWorld().setBlockState(randomPos, plant, 2); event.getWorld().setBlockState(randomPos, plant, 2);
} }
} }