use of com.simibubi.create.foundation.block.render.SpriteShiftEntry in project Create by Creators-of-Create.
the class BeltRenderer method renderSafe.
@Override
protected void renderSafe(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (!Backend.canUseInstancing(te.getLevel())) {
BlockState blockState = te.getBlockState();
if (!AllBlocks.BELT.has(blockState))
return;
BeltSlope beltSlope = blockState.getValue(BeltBlock.SLOPE);
BeltPart part = blockState.getValue(BeltBlock.PART);
Direction facing = blockState.getValue(BeltBlock.HORIZONTAL_FACING);
AxisDirection axisDirection = facing.getAxisDirection();
boolean downward = beltSlope == BeltSlope.DOWNWARD;
boolean upward = beltSlope == BeltSlope.UPWARD;
boolean diagonal = downward || upward;
boolean start = part == BeltPart.START;
boolean end = part == BeltPart.END;
boolean sideways = beltSlope == BeltSlope.SIDEWAYS;
boolean alongX = facing.getAxis() == Axis.X;
PoseStack localTransforms = new PoseStack();
TransformStack msr = TransformStack.cast(localTransforms);
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
float renderTick = AnimationTickHolder.getRenderTime(te.getLevel());
msr.centre().rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)).rotateZ(sideways ? 90 : 0).rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0).unCentre();
if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) {
boolean b = start;
start = end;
end = b;
}
DyeColor color = te.color.orElse(null);
for (boolean bottom : Iterate.trueAndFalse) {
PartialModel beltPartial = getBeltPartial(diagonal, start, end, bottom);
SuperByteBuffer beltBuffer = CachedBufferer.partial(beltPartial, blockState).light(light);
SpriteShiftEntry spriteShift = getSpriteShiftEntry(color, diagonal, bottom);
// UV shift
float speed = te.getSpeed();
if (speed != 0 || te.color.isPresent()) {
float time = renderTick * axisDirection.getStep();
if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX || sideways && axisDirection == AxisDirection.NEGATIVE)
speed = -speed;
float scrollMult = diagonal ? 3f / 8f : 0.5f;
float spriteSize = spriteShift.getTarget().getV1() - spriteShift.getTarget().getV0();
double scroll = speed * time / (31.5 * 16) + (bottom ? 0.5 : 0.0);
scroll = scroll - Math.floor(scroll);
scroll = scroll * spriteSize * scrollMult;
beltBuffer.shiftUVScrolling(spriteShift, (float) scroll);
}
beltBuffer.transform(localTransforms).renderInto(ms, vb);
// Diagonal belt do not have a separate bottom model
if (diagonal)
break;
}
if (te.hasPulley()) {
Direction dir = sideways ? Direction.UP : blockState.getValue(BeltBlock.HORIZONTAL_FACING).getClockWise();
Supplier<PoseStack> matrixStackSupplier = () -> {
PoseStack stack = new PoseStack();
TransformStack stacker = TransformStack.cast(stack);
stacker.centre();
if (dir.getAxis() == Axis.X)
stacker.rotateY(90);
if (dir.getAxis() == Axis.Y)
stacker.rotateX(90);
stacker.rotateX(90);
stacker.unCentre();
return stack;
};
SuperByteBuffer superBuffer = CachedBufferer.partialDirectional(AllBlockPartials.BELT_PULLEY, blockState, dir, matrixStackSupplier);
KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb);
}
}
renderItems(te, partialTicks, ms, buffer, light, overlay);
}
use of com.simibubi.create.foundation.block.render.SpriteShiftEntry in project Create by Creators-of-Create.
the class BeltModel method getQuads.
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData extraData) {
List<BakedQuad> quads = super.getQuads(state, side, rand, extraData);
if (!extraData.hasProperty(CASING_PROPERTY))
return quads;
CasingType type = extraData.getData(CASING_PROPERTY);
if (type == CasingType.NONE || type == CasingType.BRASS)
return quads;
quads = new ArrayList<>(quads);
SpriteShiftEntry spriteShift = AllSpriteShifts.ANDESIDE_BELT_CASING;
VertexFormat format = DefaultVertexFormat.BLOCK;
for (int i = 0; i < quads.size(); i++) {
BakedQuad quad = quads.get(i);
if (spriteShift == null)
continue;
if (quad.getSprite() != spriteShift.getOriginal())
continue;
TextureAtlasSprite original = quad.getSprite();
TextureAtlasSprite target = spriteShift.getTarget();
BakedQuad newQuad = QuadHelper.clone(quad);
int[] vertexData = newQuad.getVertices();
for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) {
int uvOffset = 16 / 4;
int uIndex = vertex + uvOffset;
int vIndex = vertex + uvOffset + 1;
float u = Float.intBitsToFloat(vertexData[uIndex]);
float v = Float.intBitsToFloat(vertexData[vIndex]);
vertexData[uIndex] = Float.floatToRawIntBits(target.getU(SuperByteBuffer.getUnInterpolatedU(original, u)));
vertexData[vIndex] = Float.floatToRawIntBits(target.getV(SuperByteBuffer.getUnInterpolatedV(original, v)));
}
quads.set(i, newQuad);
}
return quads;
}
use of com.simibubi.create.foundation.block.render.SpriteShiftEntry in project Create by Creators-of-Create.
the class BeltInstance method update.
@Override
public void update() {
DyeColor color = blockEntity.color.orElse(null);
boolean bottom = true;
for (BeltData key : keys) {
SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
key.setScrollTexture(spriteShiftEntry).setColor(blockEntity).setRotationalSpeed(getScrollSpeed());
bottom = false;
}
if (pulleyKey != null) {
updateRotation(pulleyKey);
}
}
Aggregations