Search in sources :

Example 1 with Surround

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

the class BlockSurfaceRoot method getBoundingBox.

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess blockAccess, BlockPos pos) {
    if (state.getBlock() != this) {
        return NULL_AABB;
    }
    AxisAlignedBB trunkBB = null;
    for (Surround dir : sidesFirst) {
        BlockPos dPos = pos.add(dir.getOffset());
        IBlockState testState = blockAccess.getBlockState(dPos);
        if (testState.getBlock() instanceof BlockBranchThick) {
            BlockBranchThick trunk = (BlockBranchThick) testState.getBlock();
            trunkBB = trunk.getBoundingBox(testState, blockAccess, dPos).offset(dir.getOffsetPos()).intersect(FULL_BLOCK_AABB);
            // There should only be one trunk in proximity
            break;
        }
    }
    int thisRadius = getRadius(state);
    int radialHeight = getRadialHeight(thisRadius);
    double radius = thisRadius / 16.0;
    double gap = 0.5 - radius;
    AxisAlignedBB aabb = new AxisAlignedBB(-radius, 0, -radius, radius, radialHeight / 16d, radius);
    for (EnumFacing dir : EnumFacing.VALUES) {
        RootConnection conn = getSideConnectionRadius(blockAccess, pos, thisRadius, dir);
        if (conn != null) {
            aabb = aabb.expand(dir.getFrontOffsetX() * gap, dir.getFrontOffsetY() * gap, dir.getFrontOffsetZ() * gap);
            if (conn.level == ConnectionLevel.HIGH) {
                aabb = aabb.setMaxY(1.0 + (radialHeight / 16d));
            }
        }
    }
    aabb = aabb.offset(0.5, 0.0, 0.5);
    return trunkBB != null ? trunkBB.union(aabb) : aabb;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Surround(com.ferreusveritas.dynamictrees.util.CoordUtils.Surround) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with Surround

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

the class BlockTrunkShell method getMuseUnchecked.

@Nullable
public ShellMuse getMuseUnchecked(@Nonnull IBlockAccess access, @Nonnull IBlockState state, @Nonnull BlockPos pos) {
    Surround museDir = getMuseDir(state, pos);
    BlockPos musePos = pos.add(museDir.getOffset());
    IBlockState museState = access.getBlockState(musePos);
    Block block = museState.getBlock();
    if (block instanceof IMusable && ((IMusable) block).isMusable()) {
        return new ShellMuse(museState, musePos, museDir);
    }
    return null;
}
Also used : Surround(com.ferreusveritas.dynamictrees.util.CoordUtils.Surround) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 3 with Surround

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

the class BakedModelBlockBranchThick method bakeTrunkBark.

public IBakedModel bakeTrunkBark(int radius, TextureAtlasSprite bark, boolean side) {
    SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(modelBlock, ItemOverrideList.NONE).setTexture(bark);
    AxisAlignedBB wholeVolume = new AxisAlignedBB(8 - radius, 0, 8 - radius, 8 + radius, 16, 8 + radius);
    final EnumFacing[] run = side ? EnumFacing.HORIZONTALS : new EnumFacing[] { EnumFacing.UP, EnumFacing.DOWN };
    ArrayList<Vec3i> offsets = new ArrayList<>();
    for (Surround dir : Surround.values()) {
        // 8 surrounding component pieces
        offsets.add(dir.getOffset());
    }
    // Center
    offsets.add(new Vec3i(0, 0, 0));
    for (EnumFacing face : run) {
        for (Vec3i offset : offsets) {
            if (face.getAxis() == Axis.Y || new Vec3d(face.getDirectionVec()).add(new Vec3d(offset)).lengthSquared() > 2.25) {
                // This means that the dir and face share a common direction
                // Scale the dimensions to match standard minecraft texels
                Vec3d scaledOffset = new Vec3d(offset.getX() * 16, offset.getY() * 16, offset.getZ() * 16);
                AxisAlignedBB partBoundary = new AxisAlignedBB(0, 0, 0, 16, 16, 16).offset(scaledOffset).intersect(wholeVolume);
                Vector3f[] limits = ModelUtils.AABBLimits(partBoundary);
                Map<EnumFacing, BlockPartFace> mapFacesIn = Maps.newEnumMap(EnumFacing.class);
                BlockFaceUV uvface = new BlockFaceUV(ModelUtils.modUV(ModelUtils.getUVs(partBoundary, face)), getFaceAngle(Axis.Y, face));
                mapFacesIn.put(face, new BlockPartFace(null, -1, null, uvface));
                BlockPart part = new BlockPart(limits[0], limits[1], mapFacesIn, null, true);
                builder.addFaceQuad(face, ModelUtils.makeBakedQuad(part, part.mapFaces.get(face), bark, face, ModelRotation.X0_Y0, false));
            }
        }
    }
    return builder.makeBakedModel();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vec3i(net.minecraft.util.math.Vec3i) Surround(com.ferreusveritas.dynamictrees.util.CoordUtils.Surround) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 4 with Surround

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

the class BakedModelBlockBranchThick method bakeTrunkRings.

public IBakedModel bakeTrunkRings(int radius, TextureAtlasSprite ring, EnumFacing face, boolean fancy) {
    SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(modelBlock, ItemOverrideList.NONE).setTexture(ring);
    AxisAlignedBB wholeVolume = new AxisAlignedBB(8 - radius, 0, 8 - radius, 8 + radius, 16, 8 + radius);
    int wholeVolumeWidth = fancy ? 48 : radius * 2;
    ArrayList<Vec3i> offsets = new ArrayList<>();
    for (Surround dir : Surround.values()) {
        // 8 surrounding component pieces
        offsets.add(dir.getOffset());
    }
    // Center
    offsets.add(new Vec3i(0, 0, 0));
    for (Vec3i offset : offsets) {
        // Scale the dimensions to match standard minecraft texels
        Vec3d scaledOffset = new Vec3d(offset.getX() * 16, offset.getY() * 16, offset.getZ() * 16);
        AxisAlignedBB partBoundary = new AxisAlignedBB(0, 0, 0, 16, 16, 16).offset(scaledOffset).intersect(wholeVolume);
        Vector3f posFrom = new Vector3f((float) partBoundary.minX, (float) partBoundary.minY, (float) partBoundary.minZ);
        Vector3f posTo = new Vector3f((float) partBoundary.maxX, (float) partBoundary.maxY, (float) partBoundary.maxZ);
        Map<EnumFacing, BlockPartFace> mapFacesIn = Maps.newEnumMap(EnumFacing.class);
        float textureOffsetX = fancy ? -16f : (float) wholeVolume.minX;
        float textureOffsetZ = fancy ? -16f : (float) wholeVolume.minZ;
        float minX = ((float) ((partBoundary.minX - textureOffsetX) / wholeVolumeWidth)) * 16f;
        float maxX = ((float) ((partBoundary.maxX - textureOffsetX) / wholeVolumeWidth)) * 16f;
        float minZ = ((float) ((partBoundary.minZ - textureOffsetZ) / wholeVolumeWidth)) * 16f;
        float maxZ = ((float) ((partBoundary.maxZ - textureOffsetZ) / wholeVolumeWidth)) * 16f;
        if (face == EnumFacing.DOWN) {
            minZ = ((float) ((partBoundary.maxZ - textureOffsetZ) / wholeVolumeWidth)) * 16f;
            maxZ = ((float) ((partBoundary.minZ - textureOffsetZ) / wholeVolumeWidth)) * 16f;
        }
        float[] uvs = new float[] { minX, minZ, maxX, maxZ };
        BlockFaceUV uvface = new BlockFaceUV(uvs, getFaceAngle(Axis.Y, face));
        mapFacesIn.put(face, new BlockPartFace(null, -1, null, uvface));
        BlockPart part = new BlockPart(posFrom, posTo, mapFacesIn, null, true);
        builder.addFaceQuad(face, ModelUtils.makeBakedQuad(part, part.mapFaces.get(face), ring, face, ModelRotation.X0_Y0, false));
    }
    return builder.makeBakedModel();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vec3i(net.minecraft.util.math.Vec3i) Surround(com.ferreusveritas.dynamictrees.util.CoordUtils.Surround) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 5 with Surround

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

the class FeatureGenMound method postGeneration.

/**
 * Creates a 3x2x3 cube of dirt around the base of the tree using blocks derived from the environment.  This is used
 * to cleanup the overhanging trunk that happens when a thick tree is generated next to a drop off.  Only runs when
 * the radius is greater than 8.
 */
@Override
public boolean postGeneration(World world, BlockPos rootPos, Species species, Biome biome, int radius, List<BlockPos> endPoints, SafeChunkBounds safeBounds, IBlockState initialDirtState) {
    if (radius < moundCutoffRadius && safeBounds != SafeChunkBounds.ANY) {
        // A mound was already generated in preGen and worldgen test
        BlockPos treePos = rootPos.up();
        IBlockState belowState = world.getBlockState(rootPos.down());
        // Place dirt blocks around rooty dirt block if tree has a > 8 radius
        IBlockState branchState = world.getBlockState(treePos);
        if (TreeHelper.getTreePart(branchState).getRadius(branchState) > BlockBranch.RADMAX_NORMAL) {
            for (Surround dir : Surround.values()) {
                BlockPos dPos = rootPos.add(dir.getOffset());
                world.setBlockState(dPos, initialDirtState);
                world.setBlockState(dPos.down(), belowState);
            }
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Surround(com.ferreusveritas.dynamictrees.util.CoordUtils.Surround) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Surround (com.ferreusveritas.dynamictrees.util.CoordUtils.Surround)8 BlockPos (net.minecraft.util.math.BlockPos)5 IBlockState (net.minecraft.block.state.IBlockState)4 EnumFacing (net.minecraft.util.EnumFacing)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 ArrayList (java.util.ArrayList)2 Block (net.minecraft.block.Block)2 Vec3d (net.minecraft.util.math.Vec3d)2 Vec3i (net.minecraft.util.math.Vec3i)2 Vector3f (org.lwjgl.util.vector.Vector3f)2 BlockSurfaceRoot (com.ferreusveritas.dynamictrees.blocks.BlockSurfaceRoot)1 Nullable (javax.annotation.Nullable)1 BlockBush (net.minecraft.block.BlockBush)1