use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class EncasedCogInstance method init.
@Override
public void init() {
rotatingModel = setup(getCogModel().createInstance());
Block block = blockState.getBlock();
if (!(block instanceof IRotate))
return;
IRotate def = (IRotate) block;
rotatingTopShaft = Optional.empty();
rotatingBottomShaft = Optional.empty();
for (Direction d : Iterate.directionsInAxis(axis)) {
if (!def.hasShaftTowards(blockEntity.getLevel(), blockEntity.getBlockPos(), blockState, d))
continue;
RotatingData data = setup(getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, d).createInstance());
if (d.getAxisDirection() == AxisDirection.POSITIVE)
rotatingTopShaft = Optional.of(data);
else
rotatingBottomShaft = Optional.of(data);
}
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class GaugeBlock method getStateForPlacement.
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Level world = context.getLevel();
Direction face = context.getClickedFace();
BlockPos placedOnPos = context.getClickedPos().relative(context.getClickedFace().getOpposite());
BlockState placedOnState = world.getBlockState(placedOnPos);
Block block = placedOnState.getBlock();
if (block instanceof IRotate && ((IRotate) block).hasShaftTowards(world, placedOnPos, placedOnState, face)) {
BlockState toPlace = defaultBlockState();
Direction horizontalFacing = context.getHorizontalDirection();
Direction nearestLookingDirection = context.getNearestLookingDirection();
boolean lookPositive = nearestLookingDirection.getAxisDirection() == AxisDirection.POSITIVE;
if (face.getAxis() == Axis.X) {
toPlace = toPlace.setValue(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH).setValue(AXIS_ALONG_FIRST_COORDINATE, true);
} else if (face.getAxis() == Axis.Y) {
toPlace = toPlace.setValue(FACING, horizontalFacing.getOpposite()).setValue(AXIS_ALONG_FIRST_COORDINATE, horizontalFacing.getAxis() == Axis.X);
} else {
toPlace = toPlace.setValue(FACING, lookPositive ? Direction.WEST : Direction.EAST).setValue(AXIS_ALONG_FIRST_COORDINATE, false);
}
return toPlace;
}
return super.getStateForPlacement(context);
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class RotationPropagator method handleRemoved.
/**
* Remove the given entity from the network.
*
* @param worldIn
* @param pos
* @param removedTE
*/
public static void handleRemoved(Level worldIn, BlockPos pos, KineticTileEntity removedTE) {
if (worldIn.isClientSide)
return;
if (removedTE == null)
return;
if (removedTE.getTheoreticalSpeed() == 0)
return;
for (BlockPos neighbourPos : getPotentialNeighbourLocations(removedTE)) {
BlockState neighbourState = worldIn.getBlockState(neighbourPos);
if (!(neighbourState.getBlock() instanceof IRotate))
continue;
BlockEntity tileEntity = worldIn.getBlockEntity(neighbourPos);
if (!(tileEntity instanceof KineticTileEntity))
continue;
final KineticTileEntity neighbourTE = (KineticTileEntity) tileEntity;
if (!neighbourTE.hasSource() || !neighbourTE.source.equals(pos))
continue;
propagateMissingSource(neighbourTE);
}
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class KineticDebugger method tick.
public static void tick() {
if (!isActive()) {
if (KineticTileEntityRenderer.rainbowMode) {
KineticTileEntityRenderer.rainbowMode = false;
CreateClient.BUFFER_CACHE.invalidate();
}
return;
}
KineticTileEntity te = getSelectedTE();
if (te == null)
return;
Level world = Minecraft.getInstance().level;
BlockPos toOutline = te.hasSource() ? te.source : te.getBlockPos();
BlockState state = te.getBlockState();
VoxelShape shape = world.getBlockState(toOutline).getBlockSupportShape(world, toOutline);
if (te.getTheoreticalSpeed() != 0 && !shape.isEmpty())
CreateClient.OUTLINER.chaseAABB("kineticSource", shape.bounds().move(toOutline)).lineWidth(1 / 16f).colored(te.hasSource() ? Color.generateFromLong(te.network).getRGB() : 0xffcc00);
if (state.getBlock() instanceof IRotate) {
Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
Vec3 vec = Vec3.atLowerCornerOf(Direction.get(AxisDirection.POSITIVE, axis).getNormal());
Vec3 center = VecHelper.getCenterOf(te.getBlockPos());
CreateClient.OUTLINER.showLine("rotationAxis", center.add(vec), center.subtract(vec)).lineWidth(1 / 16f);
}
}
use of com.simibubi.create.content.contraptions.base.IRotate in project Create by Creators-of-Create.
the class AbstractPulleyRenderer method renderSafe.
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (Backend.canUseInstancing(te.getLevel()))
return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
float offset = getOffset(te, partialTicks);
boolean running = isRunning(te);
Axis rotationAxis = ((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState());
kineticRotationTransform(getRotatedCoil(te), te, rotationAxis, AngleHelper.rad(offset * 180), light).renderInto(ms, buffer.getBuffer(RenderType.solid()));
Level world = te.getLevel();
BlockState blockState = te.getBlockState();
BlockPos pos = te.getBlockPos();
SuperByteBuffer halfMagnet = CachedBufferer.partial(this.halfMagnet, blockState);
SuperByteBuffer halfRope = CachedBufferer.partial(this.halfRope, blockState);
SuperByteBuffer magnet = renderMagnet(te);
SuperByteBuffer rope = renderRope(te);
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
if (running || offset == 0)
renderAt(world, offset > .25f ? magnet : halfMagnet, offset, pos, ms, vb);
float f = offset % 1;
if (offset > .75f && (f < .25f || f > .75f))
renderAt(world, halfRope, f > .75f ? f - 1 : f, pos, ms, vb);
if (!running)
return;
for (int i = 0; i < offset - 1.25f; i++) renderAt(world, rope, offset - i - 1, pos, ms, vb);
}
Aggregations