Search in sources :

Example 41 with Axis

use of net.minecraft.core.Direction.Axis in project Cyclic by Lothrazar.

the class RenderResizableCuboid method renderCube.

/**
 * model 3d cube is the fluid
 */
public void renderCube(Model3D cube, PoseStack matrix, VertexConsumer buffer, int argb, int light) {
    float red = UtilRender.getRed(argb);
    float green = UtilRender.getGreen(argb);
    float blue = UtilRender.getBlue(argb);
    float alpha = UtilRender.getAlpha(argb);
    Vec3 size = new Vec3(cube.sizeX(), cube.sizeY(), cube.sizeZ());
    matrix.pushPose();
    matrix.translate(cube.minX, cube.minY, cube.minZ);
    com.mojang.math.Matrix4f matrix4f = matrix.last().pose();
    for (Direction face : Direction.values()) {
        if (cube.shouldSideRender(face)) {
            int ordinal = face.ordinal();
            TextureAtlasSprite sprite = cube.textures[ordinal];
            if (sprite != null) {
                Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
                Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
                float other = face.getAxisDirection() == AxisDirection.POSITIVE ? (float) getValue(size, face.getAxis()) : 0;
                // Swap the face if this is positive: the renderer returns indexes that ALWAYS are for the negative face, so light it properly this way
                face = face.getAxisDirection() == AxisDirection.NEGATIVE ? face : face.getOpposite();
                Direction opposite = face.getOpposite();
                float minU = sprite.getU0();
                float maxU = sprite.getU1();
                // Flip the v
                float minV = sprite.getV1();
                float maxV = sprite.getV0();
                double sizeU = getValue(size, u);
                double sizeV = getValue(size, v);
                // Example: Mechanical pipes rendering water or lava, makes it relatively easy to see the texture artifacts
                for (int uIndex = 0; uIndex < sizeU; uIndex++) {
                    float[] baseUV = new float[] { minU, maxU, minV, maxV };
                    double addU = 1;
                    // If the size of the texture is greater than the cuboid goes on for then make sure the texture positions are lowered
                    if (uIndex + addU > sizeU) {
                        addU = sizeU - uIndex;
                        baseUV[U_MAX] = baseUV[U_MIN] + (baseUV[U_MAX] - baseUV[U_MIN]) * (float) addU;
                    }
                    for (int vIndex = 0; vIndex < sizeV; vIndex++) {
                        float[] uv = Arrays.copyOf(baseUV, 4);
                        double addV = 1;
                        if (vIndex + addV > sizeV) {
                            addV = sizeV - vIndex;
                            uv[V_MAX] = uv[V_MIN] + (uv[V_MAX] - uv[V_MIN]) * (float) addV;
                        }
                        float[] xyz = new float[] { uIndex, (float) (uIndex + addU), vIndex, (float) (vIndex + addV) };
                        renderPoint(matrix4f, buffer, face, u, v, other, uv, xyz, true, false, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, face, u, v, other, uv, xyz, true, true, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, face, u, v, other, uv, xyz, false, true, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, face, u, v, other, uv, xyz, false, false, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, opposite, u, v, other, uv, xyz, false, false, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, opposite, u, v, other, uv, xyz, false, true, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, opposite, u, v, other, uv, xyz, true, true, red, green, blue, alpha, light);
                        renderPoint(matrix4f, buffer, opposite, u, v, other, uv, xyz, true, false, red, green, blue, alpha, light);
                    }
                }
            }
        }
    }
    matrix.popPose();
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vec3(net.minecraft.world.phys.Vec3) Matrix4f(com.mojang.math.Matrix4f) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 42 with Axis

use of net.minecraft.core.Direction.Axis in project Tropicraft by Tropicraft.

the class SmoothingGravityProcessor method process.

@Override
public StructureBlockInfo process(LevelReader level, BlockPos seedPos, BlockPos pos2, StructureBlockInfo originalBlockInfo, StructureBlockInfo blockInfo, StructurePlaceSettings placementSettingsIn, StructureTemplate template) {
    Axis pathDir = getPathDirection(level, seedPos, blockInfo, placementSettingsIn, template);
    if (pathDir == null) {
        // Better than nothing
        pathDir = Axis.X;
    }
    BlockPos pos = blockInfo.pos;
    BlockPos posForward = pos.relative(Direction.get(AxisDirection.POSITIVE, pathDir));
    BlockPos posBackward = pos.relative(Direction.get(AxisDirection.NEGATIVE, pathDir));
    int heightForward = level.getHeight(heightmap, posForward.getX(), posForward.getZ()) + offset;
    int heightBackward = level.getHeight(heightmap, posBackward.getX(), posBackward.getZ()) + offset;
    int height = level.getHeight(heightmap, pos.getX(), pos.getZ()) + offset;
    if (heightForward > height && heightBackward > height) {
        return new StructureBlockInfo(new BlockPos(pos.getX(), Math.min(heightForward, heightBackward), pos.getZ()), blockInfo.state, blockInfo.nbt);
    }
    return baseline.process(level, seedPos, pos2, originalBlockInfo, blockInfo, placementSettingsIn, template);
}
Also used : BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) Axis(net.minecraft.core.Direction.Axis)

Example 43 with Axis

use of net.minecraft.core.Direction.Axis in project The-Aether by Gilded-Games.

the class AetherPortalBlock method updateShape.

@Override
@Deprecated
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
    Axis directionAxis = facing.getAxis();
    Axis stateAxis = stateIn.getValue(AXIS);
    boolean flag = stateAxis != directionAxis && directionAxis.isHorizontal();
    return (!flag && facingState.getBlock() != this && !(new AetherPortalBlock.Size(worldIn, currentPos, stateAxis)).canCreatePortal()) ? Blocks.AIR.defaultBlockState() : super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
}
Also used : Axis(net.minecraft.core.Direction.Axis)

Example 44 with Axis

use of net.minecraft.core.Direction.Axis in project createaddition by mrh0.

the class RedstoneRelay method getShape.

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
    Direction dir = state.getValue(HORIZONTAL_FACING);
    if (state.getValue(VERTICAL))
        return VERTICAL_SHAPE.get(dir.getOpposite());
    Axis axis = dir.getAxis();
    return axis == Axis.X ? HORIZONTAL_SHAPE_X : HORIZONTAL_SHAPE_Z;
}
Also used : Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 45 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class DirectionalAxisKineticBlock method getStateForPlacement.

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
    Direction facing = getFacingForPlacement(context);
    BlockPos pos = context.getClickedPos();
    Level world = context.getLevel();
    boolean alongFirst = false;
    Axis faceAxis = facing.getAxis();
    if (faceAxis.isHorizontal()) {
        alongFirst = faceAxis == Axis.Z;
        Direction positivePerpendicular = DirectionHelper.getPositivePerpendicular(faceAxis);
        boolean shaftAbove = prefersConnectionTo(world, pos, Direction.UP, true);
        boolean shaftBelow = prefersConnectionTo(world, pos, Direction.DOWN, true);
        boolean preferLeft = prefersConnectionTo(world, pos, positivePerpendicular, false);
        boolean preferRight = prefersConnectionTo(world, pos, positivePerpendicular.getOpposite(), false);
        if (shaftAbove || shaftBelow || preferLeft || preferRight)
            alongFirst = faceAxis == Axis.X;
    }
    if (faceAxis.isVertical()) {
        alongFirst = getAxisAlignmentForPlacement(context);
        Direction prefferedSide = null;
        for (Direction side : Iterate.horizontalDirections) {
            if (!prefersConnectionTo(world, pos, side, true) && !prefersConnectionTo(world, pos, side.getClockWise(), false))
                continue;
            if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
                prefferedSide = null;
                break;
            }
            prefferedSide = side;
        }
        if (prefferedSide != null)
            alongFirst = prefferedSide.getAxis() == Axis.X;
    }
    return this.defaultBlockState().setValue(FACING, facing).setValue(AXIS_ALONG_FIRST_COORDINATE, alongFirst);
}
Also used : BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Aggregations

Axis (net.minecraft.core.Direction.Axis)85 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)35 AxisDirection (net.minecraft.core.Direction.AxisDirection)24 Vec3 (net.minecraft.world.phys.Vec3)14 Level (net.minecraft.world.level.Level)13 IRotate (com.simibubi.create.content.contraptions.base.IRotate)9 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)7 Block (net.minecraft.world.level.block.Block)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)6 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)5 Player (net.minecraft.world.entity.player.Player)5 HashSet (java.util.HashSet)4 ItemStack (net.minecraft.world.item.ItemStack)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 Part (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part)3 ArrayList (java.util.ArrayList)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)3