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);
}
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;
}
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;
}
}
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;
}
Aggregations