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

CyclopsMC / IntegratedDynamics / 16552051255

27 Jul 2025 01:58PM UTC coverage: 53.206% (+8.0%) from 45.161%
16552051255

push

github

rubensworks
Resolve minor TODOs

2888 of 8740 branches covered (33.04%)

Branch coverage included in aggregate %.

17341 of 29280 relevant lines covered (59.22%)

3.08 hits per line

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

0.0
/src/main/java/org/cyclops/integrateddynamics/core/client/gui/container/ContainerScreenMultipartAspects.java
1
package org.cyclops.integrateddynamics.core.client.gui.container;
2

3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import net.minecraft.ChatFormatting;
6
import net.minecraft.client.gui.Font;
7
import net.minecraft.client.gui.GuiGraphics;
8
import net.minecraft.client.renderer.RenderPipelines;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.resources.ResourceLocation;
11
import net.minecraft.util.ARGB;
12
import net.minecraft.world.entity.player.Inventory;
13
import org.apache.commons.lang3.tuple.Triple;
14
import org.cyclops.cyclopscore.client.gui.component.button.ButtonImage;
15
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
16
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenScrolling;
17
import org.cyclops.cyclopscore.client.gui.image.IImage;
18
import org.cyclops.cyclopscore.helper.IModHelpers;
19
import org.cyclops.integrateddynamics.Reference;
20
import org.cyclops.integrateddynamics.api.part.IPartState;
21
import org.cyclops.integrateddynamics.api.part.IPartType;
22
import org.cyclops.integrateddynamics.api.part.aspect.IAspect;
23
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
24
import org.cyclops.integrateddynamics.core.inventory.container.ContainerMultipartAspects;
25

26
import java.awt.*;
27
import java.util.List;
28
import java.util.Map;
29

30
/**
31
 * Gui for parts.
32
 * @author rubensworks
33
 */
34
public abstract class ContainerScreenMultipartAspects<P extends IPartType<P, S>, S extends IPartState<P>, A extends IAspect<?, ?>, C extends ContainerMultipartAspects<P, S, A>>
35
        extends ContainerScreenScrolling<C> {
36

37
    private static final Rectangle ITEM_POSITION = new Rectangle(8, 17, 18, 18);
×
38

39
    protected final DisplayErrorsComponent displayErrors = new DisplayErrorsComponent();
×
40

41
    private Map<IAspect, ButtonText> aspectPropertyButtons = Maps.newHashMap();
×
42

43
    public ContainerScreenMultipartAspects(C container, Inventory inventory, Component title) {
44
        super(container, inventory, title);
×
45
    }
×
46

47
    @Override
48
    protected Rectangle getScrollRegion() {
49
        return new Rectangle(this.leftPos + 9, this.topPos + 18, 160, 105);
×
50
    }
51

52
    @Override
53
    public void init() {
54
        clearWidgets();
×
55
        super.init();
×
56
        if(getMenu().getPartType().getContainerProviderSettings(null).isPresent()) {
×
57
            addRenderableWidget(new ButtonImage(this.leftPos - 20, this.topPos + 0, 18, 18,
×
58
                    Component.translatable("gui.integrateddynamics.partsettings"),
×
59
                    createServerPressable(ContainerMultipartAspects.BUTTON_SETTINGS, (button) -> {}),
×
60
                    new IImage[]{
61
                            org.cyclops.integrateddynamics.client.gui.image.Images.BUTTON_BACKGROUND_INACTIVE,
62
                            org.cyclops.integrateddynamics.client.gui.image.Images.BUTTON_MIDDLE_SETTINGS
63
                    },
64
                    false, 0, 0));
65
            if (getMenu().getPartType().supportsOffsets()) {
×
66
                addRenderableWidget(new ButtonImage(this.leftPos - 20, this.topPos + 20, 18, 18,
×
67
                        Component.translatable("gui.integrateddynamics.part_offsets"),
×
68
                        createServerPressable(ContainerMultipartAspects.BUTTON_OFFSETS, (button) -> {
×
69
                        }),
×
70
                        new IImage[]{
71
                                org.cyclops.integrateddynamics.client.gui.image.Images.BUTTON_BACKGROUND_INACTIVE,
72
                                org.cyclops.integrateddynamics.client.gui.image.Images.BUTTON_MIDDLE_OFFSET
73
                        },
74
                        false, 0, 0));
75
            }
76
        }
77
        for(Map.Entry<IAspect, String> entry : getMenu().getAspectPropertyButtons().entrySet()) {
×
78
            ButtonText button = new ButtonText(-20, -20, 10, 10,
×
79
                    Component.translatable("gui.integrateddynamics.aspect_settings"), Component.literal("+"),
×
80
                    createServerPressable(entry.getValue(), b -> {}), true);
×
81
            aspectPropertyButtons.put(entry.getKey(), button);
×
82
            addRenderableWidget(button);
×
83
        }
×
84
    }
×
85

86
    protected abstract String getNameId();
87

88
    @Override
89
    protected ResourceLocation constructGuiTexture() {
90
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/" + getNameId() + ".png");
×
91
    }
92

93
    protected float colorSmoothener(float color) {
94
        return 1F - ((1F - color) / 4F);
×
95
    }
96

97
    @SuppressWarnings("unchecked")
98
    @Override
99
    protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
100
        super.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
×
101

102
        // Reset button positions
103
        for(Map.Entry<IAspect, ButtonText> entry : this.aspectPropertyButtons.entrySet()) {
×
104
            entry.getValue().setX(-20);
×
105
            entry.getValue().setY(-20);
×
106
        }
×
107

108
        // Draw part name
109
        IModHelpers.get().getRenderHelpers().drawScaledCenteredString(guiGraphics, font, title.getString(),
×
110
                this.leftPos + offsetX + 6, this.topPos + offsetY + 10, 70, ARGB.opaque(4210752), false, Font.DisplayMode.NORMAL);
×
111

112
        // Draw aspects
113
        C container = getMenu();
×
114
        int aspectBoxHeight = container.getAspectBoxHeight();
×
115
        for(int i = 0; i < container.getPageSize(); i++) {
×
116
            if(container.isElementVisible(i)) {
×
117
                A aspect = container.getVisibleElement(i);
×
118

119
                //GlStateManager._disableAlphaTest();
120
                Triple<Float, Float, Float> rgb = IModHelpers.get().getBaseHelpers().intToRGB(aspect.getValueType().getDisplayColor());
×
121
                int color = ARGB.colorFromFloat(
×
122
                        1F,
123
                        colorSmoothener(rgb.getLeft()),
×
124
                        colorSmoothener(rgb.getMiddle()),
×
125
                        colorSmoothener(rgb.getRight())
×
126
                );
127

128
                // Background
129
                guiGraphics.blit(RenderPipelines.GUI_TEXTURED, texture, leftPos + offsetX + 9,
×
130
                        topPos + offsetY + 18 + aspectBoxHeight * i, 0, getBaseYSize(), 160, aspectBoxHeight - 1, 256, 256, color);
×
131

132
                // Aspect type info
133
                String aspectName = IModHelpers.get().getL10NHelpers().localize(aspect.getTranslationKey());
×
134
                IModHelpers.get().getRenderHelpers().drawScaledCenteredString(guiGraphics, font, aspectName,
×
135
                        this.leftPos + offsetX + 26,
136
                        this.topPos + offsetY + 25 + aspectBoxHeight * i,
137
                        getMaxLabelWidth(), IModHelpers.get().getBaseHelpers().RGBAToInt(40, 40, 40, 255), false, Font.DisplayMode.NORMAL);
×
138

139
                drawAdditionalElementInfo(guiGraphics, container, i, aspect);
×
140

141
                if(aspectPropertyButtons.containsKey(aspect)) {
×
142
                    ButtonText button = aspectPropertyButtons.get(aspect);
×
143
                    button.setX(this.leftPos + offsetX + 116);
×
144
                    button.setY(this.topPos + offsetY + 20 + aspectBoxHeight * i);
×
145
                }
146
            }
147
        }
148
    }
×
149

150
    protected abstract void drawAdditionalElementInfo(GuiGraphics guiGraphics, C container, int index, A aspect);
151

152
    protected Rectangle getElementPosition(C container, int i, boolean absolute) {
153
        return new Rectangle(ITEM_POSITION.x + offsetX + (absolute ? this.leftPos : 0),
×
154
                             ITEM_POSITION.y + container.getAspectBoxHeight() * i + offsetY + (absolute ? this.topPos : 0),
×
155
                             ITEM_POSITION.width, ITEM_POSITION.height
156
        );
157
    }
158

159
    @Override
160
    protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
161
        // super.drawGuiContainerForegroundLayer(matrixStack, mouseX, mouseY);
162
        C container = getMenu();
×
163
        for(int i = 0; i < container.getPageSize(); i++) {
×
164
            if(container.isElementVisible(i)) {
×
165
                // Item icon tooltip
166
                if(isPointInRegion(getElementPosition(container, i, false), new Point(mouseX, mouseY))) {
×
167
                    List<Component> lines = Lists.newLinkedList();
×
168
                    container.getVisibleElement(i).loadTooltip(lines::add, true);
×
169
                    drawTooltip(lines, guiGraphics, mouseX, mouseY);
×
170
                }
171
                drawAdditionalElementInfoForeground(guiGraphics, container, i, container.getVisibleElement(i), mouseX, mouseY);
×
172

173
                // Optional aspect properties tooltip
174
                IAspect aspect = container.getVisibleElement(i);
×
175
                if(aspectPropertyButtons.containsKey(aspect)) {
×
176
                    ButtonText button = aspectPropertyButtons.get(aspect);
×
177
                    int x = button.getX() - leftPos;
×
178
                    int y = button.getY() - topPos;
×
179
                    if(isHovering(x, y, button.getWidth(), button.getHeight(), mouseX, mouseY)) {
×
180
                        List<Component> lines = Lists.newLinkedList();
×
181
                        lines.add(Component.translatable("gui.integrateddynamics.part.properties")
×
182
                                .withStyle(ChatFormatting.WHITE));
×
183
                        for(IAspectPropertyTypeInstance property : ((IAspect<?, ?>) aspect).getPropertyTypes()) {
×
184
                            lines.add(Component.literal("-")
×
185
                                    .withStyle(ChatFormatting.YELLOW)
×
186
                                    .append(Component.translatable(property.getTranslationKey())));
×
187
                        }
×
188
                        drawTooltip(lines, guiGraphics, mouseX, mouseY);
×
189
                    }
190
                }
191
            }
192
        }
193

194
        if (isHovering(-20, 0, 18, 18, mouseX, mouseY)) {
×
195
            drawTooltip(Lists.newArrayList(Component.translatable("gui.integrateddynamics.part_settings")), guiGraphics, mouseX, mouseY);
×
196
        }
197
        if (isHovering(-20, 20, 18, 18, mouseX, mouseY)) {
×
198
            drawTooltip(Lists.newArrayList(Component.translatable("gui.integrateddynamics.part_offsets")), guiGraphics, mouseX, mouseY);
×
199
        }
200
    }
×
201

202
    protected abstract void drawAdditionalElementInfoForeground(GuiGraphics guiGraphics, C container, int index,
203
                                                                A aspect, int mouseX, int mouseY);
204

205
    public int getMaxLabelWidth() {
206
        return 63;
×
207
    }
208
}
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