use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BeltConnectorItem method canConnect.
public static boolean canConnect(Level world, BlockPos first, BlockPos second) {
if (!world.isAreaLoaded(first, 1))
return false;
if (!world.isAreaLoaded(second, 1))
return false;
if (!second.closerThan(first, maxLength()))
return false;
BlockPos diff = second.subtract(first);
Axis shaftAxis = world.getBlockState(first).getValue(BlockStateProperties.AXIS);
int x = diff.getX();
int y = diff.getY();
int z = diff.getZ();
int sames = ((Math.abs(x) == Math.abs(y)) ? 1 : 0) + ((Math.abs(y) == Math.abs(z)) ? 1 : 0) + ((Math.abs(z) == Math.abs(x)) ? 1 : 0);
if (shaftAxis.choose(x, y, z) != 0)
return false;
if (sames != 1)
return false;
if (shaftAxis != world.getBlockState(second).getValue(BlockStateProperties.AXIS))
return false;
if (shaftAxis == Axis.Y && x != 0 && z != 0)
return false;
BlockEntity tileEntity = world.getBlockEntity(first);
BlockEntity tileEntity2 = world.getBlockEntity(second);
if (!(tileEntity instanceof KineticTileEntity))
return false;
if (!(tileEntity2 instanceof KineticTileEntity))
return false;
float speed1 = ((KineticTileEntity) tileEntity).getTheoreticalSpeed();
float speed2 = ((KineticTileEntity) tileEntity2).getTheoreticalSpeed();
if (Math.signum(speed1) != Math.signum(speed2) && speed1 != 0 && speed2 != 0)
return false;
BlockPos step = new BlockPos(Math.signum(diff.getX()), Math.signum(diff.getY()), Math.signum(diff.getZ()));
int limit = 1000;
for (BlockPos currentPos = first.offset(step); !currentPos.equals(second) && limit-- > 0; currentPos = currentPos.offset(step)) {
BlockState blockState = world.getBlockState(currentPos);
if (ShaftBlock.isShaft(blockState) && blockState.getValue(AbstractShaftBlock.AXIS) == shaftAxis)
continue;
if (!blockState.getMaterial().isReplaceable())
return false;
}
return true;
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class BeltShapes method getBeltShape.
private static VoxelShape getBeltShape(BlockState state) {
Direction facing = state.getValue(BeltBlock.HORIZONTAL_FACING);
Axis axis = facing.getAxis();
BeltPart part = state.getValue(BeltBlock.PART);
BeltSlope slope = state.getValue(BeltBlock.SLOPE);
// vertical
if (slope == BeltSlope.VERTICAL) {
if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
return VERTICAL_FULL.get(axis);
// vertical ending
return (part == BeltPart.START ? VERTICAL_START : VERTICAL_END).get(facing);
}
// flat part
if (slope == BeltSlope.HORIZONTAL) {
if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
return FLAT_FULL.get(axis);
// flat ending
return (part == BeltPart.START ? FLAT_START : FLAT_END).get(facing);
}
// sideways part
if (slope == BeltSlope.SIDEWAYS) {
if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
return SIDE_FULL.get(axis);
// flat ending
return (part == BeltPart.START ? SIDE_START : SIDE_END).get(facing);
}
// slope
if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC : SLOPE_ASC).get(facing);
// sloped ending
if (part == BeltPart.START)
return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC_START : SLOPE_ASC_START).get(facing);
if (part == BeltPart.END)
return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC_END : SLOPE_ASC_END).get(facing);
// bad state
return Shapes.empty();
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class SplitShaftRenderer method renderSafe.
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (Backend.canUseInstancing(te.getLevel()))
return;
Block block = te.getBlockState().getBlock();
final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());
final BlockPos pos = te.getBlockPos();
float time = AnimationTickHolder.getRenderTime(te.getLevel());
for (Direction direction : Iterate.directions) {
Axis axis = direction.getAxis();
if (boxAxis != axis)
continue;
float offset = getRotationOffsetForPosition(te, pos, axis);
float angle = (time * te.getSpeed() * 3f / 10) % 360;
float modifier = 1;
if (te instanceof SplitShaftTileEntity)
modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction);
angle *= modifier;
angle += offset;
angle = angle / 180f * (float) Math.PI;
SuperByteBuffer superByteBuffer = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
kineticRotationTransform(superByteBuffer, te, axis, angle, light);
superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class GearboxRenderer method renderSafe.
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (Backend.canUseInstancing(te.getLevel()))
return;
final Axis boxAxis = te.getBlockState().getValue(BlockStateProperties.AXIS);
final BlockPos pos = te.getBlockPos();
float time = AnimationTickHolder.getRenderTime(te.getLevel());
for (Direction direction : Iterate.directions) {
final Axis axis = direction.getAxis();
if (boxAxis == axis)
continue;
SuperByteBuffer shaft = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
float offset = getRotationOffsetForPosition(te, pos, axis);
float angle = (time * te.getSpeed() * 3f / 10) % 360;
if (te.getSpeed() != 0 && te.hasSource()) {
BlockPos source = te.source.subtract(te.getBlockPos());
Direction sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ());
if (sourceFacing.getAxis() == direction.getAxis())
angle *= sourceFacing == direction ? 1 : -1;
else if (sourceFacing.getAxisDirection() == direction.getAxisDirection())
angle *= -1;
}
angle += offset;
angle = angle / 180f * (float) Math.PI;
kineticRotationTransform(shaft, te, axis, angle, light);
shaft.renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class EncasedBeltBlock method updateAfterWrenched.
@Override
public BlockState updateAfterWrenched(BlockState newState, UseOnContext context) {
// Blocks.AIR.getDefaultState()
// .updateNeighbors(context.getWorld(), context.getPos(), 1);
Axis axis = newState.getValue(AXIS);
newState = defaultBlockState().setValue(AXIS, axis);
if (newState.hasProperty(BlockStateProperties.POWERED))
newState = newState.setValue(BlockStateProperties.POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == axis)
continue;
BlockPos pos = context.getClickedPos();
BlockPos offset = pos.relative(facing);
newState = updateShape(newState, facing, context.getLevel().getBlockState(offset), context.getLevel(), pos, offset);
}
// newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2);
return newState;
}
Aggregations