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

CyclopsMC / IntegratedDynamics / 16601227395

29 Jul 2025 03:58PM UTC coverage: 44.876% (+0.02%) from 44.855%
16601227395

push

github

rubensworks
Bump mod version

2574 of 8522 branches covered (30.2%)

Branch coverage included in aggregate %.

11766 of 23433 relevant lines covered (50.21%)

2.38 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 net.neoforged.api.distmarker.Dist;
12
import net.neoforged.api.distmarker.OnlyIn;
13
import org.cyclops.cyclopscore.client.gui.image.Images;
14
import org.cyclops.integrateddynamics.api.client.render.valuetype.IValueTypeWorldRenderer;
15
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
16
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
17
import org.cyclops.integrateddynamics.api.part.IPartContainer;
18
import org.cyclops.integrateddynamics.api.part.IPartState;
19
import org.cyclops.integrateddynamics.api.part.IPartType;
20
import org.cyclops.integrateddynamics.client.render.valuetype.ValueTypeWorldRenderers;
21
import org.cyclops.integrateddynamics.part.PartTypePanelDisplay;
22

23
/**
24
 * Overlay renderer for the display part to display values on the part.
25
 * @author rubensworks
26
 */
27
@OnlyIn(Dist.CLIENT)
28
public class DisplayPartOverlayRenderer extends PartOverlayRendererBase {
×
29

30
    public static final float MAX = 12.5F;
31
    protected static final float pixel = 0.0625F;  // 0.0625 == 1/16
32

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

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

64
        BlockPos pos = partContainer.getPosition().getBlockPos();
×
65
        if(!shouldRender(pos)) return;
×
66

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

73
        matrixStack.pushPose();
×
74

75
        float scale = 0.04F;
×
76
        setMatrixOrientation(matrixStack, direction);
×
77
        matrixStack.scale(scale, scale, scale);
×
78
        matrixStack.scale(1, -1, 1);
×
79

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

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

107
        matrixStack.popPose();
×
108
    }
×
109

110
    protected void drawError(BlockEntityRendererProvider.Context context, PoseStack matrixStack, MultiBufferSource renderTypeBuffer,
111
                             int combinedLight, int combinedOverlay, float distanceAlpha) {
112
        Images.ERROR.drawWorldWithAlpha(Minecraft.getInstance().getTextureManager(), matrixStack, renderTypeBuffer, combinedLight, combinedOverlay, 12.5F, 12.5F, distanceAlpha);
×
113
    }
×
114
}
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