Search in sources :

Example 6 with Seed

use of com.ferreusveritas.dynamictrees.items.Seed 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

Seed (com.ferreusveritas.dynamictrees.items.Seed)6 DropCreatorSeed (com.ferreusveritas.dynamictrees.systems.dropcreators.DropCreatorSeed)2 Species (com.ferreusveritas.dynamictrees.trees.Species)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ICellKit (com.ferreusveritas.dynamictrees.api.cells.ICellKit)1 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)1 LeavesProperties (com.ferreusveritas.dynamictrees.blocks.LeavesProperties)1 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 World (net.minecraft.world.World)1 IForgeRegistry (net.minecraftforge.registries.IForgeRegistry)1