use of com.ferreusveritas.dynamictrees.util.SimpleVoxmap in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenHugeMushroom method generate.
@Override
public boolean generate(World world, BlockPos rootPos, Species species, Biome biome, Random random, int radius, SafeChunkBounds safeBounds) {
BlockPos genPos = rootPos.up();
int height = getMushroomHeight(world, rootPos, biome, random, radius, safeBounds);
IBlockState soilState = world.getBlockState(rootPos);
if (species.isAcceptableSoilForWorldgen(world, rootPos, soilState)) {
Block mushroomBlock = this.mushroomType;
if (mushroomBlock == null) {
mushroomBlock = random.nextBoolean() ? Blocks.BROWN_MUSHROOM_BLOCK : Blocks.RED_MUSHROOM_BLOCK;
}
SimpleVoxmap capMap = getCapForHeight(mushroomBlock, height);
// Determine the cap position(top block of mushroom cap)
BlockPos capPos = genPos.up(height - 1);
// Get a bounding box for the entire cap
BlockBounds capBounds = capMap.getBounds().move(capPos);
if (safeBounds.inBounds(capBounds, true)) {
// Check if there's room for a mushroom cap and stem
for (MutableBlockPos mutPos : Iterables.concat(BlockPos.getAllInBoxMutable(BlockPos.ORIGIN.down(capMap.getLenY()), BlockPos.ORIGIN.down(height - 1)), capMap.getAllNonZero())) {
// System.out.println(mutPos);
BlockPos dPos = mutPos.add(capPos);
IBlockState state = world.getBlockState(dPos);
if (!state.getBlock().canBeReplacedByLeaves(state, world, dPos) || !state.getBlock().isReplaceable(world, dPos)) {
return false;
}
}
// Construct the mushroom cap from the voxel map
for (Cell cell : capMap.getAllNonZeroCells()) {
BlockHugeMushroom.EnumType mushroomType = BlockHugeMushroom.EnumType.byMetadata(cell.getValue());
world.setBlockState(capPos.add(cell.getPos()), mushroomBlock.getDefaultState().withProperty(BlockHugeMushroom.VARIANT, mushroomType));
}
// Construct the stem
int stemLen = height - capMap.getLenY();
IBlockState stemBlock = mushroomBlock.getDefaultState().withProperty(BlockHugeMushroom.VARIANT, BlockHugeMushroom.EnumType.STEM);
for (int y = 0; y < stemLen; y++) {
world.setBlockState(genPos.up(y), stemBlock);
}
return true;
}
}
return false;
}
use of com.ferreusveritas.dynamictrees.util.SimpleVoxmap in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenRoots method startRoots.
public boolean startRoots(World world, BlockPos treePos, Species species, int trunkRadius) {
int hash = CoordUtils.coordHashCode(treePos, 2);
SimpleVoxmap rootMap = rootMaps[hash % rootMaps.length];
nextRoot(world, rootMap, treePos, species, trunkRadius, BlockPos.ORIGIN, 0, -1, null, 0);
return true;
}
use of com.ferreusveritas.dynamictrees.util.SimpleVoxmap in project DynamicTrees by DynamicTreesTeam.
the class JoCode method cleanupFrankentree.
/**
* Attempt to clean up fused trees that have multiple root blocks by simply destroying them both messily
*/
protected void cleanupFrankentree(World world, BlockPos treePos, IBlockState treeState, List<BlockPos> endPoints, SafeChunkBounds safeBounds) {
Set<BlockPos> blocksToDestroy = new HashSet<>();
BlockBranch branch = TreeHelper.getBranch(treeState);
MapSignal signal = new MapSignal(new NodeCollector(blocksToDestroy));
signal.destroyLoopedNodes = false;
signal.trackVisited = true;
branch.analyse(treeState, world, treePos, null, signal);
BlockBranch.destroyMode = EnumDestroyMode.IGNORE;
for (BlockPos pos : blocksToDestroy) {
if (safeBounds.inBounds(pos, false)) {
IBlockState branchState = world.getBlockState(pos);
Optional<BlockBranch> branchBlock = TreeHelper.getBranchOpt(branchState);
if (branchBlock.isPresent()) {
int radius = branchBlock.get().getRadius(branchState);
TreeFamily family = branchBlock.get().getFamily();
Species species = family.getCommonSpecies();
if (family.getPrimaryThickness() == radius) {
ILeavesProperties leavesProperties = species.getLeavesProperties();
if (leavesProperties != LeavesProperties.NULLPROPERTIES) {
SimpleVoxmap leafCluster = leavesProperties.getCellKit().getLeafCluster();
if (leafCluster != LeafClusters.NULLMAP) {
for (Cell cell : leafCluster.getAllNonZeroCells()) {
BlockPos delPos = pos.add(cell.getPos());
if (safeBounds.inBounds(delPos, false)) {
IBlockState leavesState = world.getBlockState(delPos);
if (TreeHelper.isLeaves(leavesState)) {
BlockDynamicLeaves leavesBlock = (BlockDynamicLeaves) leavesState.getBlock();
if (leavesProperties.getTree() == leavesBlock.getProperties(leavesState).getTree()) {
world.setBlockState(delPos, ModBlocks.blockStates.air, 2);
}
}
}
}
}
}
}
world.setBlockState(pos, ModBlocks.blockStates.air, 2);
}
}
}
BlockBranch.destroyMode = EnumDestroyMode.HARVEST;
// Now wreck out all surrounding leaves. Let them grow back naturally.
/*if(!endPoints.isEmpty()) {
BlockBounds bounds = new BlockBounds(endPoints);
bounds.expand(3);
for(BlockPos pos : bounds.iterate()) {
if(safeBounds.inBounds(pos, false)) {
if(TreeHelper.isLeaves(world.getBlockState(pos))) {
world.setBlockState(pos, ModBlocks.blockStates.air, 2);
}
}
}
}*/
}
use of com.ferreusveritas.dynamictrees.util.SimpleVoxmap in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenUndergrowth method postGeneration.
@Override
public boolean postGeneration(World world, BlockPos rootPos, Species species, Biome biome, int radius, List<BlockPos> endPoints, SafeChunkBounds safeBounds, IBlockState initialDirtState) {
if (safeBounds != SafeChunkBounds.ANY && radius > 2) {
// worldgen
Vec3d vTree = new Vec3d(rootPos).addVector(0.5, 0.5, 0.5);
for (int i = 0; i < 2; i++) {
int rad = MathHelper.clamp(world.rand.nextInt(radius - 2) + 2, 2, radius - 1);
Vec3d v = vTree.add(new Vec3d(1, 0, 0).scale(rad).rotateYaw((float) (world.rand.nextFloat() * Math.PI * 2)));
BlockPos vPos = new BlockPos(v);
if (!safeBounds.inBounds(vPos, true)) {
continue;
}
BlockPos pos = CoordUtils.findGround(world, vPos);
IBlockState soilBlockState = world.getBlockState(pos);
if (species.isAcceptableSoil(world, pos, soilBlockState)) {
int type = world.rand.nextInt(2);
world.setBlockState(pos, Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, type == 0 ? BlockPlanks.EnumType.OAK : BlockPlanks.EnumType.JUNGLE));
pos = pos.up(world.rand.nextInt(3));
IBlockState leavesState = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, type == 0 ? BlockPlanks.EnumType.OAK : BlockPlanks.EnumType.JUNGLE).withProperty(BlockOldLeaf.CHECK_DECAY, Boolean.valueOf(false));
SimpleVoxmap leafMap = species.getLeavesProperties().getCellKit().getLeafCluster();
MutableBlockPos leafPos = new MutableBlockPos();
for (MutableBlockPos dPos : leafMap.getAllNonZero()) {
leafPos.setPos(pos.getX() + dPos.getX(), pos.getY() + dPos.getY(), pos.getZ() + dPos.getZ());
if (safeBounds.inBounds(leafPos, true) && (CoordUtils.coordHashCode(leafPos, 0) % 5) != 0 && world.getBlockState(leafPos).getBlock().isReplaceable(world, leafPos)) {
world.setBlockState(leafPos, leavesState);
}
}
}
}
return true;
}
return false;
}
use of com.ferreusveritas.dynamictrees.util.SimpleVoxmap in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenBush method commonGen.
protected void commonGen(World world, BlockPos rootPos, Species species, Random random, int radius, SafeChunkBounds safeBounds) {
if (radius <= 2) {
return;
}
Vec3d vTree = new Vec3d(rootPos).addVector(0.5, 0.5, 0.5);
for (int i = 0; i < 2; i++) {
int rad = MathHelper.clamp(world.rand.nextInt(radius - 2) + 2, 2, radius - 1);
Vec3d v = vTree.add(new Vec3d(1, 0, 0).scale(rad).rotateYaw((float) (random.nextFloat() * Math.PI * 2)));
BlockPos vPos = new BlockPos(v);
if (!safeBounds.inBounds(vPos, true)) {
continue;
}
BlockPos pos = CoordUtils.findGround(world, vPos);
IBlockState soilBlockState = world.getBlockState(pos);
pos = pos.up();
if (!world.getBlockState(pos).getMaterial().isLiquid() && species.isAcceptableSoil(world, pos, soilBlockState)) {
world.setBlockState(pos, logState);
SimpleVoxmap leafMap = LeafClusters.bush;
MutableBlockPos leafPos = new MutableBlockPos();
for (MutableBlockPos dPos : leafMap.getAllNonZero()) {
leafPos.setPos(pos.getX() + dPos.getX(), pos.getY() + dPos.getY(), pos.getZ() + dPos.getZ());
if (safeBounds.inBounds(leafPos, true) && (coordHashCode(leafPos) % 5) != 0 && world.getBlockState(leafPos).getBlock().isReplaceable(world, leafPos)) {
world.setBlockState(leafPos, (secondaryLeavesState == null || random.nextInt(4) != 0) ? leavesState : secondaryLeavesState);
}
}
}
}
}
Aggregations