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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.gen;
|
2014-11-10 16:47:04 +01:00
|
|
|
|
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;
|
2016-06-05 12:15:02 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
|
2016-05-21 12:46:55 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2016-07-03 20:57:00 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-02-17 16:15:16 +01:00
|
|
|
import net.minecraft.block.Block;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
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;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2014-11-10 16:47:04 +01:00
|
|
|
import net.minecraft.world.World;
|
2015-08-02 06:55:32 +02:00
|
|
|
import net.minecraft.world.WorldType;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.world.biome.BiomeOcean;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.world.chunk.IChunkGenerator;
|
2014-11-10 16:47:04 +01:00
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
import net.minecraft.world.gen.feature.WorldGenMinable;
|
2016-10-19 18:51:07 +02:00
|
|
|
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
|
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;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2016-07-04 20:15:41 +02:00
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
2014-11-10 16:47:04 +01:00
|
|
|
|
2016-07-03 20:57:00 +02:00
|
|
|
import java.util.ArrayList;
|
2014-11-10 16:47:04 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2015-02-09 17:25:05 +01:00
|
|
|
public class OreGen implements IWorldGenerator{
|
2014-11-10 16:47:04 +01:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int QUARTZ_MIN = 0;
|
|
|
|
public static final int QUARTZ_MAX = 45;
|
|
|
|
|
2016-05-21 12:46:55 +02:00
|
|
|
private final WorldGenLushCaves caveGen = new WorldGenLushCaves();
|
|
|
|
|
2016-07-03 20:57:00 +02:00
|
|
|
public OreGen(){
|
2015-10-03 10:16:18 +02:00
|
|
|
ModUtil.LOGGER.info("Registering World Generator...");
|
2016-07-03 20:57:00 +02:00
|
|
|
GameRegistry.registerWorldGenerator(this, 10);
|
2016-07-03 21:11:46 +02:00
|
|
|
MinecraftForge.TERRAIN_GEN_BUS.register(this);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){
|
2016-05-18 19:34:57 +02:00
|
|
|
int dimension = world.provider.getDimension();
|
|
|
|
if(dimension != -1 && dimension != 1){
|
2016-07-24 18:58:08 +02:00
|
|
|
if(world.getWorldType() != WorldType.FLAT && !ArrayUtils.contains(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue(), world.provider.getDimension())){
|
2016-10-19 18:51:07 +02:00
|
|
|
this.generateDefault(world, random, chunkX, chunkZ);
|
2015-11-20 20:52:03 +01:00
|
|
|
}
|
2014-11-10 16:47:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 19:34:57 +02:00
|
|
|
private void generateDefault(World world, Random random, int x, int z){
|
2015-12-20 23:38:24 +01:00
|
|
|
if(ConfigBoolValues.GENERATE_QUARTZ.isEnabled()){
|
2016-10-19 18:51:07 +02:00
|
|
|
this.addOreSpawn(InitBlocks.blockMisc, TheMiscBlocks.ORE_QUARTZ.ordinal(), Blocks.STONE, world, random, x*16, z*16, MathHelper.getRandomIntegerInRange(random, 5, 8), 10, QUARTZ_MIN, QUARTZ_MAX);
|
2015-06-28 12:42:38 +02:00
|
|
|
}
|
2016-05-21 12:46:55 +02:00
|
|
|
|
2016-10-19 18:51:07 +02:00
|
|
|
if(ConfigBoolValues.GEN_LUSH_CAVES.isEnabled()){
|
|
|
|
StructureBoundingBox box = new StructureBoundingBox(x*16+8, 0, z*16+8, x*16+8+15, 255, z*16+8+15);
|
|
|
|
int chunkRadius = 1;
|
2016-10-30 17:13:46 +01:00
|
|
|
for(int dx = -chunkRadius; dx <= chunkRadius; dx++){
|
|
|
|
for(int dz = -chunkRadius; dz <= chunkRadius; dz++){
|
2016-10-19 18:51:07 +02:00
|
|
|
int chunkX = x+dx;
|
|
|
|
int chunkZ = z+dz;
|
|
|
|
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() ^ (chunkX*29+chunkZ*31));
|
2016-10-30 17:13:46 +01:00
|
|
|
if(chunkRand.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0){
|
2016-11-06 17:12:49 +01:00
|
|
|
BlockPos randPos = world.getTopSolidOrLiquidBlock(new BlockPos(chunkX*16+chunkRand.nextInt(16)+8, 0, chunkZ*16+chunkRand.nextInt(16)+8));
|
2016-10-19 18:51:07 +02:00
|
|
|
BlockPos pos = randPos.down(MathHelper.getRandomIntegerInRange(chunkRand, 15, randPos.getY()-15));
|
|
|
|
this.caveGen.generate(world, chunkRand, pos, box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 12:46:55 +02:00
|
|
|
}
|
2014-11-10 16:47:04 +01:00
|
|
|
}
|
|
|
|
|
2015-03-08 14:58:26 +01:00
|
|
|
public void addOreSpawn(Block block, int meta, Block blockIn, World world, Random random, int blockXPos, int blockZPos, int maxVeinSize, int chancesToSpawn, int minY, int maxY){
|
2016-10-30 17:13:46 +01:00
|
|
|
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(block.getStateFromMeta(meta), 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
|
|
|
|
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){
|
|
|
|
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){
|
2016-07-24 18:58:08 +02:00
|
|
|
if(!ArrayUtils.contains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension())){
|
2016-07-03 20:57:00 +02:00
|
|
|
this.generateRice(event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.CANOLA.ordinal(), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.FLAX.ordinal(), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.GRASS, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.COFFEE.ordinal(), ConfigIntValues.COFFEE_AMOUNT.getValue(), ConfigBoolValues.DO_COFFEE_GEN.isEnabled(), Material.GRASS, event);
|
|
|
|
this.genPlantNormally(InitBlocks.blockBlackLotus, 0, ConfigIntValues.BLACK_LOTUS_AMOUNT.getValue(), ConfigBoolValues.DO_LOTUS_GEN.isEnabled(), Material.GRASS, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Generate Treasure Chests
|
|
|
|
if(ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()){
|
|
|
|
if(event.getRand().nextInt(300) == 0){
|
|
|
|
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
|
|
|
|
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
|
|
|
|
|
2016-11-19 21:11:17 +01:00
|
|
|
if(event.getWorld().getBiome(randomPos) instanceof BiomeOcean){
|
2016-07-03 20:57:00 +02:00
|
|
|
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){
|
|
|
|
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){
|
2016-07-04 20:15:41 +02:00
|
|
|
if(event.getWorld().getBlockState(randomPos.down()).getMaterial().isSolid()){
|
|
|
|
event.getWorld().setBlockState(randomPos, InitBlocks.blockTreasureChest.getStateFromMeta(event.getRand().nextInt(4)), 2);
|
2016-07-03 20:57:00 +02: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(50) == 0){
|
|
|
|
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
|
|
|
|
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
|
2016-07-04 20:15:41 +02: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);
|
|
|
|
if(blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)){
|
2016-07-04 20:15:41 +02:00
|
|
|
if(!blocksAroundTop.contains(Material.WATER) && event.getWorld().getBlockState(posToGenAt).getMaterial() == Material.AIR){
|
|
|
|
event.getWorld().setBlockState(posToGenAt, InitBlocks.blockWildPlant.getStateFromMeta(TheWildPlants.RICE.ordinal()), 2);
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void genPlantNormally(Block plant, int meta, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event){
|
|
|
|
if(doIt){
|
|
|
|
for(int i = 0; i < amount; i++){
|
|
|
|
if(event.getRand().nextInt(400) == 0){
|
|
|
|
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
|
|
|
|
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
|
|
|
|
|
2016-07-04 20:15:41 +02:00
|
|
|
if(event.getWorld().getBlockState(randomPos.down()).getMaterial() == blockBelow){
|
2016-07-03 20:57:00 +02:00
|
|
|
if(plant.canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)){
|
2016-07-04 20:15:41 +02:00
|
|
|
event.getWorld().setBlockState(randomPos, plant.getStateFromMeta(meta), 2);
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 16:47:04 +01:00
|
|
|
}
|