Search in sources :

Example 1 with WrappedWorld

use of com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld in project Create by Creators-of-Create.

the class BeltRenderer method renderItems.

protected void renderItems(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (!te.isController())
        return;
    if (te.beltLength == 0)
        return;
    ms.pushPose();
    Direction beltFacing = te.getBeltFacing();
    Vec3i directionVec = beltFacing.getNormal();
    Vec3 beltStartOffset = Vec3.atLowerCornerOf(directionVec).scale(-.5).add(.5, 15 / 16f, .5);
    ms.translate(beltStartOffset.x, beltStartOffset.y, beltStartOffset.z);
    BeltSlope slope = te.getBlockState().getValue(BeltBlock.SLOPE);
    int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0;
    boolean slopeAlongX = beltFacing.getAxis() == Axis.X;
    boolean onContraption = te.getLevel() instanceof WrappedWorld;
    for (TransportedItemStack transported : te.getInventory().getTransportedItems()) {
        ms.pushPose();
        TransformStack.cast(ms).nudge(transported.angle);
        float offset;
        float sideOffset;
        float verticalMovement;
        if (te.getSpeed() == 0) {
            offset = transported.beltPosition;
            sideOffset = transported.sideOffset;
        } else {
            offset = Mth.lerp(partialTicks, transported.prevBeltPosition, transported.beltPosition);
            sideOffset = Mth.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
        }
        if (offset < .5)
            verticalMovement = 0;
        else
            verticalMovement = verticality * (Math.min(offset, te.beltLength - .5f) - .5f);
        Vec3 offsetVec = Vec3.atLowerCornerOf(directionVec).scale(offset);
        if (verticalMovement != 0)
            offsetVec = offsetVec.add(0, verticalMovement, 0);
        boolean onSlope = slope != BeltSlope.HORIZONTAL && Mth.clamp(offset, .5f, te.beltLength - .5f) == offset;
        boolean tiltForward = (slope == BeltSlope.DOWNWARD ^ beltFacing.getAxisDirection() == AxisDirection.POSITIVE) == (beltFacing.getAxis() == Axis.Z);
        float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0;
        ms.translate(offsetVec.x, offsetVec.y, offsetVec.z);
        boolean alongX = beltFacing.getClockWise().getAxis() == Axis.X;
        if (!alongX)
            sideOffset *= -1;
        ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset);
        int stackLight = onContraption ? light : getPackedLight(te, offset);
        ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
        boolean renderUpright = BeltHelper.isItemUpright(transported.stack);
        boolean blockItem = itemRenderer.getModel(transported.stack, te.getLevel(), null, 0).isGui3d();
        int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2;
        Random r = new Random(transported.angle);
        boolean slopeShadowOnly = renderUpright && onSlope;
        float slopeOffset = 1 / 8f;
        if (slopeShadowOnly)
            ms.pushPose();
        if (!renderUpright || slopeShadowOnly)
            ms.mulPose(new Vector3f(slopeAlongX ? 0 : 1, 0, slopeAlongX ? 1 : 0).rotationDegrees(slopeAngle));
        if (onSlope)
            ms.translate(0, slopeOffset, 0);
        ms.pushPose();
        ms.translate(0, -1 / 8f + 0.005f, 0);
        ShadowRenderHelper.renderShadow(ms, buffer, .75f, .2f);
        ms.popPose();
        if (slopeShadowOnly) {
            ms.popPose();
            ms.translate(0, slopeOffset, 0);
        }
        if (renderUpright) {
            Entity renderViewEntity = Minecraft.getInstance().cameraEntity;
            if (renderViewEntity != null) {
                Vec3 positionVec = renderViewEntity.position();
                Vec3 vectorForOffset = BeltHelper.getVectorForOffset(te, offset);
                Vec3 diff = vectorForOffset.subtract(positionVec);
                float yRot = (float) (Mth.atan2(diff.x, diff.z) + Math.PI);
                ms.mulPose(Vector3f.YP.rotation(yRot));
            }
            ms.translate(0, 3 / 32d, 1 / 16f);
        }
        for (int i = 0; i <= count; i++) {
            ms.pushPose();
            ms.mulPose(Vector3f.YP.rotationDegrees(transported.angle));
            if (!blockItem && !renderUpright) {
                ms.translate(0, -.09375, 0);
                ms.mulPose(Vector3f.XP.rotationDegrees(90));
            }
            if (blockItem) {
                ms.translate(r.nextFloat() * .0625f * i, 0, r.nextFloat() * .0625f * i);
            }
            ms.scale(.5f, .5f, .5f);
            itemRenderer.renderStatic(null, transported.stack, TransformType.FIXED, false, ms, buffer, te.getLevel(), stackLight, overlay, 0);
            ms.popPose();
            if (!renderUpright) {
                if (!blockItem)
                    ms.mulPose(Vector3f.YP.rotationDegrees(10));
                ms.translate(0, blockItem ? 1 / 64d : 1 / 16d, 0);
            } else
                ms.translate(0, 0, -1 / 16f);
        }
        ms.popPose();
    }
    ms.popPose();
}
Also used : Vec3i(net.minecraft.core.Vec3i) Entity(net.minecraft.world.entity.Entity) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) ItemRenderer(net.minecraft.client.renderer.entity.ItemRenderer) Vector3f(com.mojang.math.Vector3f) WrappedWorld(com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld)

Aggregations

Vector3f (com.mojang.math.Vector3f)1 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)1 WrappedWorld (com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld)1 Random (java.util.Random)1 ItemRenderer (net.minecraft.client.renderer.entity.ItemRenderer)1 Direction (net.minecraft.core.Direction)1 AxisDirection (net.minecraft.core.Direction.AxisDirection)1 Vec3i (net.minecraft.core.Vec3i)1 Entity (net.minecraft.world.entity.Entity)1 Vec3 (net.minecraft.world.phys.Vec3)1