use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.
the class CouplingRenderer method renderCoupling.
public static void renderCoupling(PoseStack ms, MultiBufferSource buffer, Couple<AbstractMinecart> carts) {
ClientLevel world = Minecraft.getInstance().level;
if (carts.getFirst() == null || carts.getSecond() == null)
return;
Couple<Integer> lightValues = carts.map(c -> LevelRenderer.getLightColor(world, new BlockPos(c.getBoundingBox().getCenter())));
Vec3 center = carts.getFirst().position().add(carts.getSecond().position()).scale(.5f);
Couple<CartEndpoint> transforms = carts.map(c -> getSuitableCartEndpoint(c, center));
BlockState renderState = Blocks.AIR.defaultBlockState();
VertexConsumer builder = buffer.getBuffer(RenderType.solid());
SuperByteBuffer attachment = CachedBufferer.partial(AllBlockPartials.COUPLING_ATTACHMENT, renderState);
SuperByteBuffer ring = CachedBufferer.partial(AllBlockPartials.COUPLING_RING, renderState);
SuperByteBuffer connector = CachedBufferer.partial(AllBlockPartials.COUPLING_CONNECTOR, renderState);
Vec3 zero = Vec3.ZERO;
Vec3 firstEndpoint = transforms.getFirst().apply(zero);
Vec3 secondEndpoint = transforms.getSecond().apply(zero);
Vec3 endPointDiff = secondEndpoint.subtract(firstEndpoint);
double connectorYaw = -Math.atan2(endPointDiff.z, endPointDiff.x) * 180.0D / Math.PI;
double connectorPitch = Math.atan2(endPointDiff.y, endPointDiff.multiply(1, 0, 1).length()) * 180 / Math.PI;
TransformStack msr = TransformStack.cast(ms);
carts.forEachWithContext((cart, isFirst) -> {
CartEndpoint cartTransform = transforms.get(isFirst);
ms.pushPose();
cartTransform.apply(ms);
attachment.light(lightValues.get(isFirst)).renderInto(ms, builder);
msr.rotateY(connectorYaw - cartTransform.yaw);
ring.light(lightValues.get(isFirst)).renderInto(ms, builder);
ms.popPose();
});
int l1 = lightValues.getFirst();
int l2 = lightValues.getSecond();
int meanBlockLight = (((l1 >> 4) & 0xf) + ((l2 >> 4) & 0xf)) / 2;
int meanSkyLight = (((l1 >> 20) & 0xf) + ((l2 >> 20) & 0xf)) / 2;
ms.pushPose();
msr.translate(firstEndpoint).rotateY(connectorYaw).rotateZ(connectorPitch);
ms.scale((float) endPointDiff.length(), 1, 1);
connector.light(meanSkyLight << 20 | meanBlockLight << 4).renderInto(ms, builder);
ms.popPose();
}
use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.
the class GantryCarriageRenderer method renderSafe.
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getLevel()))
return;
BlockState state = te.getBlockState();
Direction facing = state.getValue(GantryCarriageBlock.FACING);
Boolean alongFirst = state.getValue(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
Axis rotationAxis = getRotationAxisOf(te);
BlockPos visualPos = facing.getAxisDirection() == AxisDirection.POSITIVE ? te.getBlockPos() : te.getBlockPos().relative(facing.getOpposite());
float angleForTe = getAngleForTe(te, visualPos, rotationAxis);
Axis gantryAxis = Axis.X;
for (Axis axis : Iterate.axes) if (axis != rotationAxis && axis != facing.getAxis())
gantryAxis = axis;
if (gantryAxis == Axis.X)
if (facing == Direction.UP)
angleForTe *= -1;
if (gantryAxis == Axis.Y)
if (facing == Direction.NORTH || facing == Direction.EAST)
angleForTe *= -1;
SuperByteBuffer cogs = CachedBufferer.partial(AllBlockPartials.GANTRY_COGS, state);
cogs.centre().rotateY(AngleHelper.horizontalAngle(facing)).rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90).rotateY(alongFirst ^ facing.getAxis() == Axis.X ? 0 : 90).translate(0, -9 / 16f, 0).rotateX(-angleForTe).translate(0, 9 / 16f, 0).unCentre();
cogs.light(light).renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
use of com.simibubi.create.foundation.render.SuperByteBuffer 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);
}
use of com.simibubi.create.foundation.render.SuperByteBuffer 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 com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.
the class GaugeRenderer 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);
BlockState gaugeState = te.getBlockState();
GaugeTileEntity gaugeTE = (GaugeTileEntity) te;
PartialModel partialModel = (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS);
SuperByteBuffer headBuffer = CachedBufferer.partial(partialModel, gaugeState);
SuperByteBuffer dialBuffer = CachedBufferer.partial(AllBlockPartials.GAUGE_DIAL, gaugeState);
float dialPivot = 5.75f / 16;
float progress = Mth.lerp(partialTicks, gaugeTE.prevDialState, gaugeTE.dialState);
for (Direction facing : Iterate.directions) {
if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(te.getLevel(), te.getBlockPos(), gaugeState, facing))
continue;
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
rotateBufferTowards(dialBuffer, facing).translate(0, dialPivot, dialPivot).rotate(Direction.EAST, (float) (Math.PI / 2 * -progress)).translate(0, -dialPivot, -dialPivot).light(light).renderInto(ms, vb);
rotateBufferTowards(headBuffer, facing).light(light).renderInto(ms, vb);
}
}
Aggregations