use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BlockClusterOutline method renderBlockFace.
protected void renderBlockFace(PoseStack ms, VertexConsumer builder, BlockPos pos, Direction face) {
Vec3 center = VecHelper.getCenterOf(pos);
Vec3 offset = Vec3.atLowerCornerOf(face.getNormal());
Vec3 plane = VecHelper.axisAlingedPlaneOf(offset);
Axis axis = face.getAxis();
offset = offset.scale(1 / 2f + 1 / 128d);
plane = plane.scale(1 / 2f).add(offset);
int deg = face.getAxisDirection().getStep() * 90;
Vec3 a1 = plane.add(center);
plane = VecHelper.rotate(plane, deg, axis);
Vec3 a2 = plane.add(center);
plane = VecHelper.rotate(plane, deg, axis);
Vec3 a3 = plane.add(center);
plane = VecHelper.rotate(plane, deg, axis);
Vec3 a4 = plane.add(center);
putQuad(ms, builder, a1, a2, a3, a4, face);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class DeployerRenderer method renderInContraption.
public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffer) {
VertexConsumer builder = buffer.getBuffer(RenderType.solid());
BlockState blockState = context.state;
Mode mode = NBTHelper.readEnum(context.tileData, "Mode", Mode.class);
PartialModel handPose = getHandPose(mode);
float speed = (float) context.getAnimationSpeed();
if (context.contraption.stalled)
speed = 0;
SuperByteBuffer shaft = CachedBufferer.block(AllBlocks.SHAFT.getDefaultState());
SuperByteBuffer pole = CachedBufferer.partial(AllBlockPartials.DEPLOYER_POLE, blockState);
SuperByteBuffer hand = CachedBufferer.partial(handPose, blockState);
double factor;
if (context.contraption.stalled || context.position == null || context.data.contains("StationaryTimer")) {
factor = Mth.sin(AnimationTickHolder.getRenderTime() * .5f) * .25f + .25f;
} else {
Vec3 center = VecHelper.getCenterOf(new BlockPos(context.position));
double distance = context.position.distanceTo(center);
double nextDistance = context.position.add(context.motion).distanceTo(center);
factor = .5f - Mth.clamp(Mth.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1);
}
Vec3 offset = Vec3.atLowerCornerOf(blockState.getValue(FACING).getNormal()).scale(factor);
PoseStack m = matrices.getModel();
m.pushPose();
m.pushPose();
Axis axis = Axis.Y;
if (context.state.getBlock() instanceof IRotate) {
IRotate def = (IRotate) context.state.getBlock();
axis = def.getRotationAxis(context.state);
}
float time = AnimationTickHolder.getRenderTime(context.world) / 20;
float angle = (time * speed) % 360;
TransformStack.cast(m).centre().rotateY(axis == Axis.Z ? 90 : 0).rotateZ(axis.isHorizontal() ? 90 : 0).unCentre();
shaft.transform(m);
shaft.rotateCentered(Direction.get(AxisDirection.POSITIVE, Axis.Y), angle);
m.popPose();
m.translate(offset.x, offset.y, offset.z);
pole.transform(m);
hand.transform(m);
transform(pole, blockState, true);
transform(hand, blockState, false);
shaft.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
hand.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
m.popPose();
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class CrushingWheelBlock method updateControllers.
public void updateControllers(BlockState state, Level world, BlockPos pos, Direction side) {
if (side.getAxis() == state.getValue(AXIS))
return;
if (world == null)
return;
BlockPos controllerPos = pos.relative(side);
BlockPos otherWheelPos = pos.relative(side, 2);
boolean controllerExists = AllBlocks.CRUSHING_WHEEL_CONTROLLER.has(world.getBlockState(controllerPos));
boolean controllerIsValid = controllerExists && world.getBlockState(controllerPos).getValue(VALID);
Direction controllerOldDirection = controllerExists ? world.getBlockState(controllerPos).getValue(CrushingWheelControllerBlock.FACING) : null;
boolean controllerShouldExist = false;
boolean controllerShouldBeValid = false;
Direction controllerNewDirection = Direction.DOWN;
BlockState otherState = world.getBlockState(otherWheelPos);
if (AllBlocks.CRUSHING_WHEEL.has(otherState)) {
controllerShouldExist = true;
CrushingWheelTileEntity te = getTileEntity(world, pos);
CrushingWheelTileEntity otherTe = getTileEntity(world, otherWheelPos);
if (te != null && otherTe != null && (te.getSpeed() > 0) != (otherTe.getSpeed() > 0) && te.getSpeed() != 0) {
Axis wheelAxis = state.getValue(AXIS);
Axis sideAxis = side.getAxis();
int controllerADO = Math.round(Math.signum(te.getSpeed())) * side.getAxisDirection().getStep();
Vec3 controllerDirVec = new Vec3(wheelAxis == Axis.X ? 1 : 0, wheelAxis == Axis.Y ? 1 : 0, wheelAxis == Axis.Z ? 1 : 0).cross(new Vec3(sideAxis == Axis.X ? 1 : 0, sideAxis == Axis.Y ? 1 : 0, sideAxis == Axis.Z ? 1 : 0));
controllerNewDirection = Direction.getNearest(controllerDirVec.x * controllerADO, controllerDirVec.y * controllerADO, controllerDirVec.z * controllerADO);
controllerShouldBeValid = true;
}
if (otherState.getValue(AXIS) != state.getValue(AXIS))
controllerShouldExist = false;
}
if (!controllerShouldExist) {
if (controllerExists)
world.setBlockAndUpdate(controllerPos, Blocks.AIR.defaultBlockState());
return;
}
if (!controllerExists) {
if (!world.getBlockState(controllerPos).getMaterial().isReplaceable())
return;
world.setBlockAndUpdate(controllerPos, AllBlocks.CRUSHING_WHEEL_CONTROLLER.getDefaultState().setValue(VALID, controllerShouldBeValid).setValue(CrushingWheelControllerBlock.FACING, controllerNewDirection));
} else if (controllerIsValid != controllerShouldBeValid || controllerOldDirection != controllerNewDirection) {
world.setBlockAndUpdate(controllerPos, world.getBlockState(controllerPos).setValue(VALID, controllerShouldBeValid).setValue(CrushingWheelControllerBlock.FACING, controllerNewDirection));
}
((CrushingWheelControllerBlock) AllBlocks.CRUSHING_WHEEL_CONTROLLER.get()).updateSpeed(world.getBlockState(controllerPos), world, controllerPos);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class GantryShaftBlock method updateShape.
@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighbour, LevelAccessor world, BlockPos pos, BlockPos neighbourPos) {
Direction facing = state.getValue(FACING);
Axis axis = facing.getAxis();
if (direction.getAxis() != axis)
return state;
boolean connect = AllBlocks.GANTRY_SHAFT.has(neighbour) && neighbour.getValue(FACING) == facing;
Part part = state.getValue(PART);
if (direction.getAxisDirection() == facing.getAxisDirection()) {
if (connect) {
if (part == Part.END)
part = Part.MIDDLE;
if (part == Part.SINGLE)
part = Part.START;
} else {
if (part == Part.MIDDLE)
part = Part.END;
if (part == Part.START)
part = Part.SINGLE;
}
} else {
if (connect) {
if (part == Part.START)
part = Part.MIDDLE;
if (part == Part.SINGLE)
part = Part.END;
} else {
if (part == Part.MIDDLE)
part = Part.START;
if (part == Part.END)
part = Part.SINGLE;
}
}
return state.setValue(PART, part);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class GantryShaftBlock method neighborChanged.
@Override
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block p_220069_4_, BlockPos p_220069_5_, boolean p_220069_6_) {
if (worldIn.isClientSide)
return;
boolean previouslyPowered = state.getValue(POWERED);
// shouldBePowered(state, worldIn, pos);
boolean shouldPower = worldIn.hasNeighborSignal(pos);
if (!previouslyPowered && !shouldPower && shouldBePowered(state, worldIn, pos)) {
worldIn.setBlock(pos, state.setValue(POWERED, true), 3);
return;
}
if (previouslyPowered == shouldPower)
return;
// Collect affected gantry shafts
List<BlockPos> toUpdate = new ArrayList<>();
Direction facing = state.getValue(FACING);
Axis axis = facing.getAxis();
for (Direction d : Iterate.directionsInAxis(axis)) {
BlockPos currentPos = pos.relative(d);
while (true) {
if (!worldIn.isLoaded(currentPos))
break;
BlockState currentState = worldIn.getBlockState(currentPos);
if (!(currentState.getBlock() instanceof GantryShaftBlock))
break;
if (currentState.getValue(FACING) != facing)
break;
if (!shouldPower && currentState.getValue(POWERED) && worldIn.hasNeighborSignal(currentPos))
return;
if (currentState.getValue(POWERED) == shouldPower)
break;
toUpdate.add(currentPos);
currentPos = currentPos.relative(d);
}
}
toUpdate.add(pos);
for (BlockPos blockPos : toUpdate) {
BlockState blockState = worldIn.getBlockState(blockPos);
BlockEntity te = worldIn.getBlockEntity(blockPos);
if (te instanceof KineticTileEntity)
((KineticTileEntity) te).detachKinetics();
if (blockState.getBlock() instanceof GantryShaftBlock)
worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
}
}
Aggregations