Added flax to the shrubland

This commit is contained in:
Adubbz 2015-04-14 20:20:25 +10:00
parent 7c99f7acf4
commit 69490107d7
4 changed files with 109 additions and 1 deletions

View File

@ -8,6 +8,8 @@
package biomesoplenty.common.biome.overworld;
import static biomesoplenty.common.block.BlockBOPDoublePlant.VARIANT;
import static biomesoplenty.common.block.BlockDoubleDecoration.HALF;
import net.minecraft.block.BlockFlower.EnumFlowerType;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.entity.passive.EntityHorse;
@ -18,9 +20,12 @@ import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.GeneratorWeighted;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.BOPPlantEnums.AllPlants;
import biomesoplenty.common.block.BlockBOPDoublePlant.FoliageType;
import biomesoplenty.common.block.BlockBOPPlant;
import biomesoplenty.common.block.BlockDoubleDecoration.Half;
import biomesoplenty.common.block.BlockGem;
import biomesoplenty.common.block.BlockGem.GemType;
import biomesoplenty.common.world.feature.GeneratorDoubleFlora;
import biomesoplenty.common.world.feature.GeneratorFlora;
import biomesoplenty.common.world.feature.GeneratorGrass;
import biomesoplenty.common.world.feature.GeneratorOreSingle;
@ -43,6 +48,7 @@ public class BiomeGenShrubland extends BOPBiome
this.addGenerator("gravel", GeneratorStage.SAND_PASS2, new GeneratorWaterside(4, 7, Blocks.gravel.getDefaultState()));
this.addGenerator("shrubs", GeneratorStage.FLOWERS, new GeneratorFlora(5, BlockBOPPlant.getVariantState(AllPlants.SHRUB)));
this.addGenerator("flax", GeneratorStage.FLOWERS, new GeneratorDoubleFlora(1, BOPBlocks.double_plant.getDefaultState().withProperty(VARIANT, FoliageType.FLAX).withProperty(HALF, Half.LOWER), BOPBlocks.double_plant.getDefaultState().withProperty(VARIANT, FoliageType.FLAX).withProperty(HALF, Half.UPPER), 24));
this.addGenerator("trees", GeneratorStage.TREE, new GeneratorBush(1, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState()));
this.addGenerator("flowers", GeneratorStage.FLOWERS, new GeneratorFlora(5, Blocks.red_flower.getDefaultState().withProperty(Blocks.red_flower.getTypeProperty(), EnumFlowerType.ALLIUM)));

View File

@ -24,7 +24,7 @@ import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
class BlockDoubleDecoration extends BlockDecoration {
public class BlockDoubleDecoration extends BlockDecoration {
// add half property
public static enum Half implements IStringSerializable

View File

@ -11,6 +11,7 @@ package biomesoplenty.common.init;
import static biomesoplenty.api.biome.generation.GeneratorRegistry.registerGenerator;
import biomesoplenty.api.biome.generation.GeneratorWeighted;
import biomesoplenty.api.biome.generation.GeneratorWeightedEntry;
import biomesoplenty.common.world.feature.GeneratorDoubleFlora;
import biomesoplenty.common.world.feature.GeneratorFlora;
import biomesoplenty.common.world.feature.GeneratorGrass;
import biomesoplenty.common.world.feature.GeneratorOreCluster;
@ -30,6 +31,7 @@ public class ModGenerators
registerGenerator("basic_tree", GeneratorBasicTree.class);
registerGenerator("bush", GeneratorBush.class);
registerGenerator("flora", GeneratorFlora.class);
registerGenerator("double_flora", GeneratorDoubleFlora.class);
registerGenerator("grass", GeneratorGrass.class);
registerGenerator("waterside", GeneratorWaterside.class);
}

View File

@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright 2015, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.world.feature;
import java.util.Random;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
import biomesoplenty.common.block.BlockDecoration;
import biomesoplenty.common.util.biome.GeneratorUtils;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class GeneratorDoubleFlora extends GeneratorCustomizable
{
private int amountPerChunk;
private IBlockState bottomState;
private IBlockState topState;
private int generationAttempts;
public GeneratorDoubleFlora() {}
public GeneratorDoubleFlora(int amountPerChunk, IBlockState bottomState, IBlockState topState, int generationAttempts)
{
this.amountPerChunk = amountPerChunk;
this.bottomState = bottomState;
this.topState = topState;
this.generationAttempts = generationAttempts;
}
public GeneratorDoubleFlora(int amountPerChunk, IBlockState bottomState, IBlockState topState)
{
this(amountPerChunk, bottomState, topState, 64);
}
@Override
public void scatter(World world, Random random, BlockPos pos)
{
for (int i = 0; i < amountPerChunk; i++)
{
int x = random.nextInt(16) + 8;
int z = random.nextInt(16) + 8;
BlockPos genPos = pos.add(x, 0, z);
int y = GeneratorUtils.safeNextInt(random, world.getHeight(genPos).getY() + 32);
genPos = genPos.add(0, y, 0);
generate(world, random, genPos);
}
}
@Override
public boolean generate(World world, Random random, BlockPos pos)
{
Block bottomBlock = this.bottomState.getBlock();
for (int i = 0; i < this.generationAttempts; ++i)
{
BlockPos genPos = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
boolean canStay = bottomBlock instanceof BlockDecoration ? ((BlockDecoration)bottomBlock).canBlockStay(world, genPos, this.bottomState) : bottomBlock.canPlaceBlockAt(world, genPos);
if (world.isAirBlock(genPos) && world.isAirBlock(genPos.up()) && (!world.provider.getHasNoSky() || genPos.getY() < 255) && canStay)
{
world.setBlockState(genPos, this.bottomState, 2);
world.setBlockState(genPos.up(), this.topState, 2);
}
}
return true;
}
@Override
public void writeToJson(JsonObject json, JsonSerializationContext context)
{
json.addProperty("amount_per_chunk", this.amountPerChunk);
json.add("bottom_state", context.serialize(this.bottomState));
json.add("top_state", context.serialize(this.topState));
json.addProperty("generation_attempts", this.generationAttempts);
}
@Override
public void readFromJson(JsonObject json, JsonDeserializationContext context)
{
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
this.bottomState = GeneratorUtils.deserializeStateNonNull(json, "bottom_state", context);
this.topState = GeneratorUtils.deserializeStateNonNull(json, "top_state", context);
this.generationAttempts = json.get("generation_attempts").getAsInt();
}
}