Added flowers to the Origin Valley
This commit is contained in:
parent
8f7c37384f
commit
0020ea25f3
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
package biomesoplenty.api.biome.generation;
|
package biomesoplenty.api.biome.generation;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.minecraft.util.BlockPos;
|
|
||||||
import net.minecraft.util.WeightedRandom;
|
import net.minecraft.util.WeightedRandom;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
|
||||||
public abstract class CustomizableWeightedGenerator extends WeightedRandom.Item implements IGeneratorDelegate
|
public abstract class CustomizableWeightedGenerator extends WeightedRandom.Item implements IGeneratorDelegate
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,18 @@ public abstract class CustomizableWeightedGenerator extends WeightedRandom.Item
|
||||||
throw new RuntimeException("The identifier for " + this.getClass().getCanonicalName() + " cannot be null!");
|
throw new RuntimeException("The identifier for " + this.getClass().getCanonicalName() + " cannot be null!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
json.addProperty("weight", this.itemWeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||||
|
{
|
||||||
|
this.itemWeight = json.get("weight").getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStage(GeneratorStage stage)
|
public void setStage(GeneratorStage stage)
|
||||||
|
|
|
@ -15,6 +15,8 @@ import biomesoplenty.api.biome.BOPBiome;
|
||||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||||
import biomesoplenty.api.block.BOPBlocks;
|
import biomesoplenty.api.block.BOPBlocks;
|
||||||
import biomesoplenty.api.block.BOPTreeEnums.AllTrees;
|
import biomesoplenty.api.block.BOPTreeEnums.AllTrees;
|
||||||
|
import biomesoplenty.common.block.BlockBOPFlower2;
|
||||||
|
import biomesoplenty.common.block.BlockBOPFlower2.FlowerType;
|
||||||
import biomesoplenty.common.block.BlockBOPGrass;
|
import biomesoplenty.common.block.BlockBOPGrass;
|
||||||
import biomesoplenty.common.block.BlockBOPLeaves;
|
import biomesoplenty.common.block.BlockBOPLeaves;
|
||||||
import biomesoplenty.common.block.BlockBOPLeaves2;
|
import biomesoplenty.common.block.BlockBOPLeaves2;
|
||||||
|
@ -22,6 +24,7 @@ import biomesoplenty.common.block.BlockBOPGrass.BOPGrassType;
|
||||||
import biomesoplenty.common.config.MiscConfigurationHandler;
|
import biomesoplenty.common.config.MiscConfigurationHandler;
|
||||||
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
||||||
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
||||||
|
import biomesoplenty.common.world.feature.weighted.GeneratorFlora;
|
||||||
|
|
||||||
public class BiomeGenOriginValley extends BOPBiome
|
public class BiomeGenOriginValley extends BOPBiome
|
||||||
{
|
{
|
||||||
|
@ -42,6 +45,12 @@ public class BiomeGenOriginValley extends BOPBiome
|
||||||
BOPBlocks.leaves_2.getDefaultState().withProperty(BlockBOPLeaves.getVariantProperty(BlockBOPLeaves2.PAGENUM), AllTrees.ORIGIN)));
|
BOPBlocks.leaves_2.getDefaultState().withProperty(BlockBOPLeaves.getVariantProperty(BlockBOPLeaves2.PAGENUM), AllTrees.ORIGIN)));
|
||||||
|
|
||||||
this.addGenerator("trees", GeneratorStage.TREE, treeGenerator);
|
this.addGenerator("trees", GeneratorStage.TREE, treeGenerator);
|
||||||
|
|
||||||
|
GeneratorWeighted flowerGenerator = new GeneratorWeighted(4);
|
||||||
|
flowerGenerator.add(new GeneratorFlora(8, BOPBlocks.flower2.getDefaultState().withProperty(BlockBOPFlower2.VARIANT, FlowerType.ROSE)));
|
||||||
|
flowerGenerator.add(new GeneratorFlora(10, Blocks.yellow_flower.getDefaultState()));
|
||||||
|
|
||||||
|
this.addGenerator("flowers", GeneratorStage.FLOWERS, flowerGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import biomesoplenty.common.world.feature.GeneratorOreCluster;
|
||||||
import biomesoplenty.common.world.feature.GeneratorOreSingle;
|
import biomesoplenty.common.world.feature.GeneratorOreSingle;
|
||||||
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
||||||
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
||||||
|
import biomesoplenty.common.world.feature.weighted.GeneratorFlora;
|
||||||
|
|
||||||
public class ModGenerators
|
public class ModGenerators
|
||||||
{
|
{
|
||||||
|
@ -22,5 +23,6 @@ public class ModGenerators
|
||||||
registerGenerator("ore_cluster", GeneratorOreCluster.class);
|
registerGenerator("ore_cluster", GeneratorOreCluster.class);
|
||||||
registerGenerator("weighted", GeneratorWeighted.class);
|
registerGenerator("weighted", GeneratorWeighted.class);
|
||||||
registerGenerator("basic_tree", GeneratorBasicTree.class);
|
registerGenerator("basic_tree", GeneratorBasicTree.class);
|
||||||
|
registerGenerator("flora", GeneratorFlora.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,14 @@
|
||||||
|
|
||||||
package biomesoplenty.common.util.biome;
|
package biomesoplenty.common.util.biome;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -44,6 +50,25 @@ public class GeneratorUtils
|
||||||
|
|
||||||
return Pair.of(minHeight, maxHeight);
|
return Pair.of(minHeight, maxHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int safeNextInt(Random random, int i)
|
||||||
|
{
|
||||||
|
if (i <= 1) return 0;
|
||||||
|
|
||||||
|
return random.nextInt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IBlockState deserializeStateNonNull(JsonObject json, String memberName, JsonDeserializationContext context)
|
||||||
|
{
|
||||||
|
IBlockState state = context.deserialize(json.get(memberName), IBlockState.class);
|
||||||
|
|
||||||
|
if (state == null)
|
||||||
|
{
|
||||||
|
throw new JsonSyntaxException("Property " + memberName + " doesn't exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isBlockTreeReplacable(Block block)
|
public static boolean isBlockTreeReplacable(Block block)
|
||||||
{
|
{
|
||||||
|
|
|
@ -303,7 +303,8 @@ public class GeneratorBasicTree extends CustomizableWeightedGenerator
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||||
{
|
{
|
||||||
json.addProperty("weight", this.itemWeight);
|
super.writeToJson(json, context);
|
||||||
|
|
||||||
json.addProperty("update_neighbours", this.updateNeighbours);
|
json.addProperty("update_neighbours", this.updateNeighbours);
|
||||||
json.addProperty("min_height", this.minHeight);
|
json.addProperty("min_height", this.minHeight);
|
||||||
json.addProperty("max_height", this.maxHeight);
|
json.addProperty("max_height", this.maxHeight);
|
||||||
|
@ -315,7 +316,8 @@ public class GeneratorBasicTree extends CustomizableWeightedGenerator
|
||||||
@Override
|
@Override
|
||||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||||
{
|
{
|
||||||
this.itemWeight = json.get("weight").getAsInt();
|
super.readFromJson(json, context);
|
||||||
|
|
||||||
this.updateNeighbours = json.get("update_neighbours").getAsBoolean();
|
this.updateNeighbours = json.get("update_neighbours").getAsBoolean();
|
||||||
|
|
||||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.weighted;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import biomesoplenty.api.biome.generation.CustomizableWeightedGenerator;
|
||||||
|
import biomesoplenty.common.block.BlockDecoration;
|
||||||
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
|
||||||
|
public class GeneratorFlora extends CustomizableWeightedGenerator
|
||||||
|
{
|
||||||
|
public IBlockState state;
|
||||||
|
|
||||||
|
public GeneratorFlora() {}
|
||||||
|
|
||||||
|
public GeneratorFlora(int weight, IBlockState state)
|
||||||
|
{
|
||||||
|
super(weight);
|
||||||
|
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scatter(World world, Random random, BlockPos pos, int amountPerChunk)
|
||||||
|
{
|
||||||
|
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, amountPerChunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(World world, Random random, BlockPos pos, int amountPerChunk)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 64; ++i)
|
||||||
|
{
|
||||||
|
BlockPos blockpos1 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
|
||||||
|
|
||||||
|
if (world.isAirBlock(blockpos1) && (!world.provider.getHasNoSky() || blockpos1.getY() < 255) &&
|
||||||
|
(this.state.getBlock() instanceof BlockDecoration ? ((BlockDecoration)this.state.getBlock()).canBlockStay(world, blockpos1, this.state) : this.state.getBlock().canPlaceBlockAt(world, blockpos1)))
|
||||||
|
{
|
||||||
|
world.setBlockState(blockpos1, this.state, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
super.writeToJson(json, context);
|
||||||
|
|
||||||
|
json.add("state", context.serialize(this.state));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||||
|
{
|
||||||
|
super.readFromJson(json, context);
|
||||||
|
|
||||||
|
this.state = GeneratorUtils.deserializeStateNonNull(json, "state", context);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue