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();
}
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);
}
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);
}
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;
}
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);
}
Aggregations