use of org.spongepowered.api.util.weighted.WeightedObject in project SpongeCommon by SpongePowered.
the class MixinBiomeTaiga method buildPopulators.
@Override
public void buildPopulators(World world, SpongeBiomeGenerationSettings gensettings) {
if (this.type == BiomeTaiga.Type.MEGA || this.type == BiomeTaiga.Type.MEGA_SPRUCE) {
BlockBlob blob = BlockBlob.builder().blobCount(VariableAmount.baseWithRandomAddition(0, 3)).block((BlockState) Blocks.MOSSY_COBBLESTONE.getDefaultState()).radius(VariableAmount.baseWithRandomAddition(0, 2)).build();
gensettings.getPopulators().add(blob);
}
DoublePlant fern = DoublePlant.builder().type(DoublePlantTypes.FERN, 1).perChunk(7 * 5).build();
gensettings.getPopulators().add(fern);
super.buildPopulators(world, gensettings);
if (this.type == BiomeTaiga.Type.MEGA || this.type == BiomeTaiga.Type.MEGA_SPRUCE) {
gensettings.getGroundCoverLayers().clear();
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((Double seed) -> {
if (seed > 1.75D) {
return (BlockState) Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT);
} else if (seed > -0.95D) {
return (BlockState) Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.PODZOL);
}
return (BlockState) Blocks.GRASS.getDefaultState();
}, WorldGenConstants.GROUND_COVER_DEPTH));
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((BlockState) this.fillerBlock, WorldGenConstants.GROUND_COVER_DEPTH));
}
BiomeDecorator theBiomeDecorator = this.decorator;
for (Iterator<Shrub> it = gensettings.getPopulators(Shrub.class).iterator(); it.hasNext(); ) {
Shrub next = it.next();
if (next.getTypes().size() == 1) {
TableEntry<ShrubType> entry = next.getTypes().getEntries().get(0);
if (entry instanceof WeightedObject && ((WeightedObject<ShrubType>) entry).get() == ShrubTypes.TALL_GRASS) {
it.remove();
}
}
}
Shrub grass = Shrub.builder().perChunk(theBiomeDecorator.grassPerChunk * 128).type(ShrubTypes.FERN, 4).type(ShrubTypes.TALL_GRASS, 1).build();
gensettings.getPopulators().add(grass);
gensettings.getPopulators().removeAll(gensettings.getPopulators(Forest.class));
Forest.Builder forest = Forest.builder();
forest.perChunk(VariableAmount.baseWithOptionalAddition(theBiomeDecorator.treesPerChunk, 1, 0.1));
if (this.type == BiomeTaiga.Type.MEGA || this.type == BiomeTaiga.Type.MEGA_SPRUCE) {
if (this.type == BiomeTaiga.Type.MEGA) {
forest.type(BiomeTreeTypes.POINTY_TAIGA.getLargePopulatorObject().get(), 1);
forest.type(BiomeTreeTypes.TALL_TAIGA.getLargePopulatorObject().get(), 12);
} else {
forest.type(BiomeTreeTypes.TALL_TAIGA.getLargePopulatorObject().get(), 13);
}
forest.type(BiomeTreeTypes.POINTY_TAIGA.getPopulatorObject(), 26 / 3d);
forest.type(BiomeTreeTypes.TALL_TAIGA.getPopulatorObject(), 52 / 3d);
} else {
forest.type(BiomeTreeTypes.POINTY_TAIGA.getPopulatorObject(), 1);
forest.type(BiomeTreeTypes.TALL_TAIGA.getPopulatorObject(), 2);
}
gensettings.getPopulators().add(0, forest.build());
}
use of org.spongepowered.api.util.weighted.WeightedObject in project SpongeCommon by SpongePowered.
the class SpawnerUtils method setEntities.
@SuppressWarnings("unchecked")
public static void setEntities(MobSpawnerBaseLogic logic, WeightedTable<EntityArchetype> table) {
logic.potentialSpawns.clear();
for (TableEntry<EntityArchetype> entry : table) {
if (!(entry instanceof WeightedObject)) {
continue;
}
WeightedObject<EntityArchetype> object = (WeightedObject<EntityArchetype>) entry;
NBTTagCompound compound = NbtTranslator.getInstance().translateData(object.get().getEntityData());
if (!compound.hasKey(NbtDataUtil.ENTITY_TYPE_ID)) {
final ResourceLocation key = EntityList.getKey((Class<? extends Entity>) object.get().getType().getEntityClass());
compound.setString(NbtDataUtil.ENTITY_TYPE_ID, key != null ? key.toString() : "");
}
logic.potentialSpawns.add(new WeightedSpawnerEntity((int) entry.getWeight(), compound));
}
}
use of org.spongepowered.api.util.weighted.WeightedObject in project SpongeCommon by SpongePowered.
the class MixinBiomeJungle method buildPopulators.
@Override
public void buildPopulators(World world, SpongeBiomeGenerationSettings gensettings) {
super.buildPopulators(world, gensettings);
BiomeDecorator theBiomeDecorator = this.decorator;
for (Iterator<Populator> it = gensettings.getPopulators().iterator(); it.hasNext(); ) {
Populator next = it.next();
if (next instanceof Shrub) {
Shrub s = (Shrub) next;
if (s.getTypes().size() == 1) {
TableEntry<ShrubType> entry = s.getTypes().getEntries().get(0);
if (entry instanceof WeightedObject && ((WeightedObject<ShrubType>) entry).get() == ShrubTypes.TALL_GRASS) {
it.remove();
}
}
}
}
Shrub grass = Shrub.builder().perChunk(theBiomeDecorator.grassPerChunk * 128).type(ShrubTypes.FERN, 1).type(ShrubTypes.TALL_GRASS, 3).build();
gensettings.getPopulators().add(grass);
Melon melon = Melon.builder().perChunk(64).build();
gensettings.getPopulators().add(melon);
Vine vine = Vine.builder().perChunk(50).build();
gensettings.getPopulators().add(vine);
gensettings.getPopulators().removeAll(gensettings.getPopulators(Forest.class));
Forest.Builder forest = Forest.builder();
forest.perChunk(VariableAmount.baseWithOptionalAddition(theBiomeDecorator.treesPerChunk, 1, 0.1));
forest.type(BiomeTreeTypes.OAK.getLargePopulatorObject().get(), 1);
forest.type(BiomeTreeTypes.JUNGLE_BUSH.getPopulatorObject(), 4.5);
if (!this.isEdge) {
forest.type(BiomeTreeTypes.JUNGLE.getLargePopulatorObject().get(), 1.2);
forest.type(BiomeTreeTypes.JUNGLE.getPopulatorObject(), 3);
} else {
forest.type(BiomeTreeTypes.JUNGLE.getPopulatorObject(), 4.5);
}
gensettings.getPopulators().add(0, forest.build());
}
use of org.spongepowered.api.util.weighted.WeightedObject in project SpongeCommon by SpongePowered.
the class MixinWorldGenDoublePlant method generate.
/**
* @author Deamon - December 12th, 2015
*
* @reason Completely changes the method to leverage the WeightedTable
* types. This method was almost completely rewritten.
*/
@Overwrite
public boolean generate(World worldIn, Random rand, BlockPos position) {
boolean flag = false;
if (this.types.isEmpty()) {
this.types.add(new WeightedObject<DoublePlantType>((DoublePlantType) (Object) this.plantType, 1));
}
for (int i = 0; i < 8; ++i) {
BlockPos next = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));
if (worldIn.isAirBlock(next) && (!worldIn.provider.isNether() || next.getY() < 254) && Blocks.DOUBLE_PLANT.canPlaceBlockAt(worldIn, next)) {
DoublePlantType type = getType(VecHelper.toVector3i(next), rand);
Blocks.DOUBLE_PLANT.placeAt(worldIn, next, (BlockDoublePlant.EnumPlantType) (Object) type, 2);
flag = true;
}
}
return flag;
}
Aggregations