use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class SubstanceFreeze method apply.
@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
IBlockState rootyState = world.getBlockState(rootPos);
BlockRooty dirt = TreeHelper.getRooty(rootyState);
Species species = dirt.getSpecies(rootyState, world, rootPos);
if (species != Species.NULLSPECIES && dirt != null) {
if (world.isRemote) {
TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.FIREWORKS_SPARK, 8);
} else {
dirt.startAnalysis(world, rootPos, new MapSignal(new NodeFreezer(species)));
// destroy the soil life so it can no longer grow
dirt.fertilize(world, rootPos, -15);
}
return Result.successful();
}
return Result.failure();
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class VanillaSaplingEventHandler method onSaplingGrowTree.
// TERRAIN_GEN_BUS
@SubscribeEvent
public void onSaplingGrowTree(SaplingGrowTreeEvent event) {
final World world = event.getWorld();
final BlockPos pos = event.getPos();
final IBlockState blockState = world.getBlockState(pos);
if (!TreeRegistry.saplingReplacers.containsKey(blockState)) {
return;
}
final Species species = TreeRegistry.saplingReplacers.get(blockState);
// Set the block to air so the plantTree function won't automatically fail.
world.setBlockToAir(pos);
event.setResult(Result.DENY);
if (species.isValid()) {
if (BlockDynamicSapling.canSaplingStay(world, species, pos)) {
species.transitionToTree(world, pos);
}
}
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class VanillaSaplingEventHandler method onPlayerPlaceBlock.
// EVENT_BUS
@SubscribeEvent
public void onPlayerPlaceBlock(PlaceEvent event) {
IBlockState blockState = event.getPlacedBlock();
if (!TreeRegistry.saplingReplacers.containsKey(blockState)) {
return;
}
final Species species = TreeRegistry.saplingReplacers.get(blockState);
final World world = event.getWorld();
final BlockPos pos = event.getPos();
// Set the block to air so the plantTree function won't automatically fail.
world.setBlockToAir(pos);
if (!species.plantSapling(world, pos)) {
// If it fails then give a seed back to the player.
ItemUtils.spawnItemStack(world, pos, species.getSeedStack(1));
}
}
use of com.ferreusveritas.dynamictrees.trees.Species 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.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class JsonBiomePropertyApplierSpecies method readSpeciesSelector.
private ISpeciesSelector readSpeciesSelector(JsonObject mainObject) {
JsonElement staticElement = mainObject.get("static");
if (staticElement != null && staticElement.isJsonPrimitive()) {
return createStaticSpeciesSelector(staticElement.getAsString());
}
JsonElement randomElement = mainObject.get("random");
if (randomElement != null && randomElement.isJsonObject()) {
RandomSpeciesSelector rand = new RandomSpeciesSelector();
for (Entry<String, JsonElement> entry : randomElement.getAsJsonObject().entrySet()) {
String speciesName = entry.getKey();
JsonElement speciesElement = entry.getValue();
int weight = 0;
if (speciesElement.isJsonPrimitive() && speciesElement.getAsJsonPrimitive().isNumber()) {
weight = speciesElement.getAsJsonPrimitive().getAsInt();
if (weight > 0) {
if (isDefault(speciesName)) {
rand.add(weight);
} else {
Species species = TreeRegistry.findSpeciesSloppy(speciesName);
if (species != Species.NULLSPECIES) {
rand.add(species, weight);
}
}
}
}
}
if (rand.getSize() > 0) {
return rand;
}
}
return null;
}
Aggregations