Search in sources :

Example 1 with ITree

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

the class TileLeaves method readData.

@Override
public void readData(PacketBufferForestry data) throws IOException {
    // this is called instead of super.readData, be careful!
    String speciesUID = data.readString();
    byte leafState = data.readByte();
    isFruitLeaf = (leafState & hasFruitFlag) > 0;
    isPollinatedState = (leafState & isPollinatedFlag) > 0;
    String fruitAlleleUID = null;
    if (isFruitLeaf) {
        fruitAlleleUID = data.readString();
        colourFruits = data.readInt();
    }
    IAllele[] treeTemplate = TreeManager.treeRoot.getTemplate(speciesUID);
    if (treeTemplate != null) {
        if (fruitAlleleUID != null) {
            IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
            if (fruitAllele instanceof IAlleleFruit) {
                treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
            }
        }
        ITree tree = TreeManager.treeRoot.templateAsIndividual(treeTemplate);
        if (isPollinatedState) {
            tree.mate(tree);
        }
        setTree(tree);
        world.markBlockRangeForRenderUpdate(getPos(), getPos());
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) ITree(forestry.api.arboriculture.ITree)

Example 2 with ITree

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

the class TileLeaves method determineFruitColour.

private int determineFruitColour() {
    ITree tree = getTree();
    if (tree == null) {
        tree = TreeDefinition.Cherry.getIndividual();
    }
    ITreeGenome genome = tree.getGenome();
    IFruitProvider fruit = genome.getFruitProvider();
    return fruit.getColour(genome, world, getPos(), getRipeningTime());
}
Also used : ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome) IFruitProvider(forestry.api.arboriculture.IFruitProvider)

Example 3 with ITree

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

the class TileLeaves method onBlockTick.

@Override
public void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    ITree tree = getTree();
    if (tree == null) {
        return;
    }
    ITreeGenome genome = tree.getGenome();
    IAlleleTreeSpecies primary = genome.getPrimary();
    if (!checkedForConversionToDefaultLeaves) {
        if (shouldConvertToDefaultLeaves()) {
            IBlockState defaultLeaves = ModuleArboriculture.getBlocks().getDefaultLeaves(primary.getUID());
            worldIn.setBlockState(getPos(), defaultLeaves);
            return;
        }
        checkedForConversionToDefaultLeaves = true;
    }
    boolean isDestroyed = isDestroyed(tree, damage);
    for (ILeafTickHandler tickHandler : primary.getRoot().getLeafTickHandlers()) {
        if (tickHandler.onRandomLeafTick(tree, world, rand, getPos(), isDestroyed)) {
            return;
        }
    }
    if (isDestroyed) {
        return;
    }
    if (damage > 0) {
        damage--;
    }
    if (hasFruit() && getRipeningTime() < ripeningPeriod) {
        ITreekeepingMode treekeepingMode = TreeManager.treeRoot.getTreekeepingMode(world);
        float sappinessModifier = treekeepingMode.getSappinessModifier(genome, 1f);
        float sappiness = genome.getSappiness() * sappinessModifier;
        if (rand.nextFloat() < sappiness) {
            ripeningTime++;
            sendNetworkUpdateRipening();
        }
    }
    if (caterpillar != null) {
        matureCaterpillar();
    }
    effectData = tree.doEffect(effectData, world, getPos());
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IBlockState(net.minecraft.block.state.IBlockState) ITreekeepingMode(forestry.api.arboriculture.ITreekeepingMode) ILeafTickHandler(forestry.api.arboriculture.ILeafTickHandler) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 4 with ITree

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

the class TileLeaves method mateWith.

@Override
public void mateWith(IIndividual individual) {
    if (individual instanceof ITree) {
        ITree tree = getTree();
        if (tree == null || world == null) {
            return;
        }
        tree.mate((ITree) individual);
        if (!world.isRemote) {
            sendNetworkUpdate();
        }
    }
}
Also used : ITree(forestry.api.arboriculture.ITree)

Example 5 with ITree

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

the class TileLeaves method readFromNBT.

/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    ripeningTime = nbttagcompound.getShort("RT");
    damage = nbttagcompound.getInteger("ENC");
    if (nbttagcompound.hasKey("CATER")) {
        maturationTime = nbttagcompound.getInteger("CATMAT");
        caterpillar = ButterflyManager.butterflyRoot.getMember(nbttagcompound.getCompoundTag("CATER"));
    }
    ITree tree = getTree();
    if (tree != null) {
        setTree(tree);
    }
}
Also used : 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