Search in sources :

Example 1 with SpriteShiftEntry

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);
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) DyeColor(net.minecraft.world.item.DyeColor) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockState(net.minecraft.world.level.block.state.BlockState) AxisDirection(net.minecraft.core.Direction.AxisDirection) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) PartialModel(com.jozufozu.flywheel.core.PartialModel) SpriteShiftEntry(com.simibubi.create.foundation.block.render.SpriteShiftEntry)

Example 2 with SpriteShiftEntry

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;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) CasingType(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) DefaultVertexFormat(com.mojang.blaze3d.vertex.DefaultVertexFormat) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat) SpriteShiftEntry(com.simibubi.create.foundation.block.render.SpriteShiftEntry)

Example 3 with SpriteShiftEntry

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);
    }
}
Also used : BeltData(com.simibubi.create.content.contraptions.base.flwdata.BeltData) DyeColor(net.minecraft.world.item.DyeColor) SpriteShiftEntry(com.simibubi.create.foundation.block.render.SpriteShiftEntry)

Aggregations

SpriteShiftEntry (com.simibubi.create.foundation.block.render.SpriteShiftEntry)3 DyeColor (net.minecraft.world.item.DyeColor)2 PartialModel (com.jozufozu.flywheel.core.PartialModel)1 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)1 DefaultVertexFormat (com.mojang.blaze3d.vertex.DefaultVertexFormat)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 VertexFormat (com.mojang.blaze3d.vertex.VertexFormat)1 BeltData (com.simibubi.create.content.contraptions.base.flwdata.BeltData)1 CasingType (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType)1 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 Direction (net.minecraft.core.Direction)1 AxisDirection (net.minecraft.core.Direction.AxisDirection)1 BlockState (net.minecraft.world.level.block.state.BlockState)1