Search in sources :

Example 56 with Species

use of com.ferreusveritas.dynamictrees.trees.Species 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;
}
Also used : LeavesProperties(com.ferreusveritas.dynamictrees.blocks.LeavesProperties) ILeavesProperties(com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties) Item(net.minecraft.item.Item) Seed(com.ferreusveritas.dynamictrees.items.Seed) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) ArrayList(java.util.ArrayList) List(java.util.List) Species(com.ferreusveritas.dynamictrees.trees.Species) ICellKit(com.ferreusveritas.dynamictrees.api.cells.ICellKit)

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