Search in sources :

Example 1 with VoxelSet

use of net.minecraft.util.shape.VoxelSet in project SpoornPink by spoorn.

the class AbstractSPTree method generate.

@Override
public boolean generate(FeatureContext<FC> context) {
    Set<BlockPos> changedTrunkBlocks = Sets.newHashSet();
    Set<BlockPos> changedLeafBlocks = Sets.newHashSet();
    StructureWorldAccess world = context.getWorld();
    boolean generated = generate(changedTrunkBlocks, changedLeafBlocks, world, context.getRandom(), context.getOrigin(), context.getConfig());
    if (!generated || changedTrunkBlocks.isEmpty() && changedLeafBlocks.isEmpty()) {
        return false;
    }
    /**
     * Copy vanilla's from {@link TreeFeature}.
     */
    return BlockBox.encompassPositions(Iterables.concat(changedTrunkBlocks, changedLeafBlocks)).map(box -> {
        VoxelSet voxelSet = placeLogsAndLeaves(world, box, changedTrunkBlocks);
        Structure.updateCorner(world, Block.NOTIFY_ALL, voxelSet, box.getMinX(), box.getMinY(), box.getMinZ());
        return true;
    }).orElse(false);
}
Also used : Iterables(com.google.common.collect.Iterables) Random(java.util.Random) Feature(net.minecraft.world.gen.feature.Feature) ModifiableWorld(net.minecraft.world.ModifiableWorld) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.math.Direction) Properties(net.minecraft.state.property.Properties) Lists(com.google.common.collect.Lists) Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) TreeFeature(net.minecraft.world.gen.feature.TreeFeature) BlockState(net.minecraft.block.BlockState) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) FeatureContext(net.minecraft.world.gen.feature.util.FeatureContext) VoxelSet(net.minecraft.util.shape.VoxelSet) Structure(net.minecraft.structure.Structure) WorldAccess(net.minecraft.world.WorldAccess) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Blocks(net.minecraft.block.Blocks) StructureWorldAccess(net.minecraft.world.StructureWorldAccess) SPTreeConfig(org.spoorn.spoornpink.world.gen.feature.config.SPTreeConfig) Codec(com.mojang.serialization.Codec) BlockBox(net.minecraft.util.math.BlockBox) TestableWorld(net.minecraft.world.TestableWorld) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) VoxelSet(net.minecraft.util.shape.VoxelSet) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Example 2 with VoxelSet

use of net.minecraft.util.shape.VoxelSet in project Biome-Makeover by Lemonszz.

the class WaterTreeFeature method placeLogsAndLeaves.

private VoxelSet placeLogsAndLeaves(WorldAccess world, BlockBox box, Set<BlockPos> logs, Set<BlockPos> leaves) {
    List<Set<BlockPos>> list = Lists.newArrayList();
    VoxelSet voxelSet = new BitSetVoxelSet(box.getBlockCountX(), box.getBlockCountY(), box.getBlockCountZ());
    for (int j = 0; j < 6; ++j) {
        list.add(Sets.newHashSet());
    }
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    Iterator var9 = Lists.newArrayList(leaves).iterator();
    BlockPos blockPos2;
    while (var9.hasNext()) {
        blockPos2 = (BlockPos) var9.next();
        if (box.contains(blockPos2)) {
            voxelSet.set(blockPos2.getX() - box.minX, blockPos2.getY() - box.minY, blockPos2.getZ() - box.minZ, true, true);
        }
    }
    var9 = Lists.newArrayList(logs).iterator();
    while (var9.hasNext()) {
        blockPos2 = (BlockPos) var9.next();
        if (box.contains(blockPos2)) {
            voxelSet.set(blockPos2.getX() - box.minX, blockPos2.getY() - box.minY, blockPos2.getZ() - box.minZ, true, true);
        }
        Direction[] var11 = Direction.values();
        int var12 = var11.length;
        for (int var13 = 0; var13 < var12; ++var13) {
            Direction direction = var11[var13];
            mutable.set(blockPos2, direction);
            if (!logs.contains(mutable)) {
                BlockState blockState = world.getBlockState(mutable);
                if (blockState.contains(Properties.DISTANCE_1_7)) {
                    list.get(0).add(mutable.toImmutable());
                    setBlockStateWithoutUpdatingNeighbors(world, mutable, blockState.with(Properties.DISTANCE_1_7, 1));
                    if (box.contains(mutable)) {
                        voxelSet.set(mutable.getX() - box.minX, mutable.getY() - box.minY, mutable.getZ() - box.minZ, true, true);
                    }
                }
            }
        }
    }
    for (int k = 1; k < 6; ++k) {
        Set<BlockPos> set = list.get(k - 1);
        Set<BlockPos> set2 = list.get(k);
        Iterator var25 = set.iterator();
        while (var25.hasNext()) {
            BlockPos blockPos3 = (BlockPos) var25.next();
            if (box.contains(blockPos3)) {
                voxelSet.set(blockPos3.getX() - box.minX, blockPos3.getY() - box.minY, blockPos3.getZ() - box.minZ, true, true);
            }
            Direction[] var27 = Direction.values();
            int var28 = var27.length;
            for (int var16 = 0; var16 < var28; ++var16) {
                Direction direction2 = var27[var16];
                mutable.set(blockPos3, direction2);
                if (!set.contains(mutable) && !set2.contains(mutable)) {
                    BlockState blockState2 = world.getBlockState(mutable);
                    if (blockState2.contains(Properties.DISTANCE_1_7)) {
                        int l = blockState2.get(Properties.DISTANCE_1_7);
                        if (l > k + 1) {
                            BlockState blockState3 = blockState2.with(Properties.DISTANCE_1_7, k + 1);
                            setBlockStateWithoutUpdatingNeighbors(world, mutable, blockState3);
                            if (box.contains(mutable)) {
                                voxelSet.set(mutable.getX() - box.minX, mutable.getY() - box.minY, mutable.getZ() - box.minZ, true, true);
                            }
                            set2.add(mutable.toImmutable());
                        }
                    }
                }
            }
        }
    }
    return voxelSet;
}
Also used : VoxelSet(net.minecraft.util.shape.VoxelSet) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) VoxelSet(net.minecraft.util.shape.VoxelSet) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) Direction(net.minecraft.util.math.Direction) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet)

Example 3 with VoxelSet

use of net.minecraft.util.shape.VoxelSet in project Biome-Makeover by Lemonszz.

the class WaterTreeFeature method generate.

public final boolean generate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, TreeFeatureConfig treeFeatureConfig) {
    Set<BlockPos> set = Sets.newHashSet();
    Set<BlockPos> set2 = Sets.newHashSet();
    Set<BlockPos> set3 = Sets.newHashSet();
    BlockBox blockBox = BlockBox.empty();
    boolean bl = this.generate(structureWorldAccess, random, blockPos, set, set2, blockBox, treeFeatureConfig);
    if (blockBox.minX <= blockBox.maxX && bl && !set.isEmpty()) {
        if (!treeFeatureConfig.decorators.isEmpty()) {
            List<BlockPos> list = Lists.newArrayList(set);
            List<BlockPos> list2 = Lists.newArrayList(set2);
            list.sort(Comparator.comparingInt(Vec3i::getY));
            list2.sort(Comparator.comparingInt(Vec3i::getY));
            treeFeatureConfig.decorators.forEach((decorator) -> {
                decorator.generate(structureWorldAccess, random, list, list2, set3, blockBox);
            });
        }
        VoxelSet voxelSet = this.placeLogsAndLeaves(structureWorldAccess, blockBox, set, set3);
        Structure.updateCorner(structureWorldAccess, 3, voxelSet, blockBox.minX, blockBox.minY, blockBox.minZ);
        return true;
    } else {
        return false;
    }
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) VoxelSet(net.minecraft.util.shape.VoxelSet) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with VoxelSet

use of net.minecraft.util.shape.VoxelSet in project SpoornPink by spoorn.

the class AbstractSPTree method placeLogsAndLeaves.

/**
 * Copy vanilla's from {@link TreeFeature}.  This updates neighbor block states for the changed blocks and prevents
 * leaves from decaying if they are near logs.
 */
private static VoxelSet placeLogsAndLeaves(WorldAccess world, BlockBox box, Set<BlockPos> trunkPositions) {
    ArrayList<Set<BlockPos>> list = Lists.newArrayList();
    BitSetVoxelSet voxelSet = new BitSetVoxelSet(box.getBlockCountX(), box.getBlockCountY(), box.getBlockCountZ());
    int i = 6;
    for (int j = 0; j < 6; ++j) {
        list.add(Sets.newHashSet());
    }
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    for (BlockPos blockPos : Lists.newArrayList(trunkPositions)) {
        if (box.contains(blockPos)) {
            ((VoxelSet) voxelSet).set(blockPos.getX() - box.getMinX(), blockPos.getY() - box.getMinY(), blockPos.getZ() - box.getMinZ());
        }
        for (Direction direction : Direction.values()) {
            BlockState blockState;
            mutable.set((Vec3i) blockPos, direction);
            if (trunkPositions.contains(mutable) || !(blockState = world.getBlockState(mutable)).contains(Properties.DISTANCE_1_7))
                continue;
            ((Set) list.get(0)).add(mutable.toImmutable());
            setBlockStateWithoutUpdatingNeighbors(world, mutable, (BlockState) blockState.with(Properties.DISTANCE_1_7, 1));
            if (!box.contains(mutable))
                continue;
            ((VoxelSet) voxelSet).set(mutable.getX() - box.getMinX(), mutable.getY() - box.getMinY(), mutable.getZ() - box.getMinZ());
        }
    }
    for (int k = 1; k < 6; ++k) {
        Set<BlockPos> set = list.get(k - 1);
        Set<BlockPos> set2 = list.get(k);
        for (BlockPos blockPos2 : set) {
            if (box.contains(blockPos2)) {
                ((VoxelSet) voxelSet).set(blockPos2.getX() - box.getMinX(), blockPos2.getY() - box.getMinY(), blockPos2.getZ() - box.getMinZ());
            }
            for (Direction direction2 : Direction.values()) {
                int l;
                BlockState blockState2;
                mutable.set((Vec3i) blockPos2, direction2);
                if (set.contains(mutable) || set2.contains(mutable) || !(blockState2 = world.getBlockState(mutable)).contains(Properties.DISTANCE_1_7) || (l = blockState2.get(Properties.DISTANCE_1_7).intValue()) <= k + 1)
                    continue;
                BlockState blockState3 = (BlockState) blockState2.with(Properties.DISTANCE_1_7, k + 1);
                setBlockStateWithoutUpdatingNeighbors(world, mutable, blockState3);
                if (box.contains(mutable)) {
                    ((VoxelSet) voxelSet).set(mutable.getX() - box.getMinX(), mutable.getY() - box.getMinY(), mutable.getZ() - box.getMinZ());
                }
                set2.add(mutable.toImmutable());
            }
        }
    }
    return voxelSet;
}
Also used : BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) VoxelSet(net.minecraft.util.shape.VoxelSet) Set(java.util.Set) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) VoxelSet(net.minecraft.util.shape.VoxelSet) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) Direction(net.minecraft.util.math.Direction)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)4 BitSetVoxelSet (net.minecraft.util.shape.BitSetVoxelSet)4 VoxelSet (net.minecraft.util.shape.VoxelSet)4 BlockState (net.minecraft.block.BlockState)3 Direction (net.minecraft.util.math.Direction)3 Set (java.util.Set)2 BlockBox (net.minecraft.util.math.BlockBox)2 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Codec (com.mojang.serialization.Codec)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 Blocks (net.minecraft.block.Blocks)1 Properties (net.minecraft.state.property.Properties)1 Structure (net.minecraft.structure.Structure)1 Vec3i (net.minecraft.util.math.Vec3i)1 ModifiableWorld (net.minecraft.world.ModifiableWorld)1 StructureWorldAccess (net.minecraft.world.StructureWorldAccess)1