Search in sources :

Example 6 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class RedwoodLogic method selectNewDirection.

@Override
public Direction selectNewDirection(GrowthLogicKitConfiguration configuration, DirectionSelectionContext context) {
    final Species species = context.species();
    final GrowSignal signal = context.signal();
    Direction newDir = super.selectNewDirection(configuration, context);
    int signalY = signal.delta.getY();
    int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
    int canopyHeight = species.getLowestBranchHeight() + treeHash % 8 + configuration.get(HEIGHT_OF_CANOPY);
    float bottomSlope = 1 + (treeHash % 10) / (float) 0xFFF;
    if (signal.isInTrunk() && newDir != Direction.UP) {
        // Turned out of trunk
        if (signalY < canopyHeight)
            signal.energy = 3;
        else {
            signal.energy += 2;
            signal.energy /= 3.2f;
            float maxEnergy = Math.max(2, Math.min(8.2f, (signalY - canopyHeight) * bottomSlope));
            signal.energy = Math.min(maxEnergy, signal.energy);
        }
    }
    return newDir;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 7 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class TaperedWitheredOakLogic method populateDirectionProbabilityMap.

@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
    final Species species = context.species();
    final World world = context.world();
    final GrowSignal signal = context.signal();
    final int[] probMap = context.probMap();
    final int radius = context.radius();
    final BlockPos pos = context.pos();
    Direction originDir = signal.dir.getOpposite();
    int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
    // Alter probability map for direction change
    // Down is always disallowed for jungle
    probMap[0] = 0;
    probMap[1] = signal.isInTrunk() ? species.getUpProbability() : 1;
    probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
    int lowestBranch = species.getLowestBranchHeight();
    int height = lowestBranch * 2 + ((treeHash % 7829) % 3);
    if (signal.delta.getY() >= height) {
        probMap[2] = probMap[3] = probMap[4] = // Only allow turns when we aren't in the trunk(or the branch is not a twig)
        probMap[5] = !signal.isInTrunk() || radius > 1 ? 2 : 0;
        // Disable the direction we came from
        probMap[originDir.ordinal()] = 0;
        // Favor current travel direction
        probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
    } else if (signal.delta.getY() == lowestBranch) {
        if (!signal.isInTrunk()) {
            probMap[1] = (signal.energy >= 2) ? 0 : 1;
            probMap[2] = probMap[3] = probMap[4] = probMap[5] = (signal.energy >= 3) ? 0 : 1;
            probMap[originDir.ordinal()] = 1;
        } else {
            int sideHash = treeHash % 16;
            probMap[2] = sideHash % 2 < 1 ? 1 : 0;
            probMap[3] = sideHash % 4 < 2 ? 1 : 0;
            probMap[4] = sideHash % 8 < 4 ? 1 : 0;
            probMap[5] = sideHash < 8 ? 1 : 0;
        }
    }
    // Disable the direction we came from
    probMap[originDir.ordinal()] = 0;
    // Favor current travel direction
    probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
    return probMap;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 8 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class TaperedWitheredOakLogic method selectNewDirection.

@Override
public Direction selectNewDirection(GrowthLogicKitConfiguration configuration, DirectionSelectionContext context) {
    final Species species = context.species();
    final GrowSignal signal = context.signal();
    Direction newDir = super.selectNewDirection(configuration, context);
    if (signal.delta.getY() == species.getLowestBranchHeight() && signal.isInTrunk() && // Turned out of trunk
    newDir != Direction.UP)
        signal.energy = 5;
    return newDir;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 9 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class DiagonalPalmFamily method createBranchBlock.

@Override
protected BranchBlock createBranchBlock() {
    final BasicBranchBlock branch = new BasicBranchBlock(this.getProperties()) {

        @Override
        public GrowSignal growIntoAir(World world, BlockPos pos, GrowSignal signal, int fromRadius) {
            final Species species = signal.getSpecies();
            final DynamicLeavesBlock leaves = species.getLeavesBlock().orElse(null);
            if (leaves != null) {
                if (fromRadius == getFamily().getPrimaryThickness()) {
                    // If we came from a twig (and we're not a stripped branch) then just make some leaves
                    if (isNextToBranch(world, pos, signal.dir.getOpposite())) {
                        signal.success = false;
                        return signal;
                    }
                    signal.success = leaves.growLeavesIfLocationIsSuitable(world, species.getLeavesProperties(), pos.above(), 0);
                    if (signal.success)
                        return leaves.branchOut(world, pos, signal);
                } else {
                    // Otherwise make a proper branch
                    return leaves.branchOut(world, pos, signal);
                }
            } else {
                // If the leaves block is null, the branch grows directly without checking for leaves requirements
                if (isNextToBranch(world, pos, signal.dir.getOpposite())) {
                    signal.success = false;
                    return signal;
                }
                setRadius(world, pos, getFamily().getPrimaryThickness(), null);
                signal.radius = getFamily().getSecondaryThickness();
                signal.success = true;
            }
            return signal;
        }
    };
    if (this.isFireProof())
        branch.setFireSpreadSpeed(0).setFlammability(0);
    return branch;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) BlockPos(net.minecraft.util.math.BlockPos) DynamicLeavesBlock(com.ferreusveritas.dynamictrees.blocks.leaves.DynamicLeavesBlock) World(net.minecraft.world.World) BasicBranchBlock(com.ferreusveritas.dynamictrees.blocks.branches.BasicBranchBlock) Species(com.ferreusveritas.dynamictrees.trees.Species)

Example 10 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.

the class ModRecipes method register.

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void register(RegistryEvent.Register<IRecipe> event) {
    IForgeRegistry<IRecipe> registry = event.getRegistry();
    ModItems.dendroPotion.registerRecipes(registry);
    // Create a dirt bucket from dirt and a bucket
    GameRegistry.addShapelessRecipe(new ResourceLocation(ModConstants.MODID, "dirtbucket"), null, new ItemStack(ModItems.dirtBucket), Ingredient.fromItem(Items.BUCKET), Ingredient.fromItem(Item.getItemFromBlock(Blocks.DIRT)));
    // Create a seed <-> sapling exchange for the 6 vanilla tree types
    for (BlockPlanks.EnumType woodType : BlockPlanks.EnumType.values()) {
        Species species = TreeRegistry.findSpecies(new ResourceLocation(ModConstants.MODID, woodType.getName().replace("_", "")));
        ItemStack saplingStack = new ItemStack(Blocks.SAPLING, 1, woodType.getMetadata());
        ItemStack seedStack = species.getSeedStack(1);
        createDirtBucketExchangeRecipes(saplingStack, seedStack, true);
    }
    // Create an apple seed from an apple and dirt bucket
    if (ModConfigs.enableAppleTrees) {
        createDirtBucketExchangeRecipes(new ItemStack(Items.APPLE), TreeRegistry.findSpecies(new ResourceLocation(ModConstants.MODID, "apple")).getSeedStack(1), false);
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) Species(com.ferreusveritas.dynamictrees.trees.Species) BlockPlanks(net.minecraft.block.BlockPlanks) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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