Search in sources :

Example 1 with WeightedObject

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());
}
Also used : BlockBlob(org.spongepowered.api.world.gen.populator.BlockBlob) ShrubType(org.spongepowered.api.data.type.ShrubType) WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) Shrub(org.spongepowered.api.world.gen.populator.Shrub) GroundCoverLayer(org.spongepowered.api.world.biome.GroundCoverLayer) BiomeDecorator(net.minecraft.world.biome.BiomeDecorator) BlockState(org.spongepowered.api.block.BlockState) Forest(org.spongepowered.api.world.gen.populator.Forest) DoublePlant(org.spongepowered.api.world.gen.populator.DoublePlant)

Example 2 with WeightedObject

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));
    }
}
Also used : WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Example 3 with WeightedObject

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());
}
Also used : ShrubType(org.spongepowered.api.data.type.ShrubType) Vine(org.spongepowered.api.world.gen.populator.Vine) WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) Shrub(org.spongepowered.api.world.gen.populator.Shrub) Forest(org.spongepowered.api.world.gen.populator.Forest) Populator(org.spongepowered.api.world.gen.Populator) BiomeDecorator(net.minecraft.world.biome.BiomeDecorator) Melon(org.spongepowered.api.world.gen.populator.Melon)

Example 4 with WeightedObject

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;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockDoublePlant(net.minecraft.block.BlockDoublePlant) WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) DoublePlantType(org.spongepowered.api.data.type.DoublePlantType) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WeightedObject (org.spongepowered.api.util.weighted.WeightedObject)4 BiomeDecorator (net.minecraft.world.biome.BiomeDecorator)2 ShrubType (org.spongepowered.api.data.type.ShrubType)2 Forest (org.spongepowered.api.world.gen.populator.Forest)2 Shrub (org.spongepowered.api.world.gen.populator.Shrub)2 BlockDoublePlant (net.minecraft.block.BlockDoublePlant)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 WeightedSpawnerEntity (net.minecraft.util.WeightedSpawnerEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockState (org.spongepowered.api.block.BlockState)1 DoublePlantType (org.spongepowered.api.data.type.DoublePlantType)1 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)1 GroundCoverLayer (org.spongepowered.api.world.biome.GroundCoverLayer)1 Populator (org.spongepowered.api.world.gen.Populator)1 BlockBlob (org.spongepowered.api.world.gen.populator.BlockBlob)1 DoublePlant (org.spongepowered.api.world.gen.populator.DoublePlant)1 Melon (org.spongepowered.api.world.gen.populator.Melon)1 Vine (org.spongepowered.api.world.gen.populator.Vine)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1