Search in sources :

Example 11 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class TreeAlyzerPlugin method drawAnalyticsPage3.

@SideOnly(Side.CLIENT)
@Override
public void drawAnalyticsPage3(GuiScreen gui, ItemStack itemStack) {
    if (gui instanceof GuiAlyzer) {
        GuiAlyzer guiAlyzer = (GuiAlyzer) gui;
        ITree tree = TreeManager.treeRoot.getMember(itemStack);
        if (tree == null) {
            return;
        }
        TextLayoutHelper textLayout = guiAlyzer.getTextLayout();
        WidgetManager widgetManager = guiAlyzer.getWidgetManager();
        textLayout.startPage(GuiAlyzer.COLUMN_0, GuiAlyzer.COLUMN_1, GuiAlyzer.COLUMN_2);
        textLayout.drawLine(Translator.translateToLocal("for.gui.beealyzer.produce") + ":", GuiAlyzer.COLUMN_0);
        textLayout.newLine();
        int x = GuiAlyzer.COLUMN_0;
        for (ItemStack stack : tree.getProducts().keySet()) {
            widgetManager.add(new ItemStackWidget(widgetManager, x, textLayout.getLineY(), stack));
            x += 18;
            if (x > 148) {
                x = GuiAlyzer.COLUMN_0;
                textLayout.newLine();
            }
        }
        textLayout.newLine();
        textLayout.newLine();
        textLayout.newLine();
        textLayout.newLine();
        textLayout.drawLine(Translator.translateToLocal("for.gui.beealyzer.specialty") + ":", GuiAlyzer.COLUMN_0);
        textLayout.newLine();
        x = GuiAlyzer.COLUMN_0;
        for (ItemStack stack : tree.getSpecialties().keySet()) {
            Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(stack, guiAlyzer.getGuiLeft() + x, guiAlyzer.getGuiTop() + textLayout.getLineY());
            x += 18;
            if (x > 148) {
                x = GuiAlyzer.COLUMN_0;
                textLayout.newLine();
            }
        }
        textLayout.endPage();
    }
}
Also used : TextLayoutHelper(forestry.core.gui.TextLayoutHelper) ItemStackWidget(forestry.core.gui.widgets.ItemStackWidget) WidgetManager(forestry.core.gui.widgets.WidgetManager) ITree(forestry.api.arboriculture.ITree) GuiAlyzer(forestry.core.gui.GuiAlyzer) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 12 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class TreeDecorator method decorateTrees.

public static void decorateTrees(World world, Random rand, int worldX, int worldZ) {
    if (!Config.isValidTreeDim(world.provider.getDimension())) {
        return;
    }
    if (biomeCache.isEmpty()) {
        generateBiomeCache(world, rand);
    }
    for (int tries = 0; tries < 4 + rand.nextInt(2); tries++) {
        int x = worldX + rand.nextInt(16);
        int z = worldZ + rand.nextInt(16);
        BlockPos pos = new BlockPos(x, 0, z);
        Biome biome = world.getBiome(pos);
        Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
        for (ITree tree : trees) {
            IAlleleTreeSpecies species = tree.getGenome().getPrimary();
            if (species.getRarity() >= rand.nextFloat()) {
                pos = getValidPos(world, x, z, tree);
                if (pos == null) {
                    continue;
                }
                if (species.getGrowthProvider().canSpawn(tree, world, pos)) {
                    if (TreeGenHelper.generateTree(tree, world, pos)) {
                        return;
                    }
                }
            }
        }
    }
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) ITree(forestry.api.arboriculture.ITree)

Example 13 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class TreeDecorator method generateBiomeCache.

private static void generateBiomeCache(World world, Random rand) {
    for (IAlleleTreeSpecies species : getSpecies()) {
        IAllele[] template = TreeManager.treeRoot.getTemplate(species);
        ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(template);
        ITree tree = TreeManager.treeRoot.getTree(world, genome);
        IGrowthProvider growthProvider = species.getGrowthProvider();
        for (Biome biome : Biome.REGISTRY) {
            Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
            if (growthProvider.isBiomeValid(tree, biome)) {
                trees.add(tree);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) Biome(net.minecraft.world.biome.Biome) IGrowthProvider(forestry.api.arboriculture.IGrowthProvider) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 14 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class ModuleArboriculture method registerErsatzGenomes.

private static void registerErsatzGenomes() {
    TreeManager.treeRoot.registerTranslator(Blocks.LEAVES, new IBlockTranslator<ITree>() {

        @Nullable
        @Override
        public ITree getIndividualFromObject(IBlockState blockState) {
            if (!blockState.getValue(BlockLeaves.DECAYABLE)) {
                return null;
            }
            switch(blockState.getValue(BlockOldLeaf.VARIANT)) {
                case OAK:
                    return TreeDefinition.Oak.getIndividual();
                case SPRUCE:
                    return TreeDefinition.Spruce.getIndividual();
                case BIRCH:
                    return TreeDefinition.Birch.getIndividual();
                case JUNGLE:
                    return TreeDefinition.Jungle.getIndividual();
            }
            return null;
        }
    });
    TreeManager.treeRoot.registerTranslator(Blocks.LEAVES2, new IBlockTranslator<ITree>() {

        @Nullable
        @Override
        public ITree getIndividualFromObject(IBlockState blockState) {
            if (!blockState.getValue(BlockLeaves.DECAYABLE)) {
                return null;
            }
            switch(blockState.getValue(BlockNewLeaf.VARIANT)) {
                case ACACIA:
                    return TreeDefinition.AcaciaVanilla.getIndividual();
                case DARK_OAK:
                    return TreeDefinition.DarkOak.getIndividual();
            }
            return null;
        }
    });
    TreeManager.treeRoot.registerTranslator(Item.getItemFromBlock(Blocks.SAPLING), new IItemTranslator<ITree>() {

        @Nullable
        @Override
        public ITree getIndividualFromObject(ItemStack itemStack) {
            switch(itemStack.getMetadata()) {
                case 0:
                    return TreeDefinition.Oak.getIndividual();
                case 1:
                    return TreeDefinition.Spruce.getIndividual();
                case 2:
                    return TreeDefinition.Birch.getIndividual();
                case 3:
                    return TreeDefinition.Jungle.getIndividual();
                case 4:
                    return TreeDefinition.AcaciaVanilla.getIndividual();
                case 5:
                    return TreeDefinition.DarkOak.getIndividual();
            }
            return null;
        }
    });
    for (BlockDefaultLeaves leaves : getBlocks().leavesDefault) {
        TreeManager.treeRoot.registerTranslator(leaves, (IBlockTranslator<IIndividual>) blockState -> {
            TreeDefinition treeDefinition = leaves.getTreeDefinition(blockState);
            if (treeDefinition != null) {
                return treeDefinition.getIndividual();
            } else {
                return null;
            }
        });
    }
}
Also used : IWoodType(forestry.api.arboriculture.IWoodType) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) Arrays(java.util.Arrays) ForestryModule(forestry.api.modules.ForestryModule) BlockRegistryArboriculture(forestry.arboriculture.blocks.BlockRegistryArboriculture) NullStorage(forestry.core.capabilities.NullStorage) Item(net.minecraft.item.Item) PacketRegistryArboriculture(forestry.arboriculture.network.PacketRegistryArboriculture) EnumHand(net.minecraft.util.EnumHand) CapabilityManager(net.minecraftforge.common.capabilities.CapabilityManager) IPacketRegistry(forestry.core.network.IPacketRegistry) Random(java.util.Random) TreeDecorator(forestry.arboriculture.worldgen.TreeDecorator) IMCUtil(forestry.core.utils.IMCUtil) ITree(forestry.api.arboriculture.ITree) BlockDefaultLeaves(forestry.arboriculture.blocks.BlockDefaultLeaves) IArmorNaturalist(forestry.api.core.IArmorNaturalist) Config(forestry.core.config.Config) Block(net.minecraft.block.Block) OreDictionary(net.minecraftforge.oredict.OreDictionary) Side(net.minecraftforge.fml.relauncher.Side) BlockArbLog(forestry.arboriculture.blocks.BlockArbLog) WoodTextureManager(forestry.arboriculture.models.WoodTextureManager) SidedProxy(net.minecraftforge.fml.common.SidedProxy) WoodBlockKind(forestry.api.arboriculture.WoodBlockKind) CommandTree(forestry.arboriculture.commands.CommandTree) BlockNewLeaf(net.minecraft.block.BlockNewLeaf) IBlockTranslator(forestry.api.genetics.IBlockTranslator) BlockEvent(net.minecraftforge.event.world.BlockEvent) AlleleFruits(forestry.arboriculture.genetics.alleles.AlleleFruits) RecipeUtil(forestry.core.recipes.RecipeUtil) Set(java.util.Set) TreeRoot(forestry.arboriculture.genetics.TreeRoot) BlockLeaves(net.minecraft.block.BlockLeaves) List(java.util.List) ArmorNaturalist(forestry.arboriculture.capabilities.ArmorNaturalist) ItemStackUtil(forestry.core.utils.ItemStackUtil) BlankForestryModule(forestry.modules.BlankForestryModule) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Entry(java.util.Map.Entry) EnumVanillaWoodType(forestry.api.arboriculture.EnumVanillaWoodType) TileFruitPod(forestry.arboriculture.tiles.TileFruitPod) IIndividual(forestry.api.genetics.IIndividual) BlockForestryLeaves(forestry.arboriculture.blocks.BlockForestryLeaves) ItemRegistryArboriculture(forestry.arboriculture.items.ItemRegistryArboriculture) ItemRegistryCore(forestry.core.items.ItemRegistryCore) Blocks(net.minecraft.init.Blocks) RecipeManagers(forestry.api.recipes.RecipeManagers) ProxyArboriculture(forestry.arboriculture.proxy.ProxyArboriculture) VillagerTradeLists(forestry.core.utils.VillagerTradeLists) TileSapling(forestry.arboriculture.tiles.TileSapling) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) TreeMutationFactory(forestry.arboriculture.genetics.TreeMutationFactory) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ProxyArboricultureClient(forestry.arboriculture.proxy.ProxyArboricultureClient) TextureManagerForestry(forestry.core.render.TextureManagerForestry) IItemTranslator(forestry.api.genetics.IItemTranslator) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) EnumForestryWoodType(forestry.api.arboriculture.EnumForestryWoodType) Nullable(javax.annotation.Nullable) IMCMessage(net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage) ICrateRegistry(forestry.api.storage.ICrateRegistry) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) TreeFactory(forestry.arboriculture.genetics.TreeFactory) ItemGrafter(forestry.arboriculture.items.ItemGrafter) EnumFruit(forestry.core.items.ItemFruit.EnumFruit) TileLeaves(forestry.arboriculture.tiles.TileLeaves) StorageManager(forestry.api.storage.StorageManager) Items(net.minecraft.init.Items) World(net.minecraft.world.World) ForestryModuleUids(forestry.modules.ForestryModuleUids) TreeManager(forestry.api.arboriculture.TreeManager) AlleleLeafEffects(forestry.arboriculture.genetics.alleles.AlleleLeafEffects) BlockOldLeaf(net.minecraft.block.BlockOldLeaf) ModuleCore(forestry.core.ModuleCore) TreekeepingMode(forestry.arboriculture.genetics.TreekeepingMode) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Fluids(forestry.core.fluids.Fluids) ForestryAPI(forestry.api.core.ForestryAPI) Constants(forestry.core.config.Constants) ModuleManager(forestry.modules.ModuleManager) AlleleManager(forestry.api.genetics.AlleleManager) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) Preconditions(com.google.common.base.Preconditions) VillagerRegistry(net.minecraftforge.fml.common.registry.VillagerRegistry) EnumGermlingType(forestry.api.arboriculture.EnumGermlingType) TreeDefinition(forestry.arboriculture.genetics.TreeDefinition) TreeBranchDefinition(forestry.arboriculture.genetics.TreeBranchDefinition) Collections(java.util.Collections) EntityVillager(net.minecraft.entity.passive.EntityVillager) TextureLeaves(forestry.arboriculture.models.TextureLeaves) IBlockState(net.minecraft.block.state.IBlockState) IIndividual(forestry.api.genetics.IIndividual) ITree(forestry.api.arboriculture.ITree) TreeDefinition(forestry.arboriculture.genetics.TreeDefinition) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable) BlockDefaultLeaves(forestry.arboriculture.blocks.BlockDefaultLeaves)

Example 15 with ITree

use of forestry.api.arboriculture.ITree in project ForestryMC by ForestryMC.

the class BlockForestryLeaves method getLeafDrop.

@Override
protected void getLeafDrop(NonNullList<ItemStack> drops, World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune) {
    TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class);
    if (tile == null) {
        return;
    }
    ITree tree = tile.getTree();
    if (tree == null) {
        return;
    }
    // Add saplings
    List<ITree> saplings = tree.getSaplings(world, playerProfile, pos, saplingModifier);
    for (ITree sapling : saplings) {
        if (sapling != null) {
            drops.add(TreeManager.treeRoot.getMemberStack(sapling, EnumGermlingType.SAPLING));
        }
    }
    // Add fruits
    if (tile.hasFruit()) {
        drops.addAll(tree.produceStacks(world, pos, tile.getRipeningTime()));
    }
}
Also used : TileLeaves(forestry.arboriculture.tiles.TileLeaves) ITree(forestry.api.arboriculture.ITree)

Aggregations

ITree (forestry.api.arboriculture.ITree)33 ItemStack (net.minecraft.item.ItemStack)9 ITreeGenome (forestry.api.arboriculture.ITreeGenome)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)4 IFruitProvider (forestry.api.arboriculture.IFruitProvider)4 IAllele (forestry.api.genetics.IAllele)4 EnumGermlingType (forestry.api.arboriculture.EnumGermlingType)3 IAlleleFruit (forestry.api.arboriculture.IAlleleFruit)3 TileSapling (forestry.arboriculture.tiles.TileSapling)3 GuiAlyzer (forestry.core.gui.GuiAlyzer)3 TextLayoutHelper (forestry.core.gui.TextLayoutHelper)3 TileLeaves (forestry.arboriculture.tiles.TileLeaves)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 IBlockState (net.minecraft.block.state.IBlockState)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 BlockPos (net.minecraft.util.math.BlockPos)2 Biome (net.minecraft.world.biome.Biome)2 WorldGenerator (net.minecraft.world.gen.feature.WorldGenerator)2