use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.
the class NodeFreezer method freezeSurroundingLeaves.
// Clumsy hack to freeze leaves
public void freezeSurroundingLeaves(World world, BlockBranch branch, BlockPos twigPos) {
if (!world.isRemote && !world.restoringBlockSnapshots) {
// do not drop items while restoring blockstates, prevents item dupe
TreeFamily tree = branch.getFamily();
IBlockState primLeaves = species.getLeavesProperties().getPrimitiveLeaves();
for (BlockPos leavesPos : BlockPos.getAllInBox(twigPos.add(-3, -3, -3), twigPos.add(3, 3, 3))) {
if (tree.isCompatibleGenericLeaves(world.getBlockState(leavesPos), world, leavesPos)) {
world.setBlockState(leavesPos, primLeaves.withProperty(BlockLeaves.DECAYABLE, false).withProperty(BlockLeaves.CHECK_DECAY, false));
}
}
}
}
use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.
the class BlockDynamicLeaves method branchOut.
public GrowSignal branchOut(World world, BlockPos pos, GrowSignal signal) {
ILeavesProperties leavesProperties = signal.getSpecies().getLeavesProperties();
// Check to be sure the placement for a branch is valid by testing to see if it would first support a leaves block
if (!needLeaves(world, pos, leavesProperties)) {
signal.success = false;
return signal;
}
// Check to see if there's neighboring branches and abort if there's any found.
EnumFacing originDir = signal.dir.getOpposite();
for (EnumFacing dir : EnumFacing.VALUES) {
if (!dir.equals(originDir)) {
if (TreeHelper.isBranch(world.getBlockState(pos.offset(dir)))) {
signal.success = false;
return signal;
}
}
}
boolean hasLeaves = false;
for (EnumFacing dir : EnumFacing.VALUES) {
if (needLeaves(world, pos.offset(dir), leavesProperties)) {
hasLeaves = true;
break;
}
}
if (hasLeaves) {
// Finally set the leaves block to a branch
TreeFamily family = signal.getSpecies().getFamily();
family.getDynamicBranch().setRadius(world, pos, (int) family.getPrimaryThickness(), null);
// For the benefit of the parent branch
signal.radius = family.getSecondaryThickness();
}
signal.success = hasLeaves;
return signal;
}
use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.
the class BlockBranch method destroyLeaves.
/**
* Attempt to destroy all of the leaves on the branch while leaving the other leaves unharmed.
*
* @param world The world
* @param cutPos The position of the block that was initially destroyed
* @param species The species of the tree that is being modified
* @param endPoints The absolute positions of the branch endpoints
* @param destroyedLeaves A map for collecting the positions and blockstates for all of the leaves blocks that will
* be destroyed.
* @param drops A list for collecting the ItemStacks and their positions relative to the cut position
*/
protected void destroyLeaves(World world, BlockPos cutPos, Species species, List<BlockPos> endPoints, Map<BlockPos, IBlockState> destroyedLeaves, List<BlockItemStack> drops) {
if (!world.isRemote && !endPoints.isEmpty()) {
// Make a bounding volume that holds all of the endpoints and expand the volume by 3 blocks for the leaves radius
BlockBounds bounds = new BlockBounds(endPoints).expand(3);
// Create a voxmap to store the leaf destruction map
SimpleVoxmap vmap = new SimpleVoxmap(bounds);
// For each of the endpoints add a 7x7 destruction volume around it
for (BlockPos endPos : endPoints) {
for (BlockPos leafPos : BlockPos.getAllInBoxMutable(endPos.add(-3, -3, -3), endPos.add(3, 3, 3))) {
// Flag this position for destruction
vmap.setVoxel(leafPos, (byte) 1);
}
// We know that the endpoint does not have a leaves block in it because it was a branch
vmap.setVoxel(endPos, (byte) 0);
}
TreeFamily family = species.getFamily();
BlockBranch familyBranch = family.getDynamicBranch();
int primaryThickness = (int) family.getPrimaryThickness();
// Expand the volume yet again by 3 blocks in all directions and search for other non-destroyed endpoints
for (MutableBlockPos findPos : bounds.expand(3).iterate()) {
IBlockState findState = world.getBlockState(findPos);
if (familyBranch.getRadius(findState) == primaryThickness) {
// Search for endpoints of the same tree family
Iterable<MutableBlockPos> leaves = species.getLeavesProperties().getCellKit().getLeafCluster().getAllNonZero();
for (MutableBlockPos leafpos : leaves) {
vmap.setVoxel(findPos.getX() + leafpos.getX(), findPos.getY() + leafpos.getY(), findPos.getZ() + leafpos.getZ(), (byte) 0);
}
}
}
ArrayList<ItemStack> dropList = new ArrayList<ItemStack>();
// Destroy all family compatible leaves
for (Cell cell : vmap.getAllNonZeroCells()) {
MutableBlockPos pos = cell.getPos();
IBlockState state = world.getBlockState(pos);
if (species.isCompatibleLeaves(world, pos, state)) {
dropList.clear();
species.getTreeHarvestDrops(world, pos, dropList, world.rand);
// We are storing this so it must be immutable
BlockPos imPos = pos.toImmutable();
BlockPos relPos = imPos.subtract(cutPos);
// Covertly destroy the leaves on the server side
world.setBlockState(imPos, ModBlocks.blockStates.air, 0);
destroyedLeaves.put(relPos, state);
dropList.forEach(i -> drops.add(new BlockItemStack(i, relPos)));
}
}
}
}
use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.
the class TreeRegistry method getPotionTransformableSpecies.
/**
* @return All species which can be transformed and have their own seed (so should have a potion recipe created).
*/
public static List<Species> getPotionTransformableSpecies() {
final List<Species> speciesList = getTransformableSpecies();
speciesList.removeIf(species -> {
TreeFamily family = species.getFamily();
// Remove the species if its seed not set, or if it's not the common species and its seed is the same as the common species'.
return (species.getSeedStack(1) == null || species.getSeed() == Seed.NULLSEED) || (species != family.getCommonSpecies() && species.getSeed() == family.getCommonSpecies().getSeed());
});
return speciesList;
}
use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.
the class TreeBuilder method build.
/**
* Builds a {@link TreeFamily} according to the specs provided. Called last in the builder chain. Repeated calls can
* be made but be sure to change the Name and Sequence for the tree before creating multiple trees.
*
* @return The newly built {@link TreeFamily}
*/
public TreeFamily build() {
if (name == null) {
System.err.println("Error: Attempted to build an nameless tree");
return TreeFamily.NULLFAMILY;
}
if (seqNum == -1 && dynamicLeavesProperties == null) {
System.err.println("Error: Attempted to build an unsequenced tree(or a tree without dynamic leaves properties)");
return TreeFamily.NULLFAMILY;
}
TreeFamily treeFamily = new TreeFamily(name) {
{
if (dynamicLeavesProperties == null) {
dynamicLeavesProperties = new LeavesProperties(primitiveLeavesBlockState) {
@Override
public int getLightRequirement() {
return dynamicLeavesLightRequirement;
}
public int getSmotherLeavesMax() {
return dynamicLeavesSmotherMax;
}
@Override
public ICellKit getCellKit() {
return TreeRegistry.findCellKit(dynamicLeavesCellKit);
}
};
LeavesPaging.getLeavesBlockForSequence(ModConstants.MODID, seqNum, dynamicLeavesProperties);
}
this.setPrimitiveLog(primitiveLogBlockState);
dynamicLeavesProperties.setTree(this);
if (stickItemStack != null) {
setStick(stickItemStack);
}
}
@Override
public void createSpecies() {
setCommonSpecies(speciesCreator != null ? speciesCreator.create(this) : new Species(name, this, dynamicLeavesProperties));
if (speciesCreateSeed) {
getCommonSpecies().generateSeed();
getCommonSpecies().setupStandardSeedDropping();
}
for (ISpeciesCreator creator : extraSpeciesCreators) {
Species species = creator.create(this);
extraSpecies.put(species.getRegistryName().getResourcePath(), species);
}
}
@Override
public void registerSpecies(IForgeRegistry<Species> speciesRegistry) {
super.registerSpecies(speciesRegistry);
extraSpecies.values().forEach(s -> speciesRegistry.register(s));
}
@Override
public List<Item> getRegisterableItems(List<Item> itemList) {
for (Species species : extraSpecies.values()) {
// Since we generated the species internally we need to let the seed out to be registered.
Seed seed = species.getSeed();
if (seed != Seed.NULLSEED) {
itemList.add(seed);
}
}
return super.getRegisterableItems(itemList);
}
};
return treeFamily;
}
Aggregations