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

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 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/ContainerScreenAspectSettings.java
1
package org.cyclops.integrateddynamics.core.client.gui.container;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.gui.Font;
7
import net.minecraft.client.gui.GuiGraphics;
8
import net.minecraft.client.input.CharacterEvent;
9
import net.minecraft.client.input.KeyEvent;
10
import net.minecraft.client.input.MouseButtonEvent;
11
import net.minecraft.client.resources.language.I18n;
12
import net.minecraft.nbt.CompoundTag;
13
import net.minecraft.network.chat.Component;
14
import net.minecraft.resources.ResourceLocation;
15
import net.minecraft.world.entity.player.Inventory;
16
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
17
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended;
18
import org.cyclops.cyclopscore.helper.IModHelpers;
19
import org.cyclops.integrateddynamics.Reference;
20
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElement;
21
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElementValueType;
22
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElementValueTypeClient;
23
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
24
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
25
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
26
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
27
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
28
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.SubGuiValueTypeInfoBase;
29
import org.cyclops.integrateddynamics.core.inventory.container.ContainerAspectSettings;
30
import org.cyclops.integrateddynamics.core.logicprogrammer.client.RenderPattern;
31
import org.lwjgl.glfw.GLFW;
32

33
import java.util.List;
34

35
/**
36
 * Gui for aspect settings.
37
 * @author rubensworks
38
 */
39
public class ContainerScreenAspectSettings extends ContainerScreenExtended<ContainerAspectSettings> {
40

41
    private static final int ERROR_WIDTH = 13;
42
    private static final int ERROR_HEIGHT = 13;
43
    private static final int OK_WIDTH = 14;
44
    private static final int OK_HEIGHT = 12;
45

46
    private final List<IAspectPropertyTypeInstance> propertyTypes;
47
    protected final SubGuiHolder subGuiHolder = new SubGuiHolder();
×
48
    protected IGuiInputElementValueType<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings, IGuiInputElementValueTypeClient<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings>> guiElement = null;
×
49
    protected int activePropertyIndex = 0;
×
50
    protected RenderPattern propertyConfigPattern = null;
×
51
    protected SubGuiValueTypeInfo propertyInfo = null;
×
52
    private ButtonText buttonLeft = null;
×
53
    private ButtonText buttonRight = null;
×
54
    private ButtonText buttonExit = null;
×
55
    private Component lastError;
56

57
    public ContainerScreenAspectSettings(ContainerAspectSettings container, Inventory inventory, Component title) {
58
        super(container, inventory, title);
×
59

60
        //noinspection deprecation
61
        this.propertyTypes = Lists.newArrayList(container.getAspect().getDefaultProperties().getTypes());
×
62
    }
×
63

64
    @Override
65
    protected ResourceLocation constructGuiTexture() {
66
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/aspect_settings.png");
×
67
    }
68

69
    public int getActivePropertyIndex() {
70
        return activePropertyIndex;
×
71
    }
72

73
    protected void saveSetting() {
74
        if(guiElement != null && lastError == null) {
×
75
            container.setValue(ValueDeseralizationContext.ofClient(), getActiveProperty(), guiElement.getValue());
×
76
        }
77
    }
×
78

79
    protected void refreshButtonEnabled() {
80
        buttonLeft.active = getActivePropertyIndex() > 0;
×
81
        buttonRight.active = getActivePropertyIndex() < propertyTypes.size() - 1;
×
82
    }
×
83

84
    @Override
85
    protected int getBaseYSize() {
86
        return 213;
×
87
    }
88

89
    @Override
90
    public void init() {
91
        super.init();
×
92
        subGuiHolder.init(this.leftPos, this.topPos);
×
93
        addRenderableWidget(buttonExit = new ButtonText(leftPos + 7, topPos + 5, 12, 10, Component.translatable("gui.cyclopscore.up"), Component.literal("<<"), createServerPressable(ContainerAspectSettings.BUTTON_EXIT, (button) -> {
×
94
            saveSetting();
×
95
        }), true));
×
96
        addRenderableWidget(buttonLeft = new ButtonText(leftPos + 21, topPos + 5, 10, 10, Component.translatable("gui.cyclopscore.left"), Component.literal("<"), (button) -> {
×
97
            saveSetting();
×
98
            if(getActivePropertyIndex() > 0) {
×
99
                setActiveProperty(getActivePropertyIndex() - 1);
×
100
                refreshButtonEnabled();
×
101
            }
102
        }, true));
×
103
        addRenderableWidget(buttonRight = new ButtonText(leftPos + 159, topPos + 5, 10, 10, Component.translatable("gui.cyclopscore.right"), Component.literal(">"), (button) -> {
×
104
            saveSetting();
×
105
            if(getActivePropertyIndex() < propertyTypes.size()) {
×
106
                setActiveProperty(getActivePropertyIndex() + 1);
×
107
                refreshButtonEnabled();
×
108
            }
109
        }, true));
×
110
        refreshButtonEnabled();
×
111

112
        setActiveProperty(activePropertyIndex);
×
113
    }
×
114

115
    @Override
116
    protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
117
        super.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
×
118
        subGuiHolder.renderBg(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, partialTicks, mouseX, mouseY);
×
119
    }
×
120

121
    @Override
122
    protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
123
        // super.drawGuiContainerForegroundLayer(matrixStack, mouseX, mouseY);
124
        subGuiHolder.drawGuiContainerForegroundLayer(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, mouseX, mouseY);
×
125

126
        IAspectPropertyTypeInstance activeProperty = getActiveProperty();
×
127
        if(activeProperty != null) {
×
128
            String label = IModHelpers.get().getL10NHelpers().localize(activeProperty.getTranslationKey());
×
129
            IModHelpers.get().getRenderHelpers().drawScaledCenteredString(guiGraphics, font, label, 88, 10, 0,
×
130
                    1.0F, 140, IModHelpers.get().getBaseHelpers().RGBAToInt(10, 10, 10, 255), false, Font.DisplayMode.NORMAL);
×
131
            if (IModHelpers.get().getRenderHelpers().isPointInRegion(this.leftPos + 40, this.topPos, 110, 20, mouseX, mouseY)) {
×
132
                String unlocalizedInfo = activeProperty.getTranslationKey() + ".info";
×
133
                if (I18n.exists(unlocalizedInfo)) {
×
134
                    drawTooltip(Lists.newArrayList(Component.translatable(unlocalizedInfo)
×
135
                            .withStyle(ChatFormatting.GRAY)), guiGraphics, mouseX, mouseY + 20);
×
136
                }
137
            }
138
        }
139
    }
×
140

141
    @Override
142
    public boolean charTyped(CharacterEvent evt) {
143
        if(!subGuiHolder.charTyped(evt)) {
×
144
            if (evt.codepoint() == 1 || this.getMinecraft().options.keyInventory.getKey().getValue() == evt.codepoint()) {
×
145
                saveSetting();
×
146
                this.getMinecraft().player.closeContainer();
×
147
            } else {
148
                return super.charTyped(evt);
×
149
            }
150
        } else {
151
            if(guiElement != null) {
×
152
                onValueChanged();
×
153
            }
154
        }
155
        return false;
×
156
    }
157

158
    @Override
159
    public boolean keyPressed(KeyEvent evt) {
160
        if (evt.key() != GLFW.GLFW_KEY_ESCAPE) {
×
161
            if (this.subGuiHolder.keyPressed(evt)) {
×
162
                if(guiElement != null) {
×
163
                    onValueChanged();
×
164
                }
165
                return true;
×
166
            } else {
167
                return false;
×
168
            }
169
        } else {
170
            saveSetting();
×
171
            return super.keyPressed(evt);
×
172
        }
173
    }
174

175
    @Override
176
    public boolean mouseClicked(MouseButtonEvent evt, boolean isDoubleClick) {
177
        return subGuiHolder.mouseClicked(evt, isDoubleClick)
×
178
                || super.mouseClicked(evt, isDoubleClick);
×
179
    }
180

181
    protected void onValueChanged() {
182
        lastError = guiElement.validate();
×
183
    }
×
184

185
    protected IAspectPropertyTypeInstance getActiveProperty() {
186
        return propertyTypes.get(Math.max(0, Math.min(propertyTypes.size() - 1, activePropertyIndex)));
×
187
    }
188

189
    protected void setActiveProperty(int index) {
190
        onActivateElement(propertyTypes.get(activePropertyIndex = index));
×
191
    }
×
192

193
    protected void onActivateElement(IAspectPropertyTypeInstance property) {
194
        // Deactivate old element
195
        if(guiElement != null) {
×
196
            guiElement.deactivate();
×
197
            subGuiHolder.removeSubGui(propertyConfigPattern);
×
198
            subGuiHolder.removeSubGui(propertyInfo);
×
199
        }
200

201
        // Determine element type
202
        IValueTypeLogicProgrammerElement lpElement = property.getType().createLogicProgrammerElement();
×
203
        guiElement = lpElement.createInnerGuiElement();
×
204
        if (guiElement == null) {
×
205
            throw new UnsupportedOperationException("Tried to invoke createInnerGuiElement on a value type that does not have an inner gui element: " + property.getType().getTypeName());
×
206
        }
207

208
        // Create new element
209
        guiElement.setValidator(property.getValidator());
×
210
        subGuiHolder.addSubGui(propertyConfigPattern = guiElement.getClient().createSubGui(8, 17, 160, 91, this, (ContainerAspectSettings) getMenu()));
×
211
        subGuiHolder.addSubGui(propertyInfo = new SubGuiValueTypeInfo(guiElement));
×
212
        propertyConfigPattern.init(leftPos, topPos);
×
213
        guiElement.activate();
×
214
        syncInputValue();
×
215
        lastError = guiElement.validate();
×
216
    }
×
217

218
    protected void syncInputValue() {
219
        IAspectPropertyTypeInstance property = getActiveProperty();
×
220
        IValue value = container.getPropertyValue(ValueDeseralizationContext.of(Minecraft.getInstance().player.level()), property);
×
221
        if(value != null) {
×
222
            guiElement.setValue(value);
×
223
            guiElement.getClient().setValueInGui(propertyConfigPattern, false);
×
224
        }
225
        onValueChanged();
×
226
    }
×
227

228

229
    @Override
230
    public void onUpdate(int valueId, CompoundTag value) {
231
        super.onUpdate(valueId, value);
×
232
        IAspectPropertyTypeInstance property = container.getPropertyIds().get(valueId);
×
233
        if(property != null && getActiveProperty() == property) {
×
234
            syncInputValue();
×
235
        }
236
    }
×
237

238
    public class SubGuiValueTypeInfo extends SubGuiValueTypeInfoBase<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> {
239

240
        public SubGuiValueTypeInfo(IGuiInputElement<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings, IGuiInputElementValueTypeClient<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings>> element) {
×
241
            super(ContainerScreenAspectSettings.this, (ContainerAspectSettings) ContainerScreenAspectSettings.this.container, element, 8, 105, 160, 20);
×
242
        }
×
243

244
        @Override
245
        protected boolean showError() {
246
            return true;
×
247
        }
248

249
        @Override
250
        protected Component getLastError() {
251
            return lastError;
×
252
        }
253

254
        @Override
255
        protected ResourceLocation getTexture() {
256
            return texture;
×
257
        }
258

259
    }
260

261
}
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