Search in sources :

Example 1 with ICellKit

use of com.ferreusveritas.dynamictrees.api.cells.ICellKit in project DynamicTrees by DynamicTreesTeam.

the class LeavesPropertiesJson method resolve.

public void resolve() {
    if (jsonObj != null) {
        for (Entry<String, JsonElement> entry : jsonObj.entrySet()) {
            String key = entry.getKey();
            JsonElement element = entry.getValue();
            if ("color".equals(key)) {
                if (element.isJsonPrimitive()) {
                    colorPrimitive = element.getAsJsonPrimitive();
                }
            } else if ("leaves".equals(key)) {
                if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) {
                    getPrimitiveLeaves(element.getAsString()).assignTo(this);
                } else if (element.isJsonObject()) {
                    getPrimitiveLeaves(element.getAsJsonObject()).assignTo(this);
                }
            } else if ("cellkit".equals(key)) {
                ICellKit kit = TreeRegistry.findCellKit(element.getAsString());
                if (kit != null) {
                    cellKit = kit;
                }
            } else if ("smother".equals(key)) {
                smotherLeavesMax = MathHelper.clamp(element.getAsInt(), 0, 64);
            } else if ("light".equals(key)) {
                lightRequirement = MathHelper.clamp(element.getAsInt(), 0, 15);
            } else if ("connectAny".equals(key)) {
                if (element.isJsonPrimitive()) {
                    connectAnyRadius = element.getAsBoolean();
                }
            } else if ("flammability".equals(key)) {
                if (element.isJsonPrimitive()) {
                    flammability = element.getAsInt();
                }
            } else if ("fireSpreadSpeed".equals(key)) {
                if (element.isJsonPrimitive()) {
                    fireSpreadSpeed = element.getAsInt();
                }
            }
        }
        // Free up json object since it is no longer used
        jsonObj = null;
    }
}
Also used : JsonElement(com.google.gson.JsonElement) ICellKit(com.ferreusveritas.dynamictrees.api.cells.ICellKit)

Example 2 with ICellKit

use of com.ferreusveritas.dynamictrees.api.cells.ICellKit 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

ICellKit (com.ferreusveritas.dynamictrees.api.cells.ICellKit)2 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)1 LeavesProperties (com.ferreusveritas.dynamictrees.blocks.LeavesProperties)1 Seed (com.ferreusveritas.dynamictrees.items.Seed)1 Species (com.ferreusveritas.dynamictrees.trees.Species)1 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)1 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Item (net.minecraft.item.Item)1 IForgeRegistry (net.minecraftforge.registries.IForgeRegistry)1