Search in sources :

Example 1 with BranchDestructionData

use of com.ferreusveritas.dynamictrees.util.BranchDestructionData in project DynamicTrees by DynamicTreesTeam.

the class BlockRooty method destroyTree.

public void destroyTree(World world, BlockPos rootPos) {
    Optional<BlockBranch> branch = TreeHelper.getBranchOpt(world.getBlockState(rootPos.up()));
    if (branch.isPresent()) {
        BranchDestructionData destroyData = branch.get().destroyBranchFromNode(world, rootPos.up(), EnumFacing.DOWN, true);
        EntityFallingTree.dropTree(world, destroyData, new ArrayList<ItemStack>(0), DestroyType.ROOT);
    }
}
Also used : BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BranchDestructionData

use of com.ferreusveritas.dynamictrees.util.BranchDestructionData in project DynamicTrees by DynamicTreesTeam.

the class EntityFallingTree method setupFromNBT.

public void setupFromNBT(NBTTagCompound tag) {
    destroyData = new BranchDestructionData(tag);
    if (destroyData.getNumBranches() == 0) {
        setDead();
    }
    destroyType = DestroyType.values()[tag.getInteger("destroytype")];
    geomCenter = new Vec3d(tag.getDouble("geomx"), tag.getDouble("geomy"), tag.getDouble("geomz"));
    massCenter = new Vec3d(tag.getDouble("massx"), tag.getDouble("massy"), tag.getDouble("massz"));
    this.setEntityBoundingBox(this.buildAABBFromDestroyData(destroyData).offset(posX, posY, posZ));
    this.renderBB = renderNormAABB.offset(posX, posY, posZ);
    onFire = tag.getBoolean("onfire");
}
Also used : BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with BranchDestructionData

use of com.ferreusveritas.dynamictrees.util.BranchDestructionData in project DynamicTrees by DynamicTreesTeam.

the class BlockBranch method sloppyBreak.

protected void sloppyBreak(World world, BlockPos cutPos, DestroyType destroyType) {
    // Do the actual destruction
    BranchDestructionData destroyData = destroyBranchFromNode(world, cutPos, EnumFacing.DOWN, false);
    // Sloppy breaks return no goodies.
    List<ItemStack> woodDropList = Collections.EMPTY_LIST;
    destroyData.leavesDrops.clear();
    // This will drop the EntityFallingTree into the world
    EntityFallingTree.dropTree(world, destroyData, woodDropList, destroyType);
}
Also used : BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) ItemStack(net.minecraft.item.ItemStack)

Example 4 with BranchDestructionData

use of com.ferreusveritas.dynamictrees.util.BranchDestructionData in project DynamicTrees by DynamicTreesTeam.

the class ModelEntityFallingTree method generateTreeQuads.

public List<TreeQuadData> generateTreeQuads(EntityFallingTree entity, World world) {
    final BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    final BranchDestructionData destructionData = entity.getDestroyData();
    final Species species = destructionData.species;
    final BlockPos cutPos = destructionData.cutPos;
    final EnumFacing cutDir = destructionData.cutDir;
    final ArrayList<TreeQuadData> treeQuads = new ArrayList<>();
    if (destructionData.getNumBranches() <= 0) {
        return treeQuads;
    }
    // Draw the ring texture cap on the cut block
    IExtendedBlockState exState = destructionData.getBranchBlockState(0);
    if (exState == null) {
        return treeQuads;
    }
    for (EnumFacing face : EnumFacing.VALUES) {
        exState = exState.withProperty(BlockBranch.CONNECTIONS[face.getIndex()], face == cutDir.getOpposite() ? 8 : 0);
    }
    int radius = ((BlockBranch) exState.getBlock()).getRadius(exState);
    float offset = (8 - Math.min(radius, BlockBranch.RADMAX_NORMAL)) / 16f;
    // Since we source the blockState from the destruction data it will always be the same
    IBakedModel branchModel = dispatcher.getModelForState(exState.getClean());
    treeQuads.addAll(toTreeQuadData(QuadManipulator.getQuads(branchModel, exState, new Vec3d(BlockPos.ORIGIN.offset(cutDir)).scale(offset), new EnumFacing[] { cutDir }), 0xFFFFFFFF, exState.getClean()));
    // Draw the rest of the tree/branch
    for (int index = 0; index < destructionData.getNumBranches(); index++) {
        Block previousBranch = exState.getBlock();
        exState = destructionData.getBranchBlockState(index);
        if (// Update the branch model only if the block is different
        !previousBranch.equals(exState.getBlock())) {
            branchModel = dispatcher.getModelForState(exState.getClean());
        }
        BlockPos relPos = destructionData.getBranchRelPos(index);
        treeQuads.addAll(toTreeQuadData(QuadManipulator.getQuads(branchModel, exState, new Vec3d(relPos)), 0xFFFFFFFF, exState.getClean()));
    }
    // Draw the leaves
    HashMap<BlockPos, IBlockState> leavesClusters = species.getFamily().getFellingLeavesClusters(destructionData);
    if (leavesClusters != null) {
        for (Entry<BlockPos, IBlockState> leafLoc : leavesClusters.entrySet()) {
            IBlockState leafState = leafLoc.getValue();
            if (leafState instanceof IExtendedBlockState) {
                leafState = ((IExtendedBlockState) leafState).getClean();
            }
            treeQuads.addAll(toTreeQuadData(QuadManipulator.getQuads(dispatcher.getModelForState(leafState), leafLoc.getValue(), new Vec3d(leafLoc.getKey())), species.getLeavesProperties().foliageColorMultiplier(leafState, world, cutPos), leafState));
        }
    } else {
        for (int index = 0; index < destructionData.getNumLeaves(); index++) {
            BlockPos relPos = destructionData.getLeavesRelPos(index);
            IBlockState state = destructionData.getLeavesBlockState(index);
            IBakedModel leavesModel = dispatcher.getModelForState(state);
            treeQuads.addAll(toTreeQuadData(QuadManipulator.getQuads(leavesModel, state, new Vec3d(relPos)), destructionData.getLeavesProperties(index).foliageColorMultiplier(state, world, cutPos.add(relPos)), state));
        }
    }
    return treeQuads;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) Vec3d(net.minecraft.util.math.Vec3d) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Species(com.ferreusveritas.dynamictrees.trees.Species) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 5 with BranchDestructionData

use of com.ferreusveritas.dynamictrees.util.BranchDestructionData in project DynamicTrees by DynamicTreesTeam.

the class ModelEntityFallingTree method getBrightness.

public static int getBrightness(EntityFallingTree entity) {
    BranchDestructionData destructionData = entity.getDestroyData();
    World world = entity.getEntityWorld();
    return world.getBlockState(destructionData.cutPos).getPackedLightmapCoords(world, destructionData.cutPos);
}
Also used : BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) World(net.minecraft.world.World)

Aggregations

BranchDestructionData (com.ferreusveritas.dynamictrees.util.BranchDestructionData)8 Species (com.ferreusveritas.dynamictrees.trees.Species)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemStack (net.minecraft.item.ItemStack)4 Vec3d (net.minecraft.util.math.Vec3d)4 NodeSpecies (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)2 EntityFallingTree (com.ferreusveritas.dynamictrees.entities.EntityFallingTree)2 NodeDestroyer (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer)2 NodeExtState (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeExtState)2 NodeNetVolume (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume)2 Block (net.minecraft.block.Block)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityCreeper (net.minecraft.entity.monster.EntityCreeper)2 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)2 World (net.minecraft.world.World)2 ModBlocks (com.ferreusveritas.dynamictrees.ModBlocks)1 ModConfigs (com.ferreusveritas.dynamictrees.ModConfigs)1