Search in sources :

Example 21 with Species

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();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) Species(com.ferreusveritas.dynamictrees.trees.Species) NodeFreezer(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFreezer) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 22 with Species

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);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Species(com.ferreusveritas.dynamictrees.trees.Species) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with Species

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));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Species(com.ferreusveritas.dynamictrees.trees.Species) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 24 with Species

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);
					}
				}
			}
		}*/
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) SimpleVoxmap(com.ferreusveritas.dynamictrees.util.SimpleVoxmap) BlockDynamicLeaves(com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) NodeCollector(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector) ILeavesProperties(com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Cell(com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 25 with Species

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;
}
Also used : RandomSpeciesSelector(com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.RandomSpeciesSelector) JsonElement(com.google.gson.JsonElement) Species(com.ferreusveritas.dynamictrees.trees.Species)

Aggregations

Species (com.ferreusveritas.dynamictrees.trees.Species)56 BlockPos (net.minecraft.util.math.BlockPos)24 IBlockState (net.minecraft.block.state.IBlockState)19 ItemStack (net.minecraft.item.ItemStack)12 GrowSignal (com.ferreusveritas.dynamictrees.systems.GrowSignal)9 Direction (net.minecraft.util.Direction)9 ResourceLocation (net.minecraft.util.ResourceLocation)8 World (net.minecraft.world.World)8 TileEntitySpecies (com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)6 EnumFacing (net.minecraft.util.EnumFacing)6 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)5 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)4 ArrayList (java.util.ArrayList)4 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)4 WrongUsageException (net.minecraft.command.WrongUsageException)4 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)3 BlockBonsaiPot (com.ferreusveritas.dynamictrees.blocks.BlockBonsaiPot)3 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)3