ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/gen/AAWorldGen.java

179 lines
10 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("OreGen.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.gen;
2019-02-06 21:01:33 +01:00
import java.util.ArrayList;
import java.util.Random;
import org.apache.commons.lang3.ArrayUtils;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.BlockMisc;
import de.ellpeck.actuallyadditions.mod.blocks.BlockWildPlant;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
2016-07-03 20:57:00 +02:00
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.state.pattern.BlockMatcher;
2015-03-08 14:58:26 +01:00
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
2016-07-03 20:57:00 +02:00
import net.minecraft.world.biome.BiomeOcean;
import net.minecraft.world.chunk.IChunkProvider;
2017-06-17 00:48:49 +02:00
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.structure.StructureBoundingBox;
2016-07-03 20:57:00 +02:00
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.IWorldGenerator;
2016-07-03 20:57:00 +02:00
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2019-02-27 19:44:33 +01:00
public class AAWorldGen implements IWorldGenerator {
public static final int QUARTZ_MIN = 0;
public static final int QUARTZ_MAX = 45;
private final WorldGenLushCaves caveGen = new WorldGenLushCaves();
2019-02-27 19:44:33 +01:00
public AAWorldGen() {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("Registering World Generator...");
2015-10-03 10:16:18 +02:00
}
@Override
2019-02-06 21:01:33 +01:00
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
2017-03-08 20:06:55 +01:00
int dimension = world.provider.getDimension();
2019-02-06 21:01:33 +01:00
if (dimension != -1 && dimension != 1) {
if (world.getWorldType() != WorldType.FLAT && canGen(world.provider.getDimension())) {
this.generateDefault(world, random, chunkX, chunkZ);
}
}
}
2019-02-06 21:01:33 +01:00
private boolean canGen(int dimension) {
boolean inList = ArrayUtils.contains(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue(), dimension);
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);
2015-06-28 12:42:38 +02:00
}
2019-02-06 21:01:33 +01:00
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
2019-02-06 21:01:33 +01:00
Random chunkRand = new Random(randConst ^ world.getSeed() ^ (x * 29 + z * 31));
2019-02-06 21:01:33 +01:00
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) {
2019-02-27 20:42:38 +01:00
BlockPos randPos = world.getTopSolidOrLiquidBlock(new BlockPos(x * 16 + MathHelper.getInt(random, 6, 10), 0, z * 16 + MathHelper.getInt(random, 6, 10)));
2019-02-06 21:01:33 +01:00
BlockPos pos = randPos.down(MathHelper.getInt(chunkRand, 15, randPos.getY() - 15));
this.caveGen.generate(world, chunkRand, pos, box);
}
}
}
2019-02-06 21:01:33 +01:00
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++) {
int posX = blockXPos + random.nextInt(16);
int posY = minY + random.nextInt(maxY - minY);
int posZ = blockZPos + random.nextInt(16);
new WorldGenMinable(state, maxVeinSize, BlockMatcher.forBlock(blockIn)).generate(world, random, new BlockPos(posX, posY, posZ));
2015-10-02 16:48:01 +02:00
}
2015-03-08 14:58:26 +01:00
}
2016-07-03 20:57:00 +02:00
@SubscribeEvent
2019-02-06 21:01:33 +01:00
public void onWorldDecoration(DecorateBiomeEvent.Decorate event) {
if ((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)) {
if (event.getType() == EventType.FLOWERS) {
if (!ArrayUtils.contains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension())) {
this.generateRice(event);
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.FLAX), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(plantDefault.withProperty(BlockWildPlant.TYPE, TheWildPlants.COFFEE), ConfigIntValues.COFFEE_AMOUNT.getValue(), ConfigBoolValues.DO_COFFEE_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockBlackLotus.getDefaultState(), ConfigIntValues.BLACK_LOTUS_AMOUNT.getValue(), ConfigBoolValues.DO_LOTUS_GEN.isEnabled(), Material.GRASS, event);
}
2016-07-03 20:57:00 +02:00
}
2019-02-06 21:01:33 +01:00
if (event.getType() == EventType.LILYPAD) {
//Generate Treasure Chests
2019-02-06 21:01:33 +01:00
if (ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()) {
if (event.getRand().nextInt(40) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
2019-02-06 21:01:33 +01:00
if (event.getWorld().getBiome(randomPos) instanceof BiomeOcean) {
if (randomPos.getY() >= 25 && randomPos.getY() <= 45) {
if (event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER) {
if (event.getWorld().getBlockState(randomPos.down()).getMaterial().isSolid()) {
2018-08-04 04:22:20 +02:00
event.getWorld().setBlockState(randomPos, InitBlocks.blockTreasureChest.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(event.getRand().nextInt(4))), 2);
}
2016-07-03 20:57:00 +02:00
}
}
}
}
}
}
}
}
2019-02-06 21:01:33 +01:00
private void generateRice(DecorateBiomeEvent event) {
if (ConfigBoolValues.DO_RICE_GEN.isEnabled()) {
for (int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++) {
if (event.getRand().nextInt(3) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
2016-07-03 20:57:00 +02:00
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
2019-02-06 21:01:33 +01:00
if (event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER) {
2016-07-03 20:57:00 +02:00
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos);
2016-07-04 20:15:41 +02:00
BlockPos posToGenAt = randomPos.up();
2016-07-03 20:57:00 +02:00
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt);
2019-02-06 21:01:33 +01:00
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) {
event.getWorld().setBlockState(posToGenAt, InitBlocks.blockWildPlant.getDefaultState().withProperty(BlockWildPlant.TYPE, TheWildPlants.RICE), 2);
2016-07-03 20:57:00 +02:00
}
}
}
}
}
}
}
2019-02-06 21:01:33 +01:00
private void genPlantNormally(IBlockState plant, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event) {
if (doIt) {
for (int i = 0; i < amount; i++) {
if (event.getRand().nextInt(100) == 0) {
BlockPos randomPos = event.getChunkPos().getBlock(event.getRand().nextInt(16) + 8, 0, event.getRand().nextInt(16) + 8);
2016-07-03 20:57:00 +02:00
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
2019-02-06 21:01:33 +01:00
if (event.getWorld().getBlockState(randomPos.down()).getMaterial() == blockBelow) {
if (plant.getBlock().canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)) {
event.getWorld().setBlockState(randomPos, plant, 2);
2016-07-03 20:57:00 +02:00
}
}
}
}
}
}
}