use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.
the class BranchDestructionData method convertBranchesToIntArrays.
// /////////////////////////////////////////////////////////
// Branches
// /////////////////////////////////////////////////////////
private int[][] convertBranchesToIntArrays(Map<BlockPos, IExtendedBlockState> branchList) {
int[] relPosData = new int[branchList.size()];
int[] connectionData = new int[branchList.size()];
int[] blockIndexData = new int[branchList.size()];
int index = 0;
// Ensure the origin block is at the first index
IExtendedBlockState origExState = branchList.get(BlockPos.ORIGIN);
if (origExState != null) {
relPosData[index] = encodeBranchesRadiusPos(BlockPos.ORIGIN, (BlockBranch) origExState.getBlock(), origExState);
connectionData[index] = encodeBranchesConnections(origExState);
blockIndexData[index++] = encodeBranchBlocks((BlockBranch) origExState.getBlock());
branchList.remove(BlockPos.ORIGIN);
}
// Encode the remaining blocks
for (Entry<BlockPos, IExtendedBlockState> set : branchList.entrySet()) {
BlockPos relPos = set.getKey();
IExtendedBlockState exState = set.getValue();
Block block = exState.getBlock();
if (block instanceof BlockBranch && bounds.inBounds(relPos)) {
// Place comfortable limits on the system
relPosData[index] = encodeBranchesRadiusPos(relPos, (BlockBranch) block, exState);
connectionData[index] = encodeBranchesConnections(exState);
blockIndexData[index++] = encodeBranchBlocks((BlockBranch) block);
}
}
// Shrink down the arrays
relPosData = Arrays.copyOf(relPosData, index);
connectionData = Arrays.copyOf(connectionData, index);
blockIndexData = Arrays.copyOf(blockIndexData, index);
return new int[][] { relPosData, connectionData, blockIndexData };
}
use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.
the class BranchDestructionData method decodeBranchBlockState.
private IExtendedBlockState decodeBranchBlockState(int encodedRadPos, int encodedConnections, int encodedBlockIndex) {
BlockBranch branch = species.getFamily().getValidBranchBlock(encodedBlockIndex);
if (branch != null) {
int radius = decodeBranchRadius(encodedRadPos);
IBlockState state = branch.getStateForRadius(radius);
if (state instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) state;
for (EnumFacing face : EnumFacing.values()) {
int rad = (encodedConnections >> (face.getIndex() * 5) & 0x1F);
exState = exState.withProperty(BlockBranch.CONNECTIONS[face.getIndex()], MathHelper.clamp(rad, 0, 8));
}
return exState;
}
}
return null;
}
use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenFruit method postGrow.
@Override
public boolean postGrow(World world, BlockPos rootPos, BlockPos treePos, Species species, int soilLife, boolean natural) {
IBlockState blockState = world.getBlockState(treePos);
BlockBranch branch = TreeHelper.getBranch(blockState);
if (branch != null && branch.getRadius(blockState) >= fruitingRadius && natural) {
if (species.seasonalFruitProductionFactor(world, rootPos) > world.rand.nextFloat()) {
NodeFindEnds endFinder = new NodeFindEnds();
TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(endFinder));
List<BlockPos> endPoints = endFinder.getEnds();
int qty = getQuantity(false);
if (!endPoints.isEmpty()) {
for (int i = 0; i < qty; i++) {
BlockPos endPoint = endPoints.get(world.rand.nextInt(endPoints.size()));
addFruit(world, species, rootPos.up(), endPoint, false, true, SafeChunkBounds.ANY);
}
}
}
}
return true;
}
use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.
the class FeatureGenPodzol method postGrow.
@Override
public boolean postGrow(World world, BlockPos rootPos, BlockPos treePos, Species species, int soilLife, boolean natural) {
if (ModConfigs.podzolGen) {
NodeFindEnds endFinder = new NodeFindEnds();
TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(endFinder));
List<BlockPos> endPoints = endFinder.getEnds();
if (!endPoints.isEmpty()) {
Random random = world.rand;
BlockPos pos = endPoints.get(random.nextInt(endPoints.size()));
int x = pos.getX() + random.nextInt(5) - 2;
int z = pos.getZ() + random.nextInt(5) - 2;
final int darkThreshold = 4;
for (int i = 0; i < 32; i++) {
BlockPos offPos = new BlockPos(x, pos.getY() - 1 - i, z);
if (!world.isAirBlock(offPos)) {
Block block = world.getBlockState(offPos).getBlock();
if (block instanceof BlockBranch || block instanceof BlockMushroom || block instanceof BlockLeaves) {
// Skip past Mushrooms and branches on the way down
continue;
} else if (block instanceof BlockFlower || block instanceof BlockTallGrass || block instanceof BlockDoublePlant) {
// Kill Plants
if (world.getLightFor(EnumSkyBlock.SKY, offPos) <= darkThreshold) {
world.setBlockToAir(pos);
}
continue;
} else if (block == Blocks.DIRT || block == Blocks.GRASS) {
// Convert grass or dirt to podzol
if (world.getLightFor(EnumSkyBlock.SKY, offPos.up()) <= darkThreshold) {
world.setBlockState(offPos, ModBlocks.blockStates.podzol);
} else {
spreadPodzol(world, pos);
}
}
break;
}
}
}
}
return true;
}
use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.
the class NodeFruitCocoa method run.
public boolean run(IBlockState blockState, World world, BlockPos pos, EnumFacing fromDir) {
if (!finished) {
int hashCode = CoordUtils.coordHashCode(pos, 1);
if ((hashCode % 97) % 29 == 0) {
BlockBranch branch = TreeHelper.getBranch(blockState);
if (branch != null && branch.getRadius(blockState) == 8) {
int side = (hashCode % 4) + 2;
EnumFacing dir = EnumFacing.getFront(side);
BlockPos deltaPos = pos.offset(dir);
if (world.isAirBlock(deltaPos)) {
IBlockState cocoaState = ModBlocks.blockFruitCocoa.getStateForPlacement(world, deltaPos, dir, 0, 0, 0, 0, null);
world.setBlockState(deltaPos, cocoaState.withProperty(BlockCocoa.AGE, worldGen ? 2 : 0), 2);
}
} else {
finished = true;
}
}
}
return false;
}
Aggregations