Search in sources :

Example 11 with BlockBranch

use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.

the class BranchDestructionData method convertBranchesToIntArrays.

// /////////////////////////////////////////////////////////
// Branches
// /////////////////////////////////////////////////////////
private int[][] convertBranchesToIntArrays(Map<BlockPos, IExtendedBlockState> branchList) {
    int[] relPosData = new int[branchList.size()];
    int[] connectionData = new int[branchList.size()];
    int[] blockIndexData = new int[branchList.size()];
    int index = 0;
    // Ensure the origin block is at the first index
    IExtendedBlockState origExState = branchList.get(BlockPos.ORIGIN);
    if (origExState != null) {
        relPosData[index] = encodeBranchesRadiusPos(BlockPos.ORIGIN, (BlockBranch) origExState.getBlock(), origExState);
        connectionData[index] = encodeBranchesConnections(origExState);
        blockIndexData[index++] = encodeBranchBlocks((BlockBranch) origExState.getBlock());
        branchList.remove(BlockPos.ORIGIN);
    }
    // Encode the remaining blocks
    for (Entry<BlockPos, IExtendedBlockState> set : branchList.entrySet()) {
        BlockPos relPos = set.getKey();
        IExtendedBlockState exState = set.getValue();
        Block block = exState.getBlock();
        if (block instanceof BlockBranch && bounds.inBounds(relPos)) {
            // Place comfortable limits on the system
            relPosData[index] = encodeBranchesRadiusPos(relPos, (BlockBranch) block, exState);
            connectionData[index] = encodeBranchesConnections(exState);
            blockIndexData[index++] = encodeBranchBlocks((BlockBranch) block);
        }
    }
    // Shrink down the arrays
    relPosData = Arrays.copyOf(relPosData, index);
    connectionData = Arrays.copyOf(connectionData, index);
    blockIndexData = Arrays.copyOf(blockIndexData, index);
    return new int[][] { relPosData, connectionData, blockIndexData };
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch)

Example 12 with BlockBranch

use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.

the class BranchDestructionData method decodeBranchBlockState.

private IExtendedBlockState decodeBranchBlockState(int encodedRadPos, int encodedConnections, int encodedBlockIndex) {
    BlockBranch branch = species.getFamily().getValidBranchBlock(encodedBlockIndex);
    if (branch != null) {
        int radius = decodeBranchRadius(encodedRadPos);
        IBlockState state = branch.getStateForRadius(radius);
        if (state instanceof IExtendedBlockState) {
            IExtendedBlockState exState = (IExtendedBlockState) state;
            for (EnumFacing face : EnumFacing.values()) {
                int rad = (encodedConnections >> (face.getIndex() * 5) & 0x1F);
                exState = exState.withProperty(BlockBranch.CONNECTIONS[face.getIndex()], MathHelper.clamp(rad, 0, 8));
            }
            return exState;
        }
    }
    return null;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch)

Example 13 with BlockBranch

use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.

the class FeatureGenFruit method postGrow.

@Override
public boolean postGrow(World world, BlockPos rootPos, BlockPos treePos, Species species, int soilLife, boolean natural) {
    IBlockState blockState = world.getBlockState(treePos);
    BlockBranch branch = TreeHelper.getBranch(blockState);
    if (branch != null && branch.getRadius(blockState) >= fruitingRadius && natural) {
        if (species.seasonalFruitProductionFactor(world, rootPos) > world.rand.nextFloat()) {
            NodeFindEnds endFinder = new NodeFindEnds();
            TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(endFinder));
            List<BlockPos> endPoints = endFinder.getEnds();
            int qty = getQuantity(false);
            if (!endPoints.isEmpty()) {
                for (int i = 0; i < qty; i++) {
                    BlockPos endPoint = endPoints.get(world.rand.nextInt(endPoints.size()));
                    addFruit(world, species, rootPos.up(), endPoint, false, true, SafeChunkBounds.ANY);
                }
            }
        }
    }
    return true;
}
Also used : NodeFindEnds(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 14 with BlockBranch

use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.

the class FeatureGenPodzol method postGrow.

@Override
public boolean postGrow(World world, BlockPos rootPos, BlockPos treePos, Species species, int soilLife, boolean natural) {
    if (ModConfigs.podzolGen) {
        NodeFindEnds endFinder = new NodeFindEnds();
        TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(endFinder));
        List<BlockPos> endPoints = endFinder.getEnds();
        if (!endPoints.isEmpty()) {
            Random random = world.rand;
            BlockPos pos = endPoints.get(random.nextInt(endPoints.size()));
            int x = pos.getX() + random.nextInt(5) - 2;
            int z = pos.getZ() + random.nextInt(5) - 2;
            final int darkThreshold = 4;
            for (int i = 0; i < 32; i++) {
                BlockPos offPos = new BlockPos(x, pos.getY() - 1 - i, z);
                if (!world.isAirBlock(offPos)) {
                    Block block = world.getBlockState(offPos).getBlock();
                    if (block instanceof BlockBranch || block instanceof BlockMushroom || block instanceof BlockLeaves) {
                        // Skip past Mushrooms and branches on the way down
                        continue;
                    } else if (block instanceof BlockFlower || block instanceof BlockTallGrass || block instanceof BlockDoublePlant) {
                        // Kill Plants
                        if (world.getLightFor(EnumSkyBlock.SKY, offPos) <= darkThreshold) {
                            world.setBlockToAir(pos);
                        }
                        continue;
                    } else if (block == Blocks.DIRT || block == Blocks.GRASS) {
                        // Convert grass or dirt to podzol
                        if (world.getLightFor(EnumSkyBlock.SKY, offPos.up()) <= darkThreshold) {
                            world.setBlockState(offPos, ModBlocks.blockStates.podzol);
                        } else {
                            spreadPodzol(world, pos);
                        }
                    }
                    break;
                }
            }
        }
    }
    return true;
}
Also used : NodeFindEnds(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) Random(java.util.Random) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) BlockPos(net.minecraft.util.math.BlockPos) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 15 with BlockBranch

use of com.ferreusveritas.dynamictrees.blocks.BlockBranch in project DynamicTrees by DynamicTreesTeam.

the class NodeFruitCocoa method run.

public boolean run(IBlockState blockState, World world, BlockPos pos, EnumFacing fromDir) {
    if (!finished) {
        int hashCode = CoordUtils.coordHashCode(pos, 1);
        if ((hashCode % 97) % 29 == 0) {
            BlockBranch branch = TreeHelper.getBranch(blockState);
            if (branch != null && branch.getRadius(blockState) == 8) {
                int side = (hashCode % 4) + 2;
                EnumFacing dir = EnumFacing.getFront(side);
                BlockPos deltaPos = pos.offset(dir);
                if (world.isAirBlock(deltaPos)) {
                    IBlockState cocoaState = ModBlocks.blockFruitCocoa.getStateForPlacement(world, deltaPos, dir, 0, 0, 0, 0, null);
                    world.setBlockState(deltaPos, cocoaState.withProperty(BlockCocoa.AGE, worldGen ? 2 : 0), 2);
                }
            } else {
                finished = true;
            }
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch)

Aggregations

BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)18 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.math.BlockPos)12 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)6 EnumFacing (net.minecraft.util.EnumFacing)6 Block (net.minecraft.block.Block)5 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)4 NodeFindEnds (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds)3 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)3 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)3 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)2 NodeCollector (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector)2 Species (com.ferreusveritas.dynamictrees.trees.Species)2 Cell (com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell)2 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)2 ItemStack (net.minecraft.item.ItemStack)2 NutRecipe (com.eerussianguy.firmalife.recipe.NutRecipe)1 INodeInspector (com.ferreusveritas.dynamictrees.api.network.INodeInspector)1 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)1 BlockBranchThick (com.ferreusveritas.dynamictrees.blocks.BlockBranchThick)1