Search in sources :

Example 1 with TreeFamily

use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.

the class BlockBranchBasic method getHydrationCell.

// /////////////////////////////////////////
// GROWTH
// /////////////////////////////////////////
@Override
public ICell getHydrationCell(IBlockAccess world, BlockPos pos, IBlockState state, EnumFacing dir, ILeavesProperties leavesProperties) {
    TreeFamily thisTree = getFamily();
    if (leavesProperties.getTree() == thisTree) {
        // The requesting leaves must match the tree for hydration to occur
        int radiusAndMeta = thisTree.getRadiusForCellKit(world, pos, state, dir, this);
        int radius = CellMetadata.getRadius(radiusAndMeta);
        int metadata = CellMetadata.getMeta(radiusAndMeta);
        return leavesProperties.getCellKit().getCellForBranch(radius, metadata);
    } else {
        return CellNull.NULLCELL;
    }
}
Also used : TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily)

Example 2 with TreeFamily

use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.

the class ClientProxy method registerModels.

@Override
public void registerModels() {
    // Resolve all leaves properties so the LeavesStateMapper can function properly
    LeavesPropertiesJson.resolveAll();
    // BLOCKS
    ModelLoader.setCustomStateMapper(ModBlocks.blockRootyDirt, new StateMap.Builder().ignore(BlockRooty.LIFE).build());
    ModelLoader.setCustomStateMapper(ModBlocks.blockRootyDirtSpecies, new StateMap.Builder().ignore(BlockRooty.LIFE).build());
    ModelLoader.setCustomStateMapper(ModBlocks.blockRootySand, new StateMap.Builder().ignore(BlockRooty.LIFE).build());
    // Register Potion Mesher
    for (DendroPotion.DendroPotionType type : DendroPotion.DendroPotionType.values()) {
        ModelHelper.regModel(ModItems.dendroPotion, type.getIndex());
    }
    // Register DirtBucket Mesher
    ModelHelper.regModel(ModItems.dirtBucket);
    // Register Woodland Staff Mesher
    ModelHelper.regModel(ModItems.treeStaff);
    // Register Meshers for Branches and Seeds
    for (TreeFamily tree : ModTrees.baseFamilies) {
        // Register Branch itemBlock
        ModelHelper.regModel(tree.getDynamicBranch());
        // Register Seed Item Models
        ModelHelper.regModel(tree.getCommonSpecies().getSeed());
        // Register custom state mapper for branch
        ModelHelper.regModel(tree);
    }
    // Sapling
    ModelHelper.setGenericStateMapper(ModBlocks.blockDynamicSapling, new ModelResourceLocation(new ResourceLocation(ModConstants.MODID, "sapling"), ""));
    // Setup the state mapper for the trunk shell
    ModelLoader.setCustomStateMapper(ModBlocks.blockTrunkShell, new StateMap.Builder().ignore(BlockTrunkShell.COREDIR).build());
    // Register models for cactus
    ModelLoader.setCustomStateMapper(ModTrees.dynamicCactus.getDynamicBranch(), new StateMap.Builder().ignore(BlockBranchCactus.TRUNK, BlockBranchCactus.ORIGIN).build());
    ModelHelper.regModel(ModTrees.dynamicCactus.getDynamicBranch());
    ModelHelper.regModel(ModTrees.dynamicCactus.getCommonSpecies().getSeed());
    // Special seed for apple
    ModelHelper.regModel(Species.REGISTRY.getValue(new ResourceLocation(ModConstants.MODID, "apple")).getSeed());
    // Set state mappers for all blocks created with the LeavesPaging object
    LeavesPaging.setStateMappers();
    // Register the file loader for Branch models
    ModelLoaderRegistry.registerLoader(new ModelLoaderBlockBranchBasic());
    ModelLoaderRegistry.registerLoader(new ModelLoaderBlockBranchCactus());
    ModelLoaderRegistry.registerLoader(new ModelLoaderBlockBranchThick());
    ModelLoaderRegistry.registerLoader(new ModelLoaderBlockSurfaceRoot());
    ModelLoaderRegistry.registerLoader(new ModelLoaderSapling());
}
Also used : DendroPotion(com.ferreusveritas.dynamictrees.items.DendroPotion) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 3 with TreeFamily

use of com.ferreusveritas.dynamictrees.trees.TreeFamily 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 4 with TreeFamily

use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.

the class ClientProxy method discoverWoodColors.

private void discoverWoodColors() {
    Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter = location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
    for (TreeFamily family : Species.REGISTRY.getValuesCollection().stream().map(s -> s.getFamily()).distinct().collect(Collectors.toList())) {
        // For roots
        family.woodColor = 0xFFF1AE;
        if (family != TreeFamily.NULLFAMILY) {
            IBlockState state = family.getPrimitiveLog();
            if (state.getBlock() != Blocks.AIR) {
                IModel model = QuadManipulator.getModelForState(state);
                ResourceLocation resloc = QuadManipulator.getModelTexture(model, bakedTextureGetter, state, EnumFacing.UP);
                if (resloc != null) {
                    PixelBuffer pixbuf = new PixelBuffer(bakedTextureGetter.apply(resloc));
                    int u = pixbuf.w / 16;
                    PixelBuffer center = new PixelBuffer(u * 8, u * 8);
                    pixbuf.blit(center, u * -8, u * -8);
                    family.woodColor = center.averageColor();
                }
            }
        }
    }
}
Also used : com.ferreusveritas.dynamictrees.models.loaders(com.ferreusveritas.dynamictrees.models.loaders) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) Random(java.util.Random) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ColorizerFoliage(net.minecraft.world.ColorizerFoliage) ModelHelper(com.ferreusveritas.dynamictrees.api.client.ModelHelper) TextureGenerationHandler(com.ferreusveritas.dynamictrees.event.TextureGenerationHandler) Block(net.minecraft.block.Block) ModItems(com.ferreusveritas.dynamictrees.ModItems) RenderFallingTree(com.ferreusveritas.dynamictrees.render.RenderFallingTree) ITreePart(com.ferreusveritas.dynamictrees.api.treedata.ITreePart) ModelLoaderRegistry(net.minecraftforge.client.model.ModelLoaderRegistry) Collectors(java.util.stream.Collectors) IModel(net.minecraftforge.client.model.IModel) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) com.ferreusveritas.dynamictrees.blocks(com.ferreusveritas.dynamictrees.blocks) ModTrees(com.ferreusveritas.dynamictrees.ModTrees) Blocks(net.minecraft.init.Blocks) Species(com.ferreusveritas.dynamictrees.trees.Species) Function(java.util.function.Function) ILeavesProperties(com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties) PixelBuffer(com.ferreusveritas.dynamictrees.client.TextureUtils.PixelBuffer) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) ModBlocks(com.ferreusveritas.dynamictrees.ModBlocks) Minecraft(net.minecraft.client.Minecraft) RenderingRegistry(net.minecraftforge.fml.client.registry.RenderingRegistry) FMLPreInitializationEvent(net.minecraftforge.fml.common.event.FMLPreInitializationEvent) FMLInitializationEvent(net.minecraftforge.fml.common.event.FMLInitializationEvent) ModelLoader(net.minecraftforge.client.model.ModelLoader) IBlockAccess(net.minecraft.world.IBlockAccess) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Entity(net.minecraft.entity.Entity) IMimic(com.ferreusveritas.dynamictrees.blocks.MimicProperty.IMimic) DendroPotion(com.ferreusveritas.dynamictrees.items.DendroPotion) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TreeHelper(com.ferreusveritas.dynamictrees.api.TreeHelper) QuadManipulator(com.ferreusveritas.dynamictrees.client.QuadManipulator) ModConstants(com.ferreusveritas.dynamictrees.ModConstants) BlockColors(net.minecraft.client.renderer.color.BlockColors) BlockColorMultipliers(com.ferreusveritas.dynamictrees.client.BlockColorMultipliers) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) BlockBreakAnimationClientHandler(com.ferreusveritas.dynamictrees.event.BlockBreakAnimationClientHandler) ResourceLocation(net.minecraft.util.ResourceLocation) Particle(net.minecraft.client.particle.Particle) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) ModelBakeEventListener(com.ferreusveritas.dynamictrees.event.ModelBakeEventListener) IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) PixelBuffer(com.ferreusveritas.dynamictrees.client.TextureUtils.PixelBuffer) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily)

Example 5 with TreeFamily

use of com.ferreusveritas.dynamictrees.trees.TreeFamily in project DynamicTrees by DynamicTreesTeam.

the class FeatureGenFlareBottom method flareBottom.

/**
 * Put a cute little flare on the bottom of the dark oaks
 *
 * @param world   The world
 * @param rootPos The position of the rooty dirt block of the tree
 * @return The radius of the bottom trunk section after operation
 */
public void flareBottom(World world, BlockPos rootPos, Species species) {
    TreeFamily family = species.getFamily();
    // Put a cute little flare on the bottom of the dark oaks
    int radius3 = TreeHelper.getRadius(world, rootPos.up(3));
    if (radius3 > 6) {
        family.getDynamicBranch().setRadius(world, rootPos.up(2), radius3 + 1, EnumFacing.UP);
        family.getDynamicBranch().setRadius(world, rootPos.up(1), radius3 + 2, EnumFacing.UP);
    }
}
Also used : TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily)

Aggregations

TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)10 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)4 Species (com.ferreusveritas.dynamictrees.trees.Species)4 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 DendroPotion (com.ferreusveritas.dynamictrees.items.DendroPotion)2 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)2 Cell (com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 EnumFacing (net.minecraft.util.EnumFacing)2 ModBlocks (com.ferreusveritas.dynamictrees.ModBlocks)1 ModConstants (com.ferreusveritas.dynamictrees.ModConstants)1 ModItems (com.ferreusveritas.dynamictrees.ModItems)1 ModTrees (com.ferreusveritas.dynamictrees.ModTrees)1 TreeHelper (com.ferreusveritas.dynamictrees.api.TreeHelper)1 ICellKit (com.ferreusveritas.dynamictrees.api.cells.ICellKit)1 ModelHelper (com.ferreusveritas.dynamictrees.api.client.ModelHelper)1 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)1 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)1 com.ferreusveritas.dynamictrees.blocks (com.ferreusveritas.dynamictrees.blocks)1