• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 16839146466

08 Aug 2025 07:44PM UTC coverage: 53.102% (+0.02%) from 53.086%
16839146466

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2868 of 8744 branches covered (32.8%)

Branch coverage included in aggregate %.

17323 of 29279 relevant lines covered (59.17%)

3.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/cyclops/integrateddynamics/client/render/part/DisplayPartOverlayRenderer.java
1
package org.cyclops.integrateddynamics.client.render.part;
2

3
import com.mojang.blaze3d.vertex.PoseStack;
4
import com.mojang.math.Axis;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.renderer.MultiBufferSource;
7
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
8
import net.minecraft.core.BlockPos;
9
import net.minecraft.core.Direction;
10
import net.minecraft.world.entity.Entity;
11
import org.cyclops.cyclopscore.client.gui.image.Images;
12
import org.cyclops.integrateddynamics.api.client.render.valuetype.IValueTypeWorldRenderer;
13
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
14
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
15
import org.cyclops.integrateddynamics.api.part.IPartContainer;
16
import org.cyclops.integrateddynamics.api.part.IPartState;
17
import org.cyclops.integrateddynamics.api.part.IPartType;
18
import org.cyclops.integrateddynamics.client.render.valuetype.ValueTypeWorldRenderers;
19
import org.cyclops.integrateddynamics.part.PartTypePanelDisplay;
20

21
/**
22
 * Overlay renderer for the display part to display values on the part.
23
 * @author rubensworks
24
 */
25
public class DisplayPartOverlayRenderer extends PartOverlayRendererBase {
×
26

27
    public static final float MAX = 12.5F;
28
    protected static final float pixel = 0.0625F;  // 0.0625 == 1/16
29

30
    @Override
31
    protected void setMatrixOrientation(PoseStack matrixStack, Direction direction) {
32
        super.setMatrixOrientation(matrixStack, direction);
×
33
        float translateX = -1F - direction.getStepX() + 4 * pixel;
×
34
        float translateY = 1F - direction.getStepY() - 4 * pixel;
×
35
        float translateZ = direction.getStepZ() - pixel + 0.0025F;
×
36
        if (direction == Direction.NORTH) {
×
37
            translateZ += 1F;
×
38
        } else if (direction == Direction.EAST) {
×
39
            translateX += 1F;
×
40
            translateZ += 1F;
×
41
        } else if (direction == Direction.SOUTH) {
×
42
            translateX += 1F;
×
43
        } else if (direction == Direction.UP) {
×
44
            translateX += 1F;
×
45
            translateZ += 1F;
×
46
        } else if (direction == Direction.DOWN) {
×
47
            translateX += 1F;
×
48
            translateY -= 1F;
×
49
        }
50
        matrixStack.translate(translateX, translateY, translateZ);
×
51
    }
×
52

53
    @Override
54
    public void renderPartOverlay(BlockEntityRendererProvider.Context context, IPartContainer partContainer,
55
                                  Direction direction, IPartType partType, float partialTicks, PoseStack matrixStack,
56
                                  MultiBufferSource renderTypeBuffer, int combinedLight, int combinedOverlay) {
57
        // Set max light value, to make independent of surrounding blocks.
58
        // Otherwise, this value could become zero when in a facade with a solid block on top. #1531
59
        combinedLight = 15728640;
×
60

61
        BlockPos pos = partContainer.getPosition().getBlockPos();
×
62
        if(!shouldRender(pos)) return;
×
63

64
        // Calculate the alpha to be used when the player is almost out of rendering bounds.
65
        Entity renderEntity = Minecraft.getInstance().player;
×
66
        float distanceFactor = (float) ((getMaxRenderDistance() - renderEntity.distanceToSqr(pos.getX(), pos.getY(), pos.getZ())) / 5);
×
67
        float distanceAlpha = Math.min(1.0F, distanceFactor);
×
68
        if(distanceAlpha < 0.05F) distanceAlpha = 0.05F; // Can't be 0 because the MC font renderer doesn't handle 0 alpha's properly.
×
69

70
        matrixStack.pushPose();
×
71

72
        float scale = 0.04F;
×
73
        setMatrixOrientation(matrixStack, direction);
×
74
        matrixStack.scale(scale, scale, scale);
×
75
        matrixStack.scale(1, -1, 1);
×
76

77
        IPartState partStateUnsafe = partContainer.getPartState(direction);
×
78
        if(!(partStateUnsafe instanceof PartTypePanelDisplay.State)) {
×
79
            drawError(context, matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, distanceAlpha);
×
80
        } else {
81
            PartTypePanelDisplay.State partState = (PartTypePanelDisplay.State) partStateUnsafe;
×
82
            if (partState.getFacingRotation() == null) {
×
83
                drawError(context, matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, distanceAlpha);
×
84
                return;
×
85
            }
86
            int rotation = partState.getFacingRotation().ordinal() - 2;
×
87
            matrixStack.translate(6, 6, 0);
×
88
            matrixStack.mulPose(Axis.ZP.rotationDegrees(rotation * 90));
×
89
            matrixStack.translate(-6, -6, 0);
×
90

91
            IValue value = partState.getDisplayValue();
×
92
            if (value != null && partState.isEnabled()) {
×
93
                IValueType<?> valueType = value.getType();
×
94
                IValueTypeWorldRenderer renderer = ValueTypeWorldRenderers.REGISTRY.getRenderer(valueType);
×
95
                if (renderer == null) {
×
96
                    renderer = ValueTypeWorldRenderers.DEFAULT;
×
97
                }
98
                renderer.renderValue(context, partContainer, direction, partType, value, partialTicks, matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, distanceAlpha);
×
99
            } else if (!partState.getInventory().isEmpty()) {
×
100
                drawError(context, matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, distanceAlpha);
×
101
            }
102
        }
103

104
        matrixStack.popPose();
×
105
    }
×
106

107
    protected void drawError(BlockEntityRendererProvider.Context context, PoseStack matrixStack, MultiBufferSource renderTypeBuffer,
108
                             int combinedLight, int combinedOverlay, float distanceAlpha) {
109
        Images.ERROR.drawWorldWithAlpha(Minecraft.getInstance().getTextureManager(), matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, 12.5F, 12.5F, distanceAlpha);
×
110
    }
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc