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

CyclopsMC / IntegratedDynamics / 13739195914

08 Mar 2025 03:58PM UTC coverage: 39.059% (+0.06%) from 39.002%
13739195914

push

github

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

1966 of 8373 branches covered (23.48%)

Branch coverage included in aggregate %.

10307 of 23049 relevant lines covered (44.72%)

2.1 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/logicprogrammer/ValueTypeRecipeLPElementPropertiesSubGui.java
1
package org.cyclops.integrateddynamics.core.logicprogrammer;
2

3
import com.google.common.collect.Sets;
4
import net.minecraft.client.Minecraft;
5
import net.minecraft.client.gui.Font;
6
import net.minecraft.client.gui.GuiGraphics;
7
import net.minecraft.client.renderer.texture.TextureManager;
8
import net.minecraft.core.Holder;
9
import net.minecraft.core.HolderSet;
10
import net.minecraft.core.registries.BuiltInRegistries;
11
import net.minecraft.core.registries.Registries;
12
import net.minecraft.network.chat.Component;
13
import net.minecraft.network.chat.MutableComponent;
14
import net.minecraft.resources.ResourceLocation;
15
import net.minecraft.tags.TagKey;
16
import net.minecraft.world.item.Item;
17
import net.minecraft.world.item.ItemStack;
18
import net.neoforged.api.distmarker.Dist;
19
import net.neoforged.api.distmarker.OnlyIn;
20
import org.cyclops.cyclopscore.client.gui.component.button.ButtonCheckbox;
21
import org.cyclops.cyclopscore.client.gui.component.button.ButtonImage;
22
import org.cyclops.cyclopscore.client.gui.image.Images;
23
import org.cyclops.cyclopscore.helper.IModHelpers;
24
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerBase;
25
import org.cyclops.integrateddynamics.core.client.gui.IDropdownEntry;
26
import org.cyclops.integrateddynamics.core.client.gui.WidgetTextFieldDropdown;
27
import org.cyclops.integrateddynamics.core.helper.L10NValues;
28
import org.cyclops.integrateddynamics.core.ingredient.ItemMatchProperties;
29
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
30

31
import java.util.Collections;
32
import java.util.LinkedHashSet;
33
import java.util.List;
34
import java.util.Set;
35

36
/**
37
 * Selection panel for the list element value type.
38
 */
39
@OnlyIn(Dist.CLIENT)
40
class ValueTypeRecipeLPElementPropertiesSubGui extends RenderPattern<ValueTypeRecipeLPElement, ContainerScreenLogicProgrammerBase, ContainerLogicProgrammerBase> {
41

42
    private final int slotId;
43
    private ButtonCheckbox inputNbt;
44
    private ButtonCheckbox inputTags;
45
    private ButtonCheckbox inputReusable;
46
    private WidgetTextFieldDropdown<ResourceLocation> inputTagsDropdown;
47
    private ButtonImage inputSave;
48

49
    public ValueTypeRecipeLPElementPropertiesSubGui(ValueTypeRecipeLPElement element, int baseX, int baseY, int maxWidth, int maxHeight,
50
                                                    ContainerScreenLogicProgrammerBase gui, ContainerLogicProgrammerBase container,
51
                                                    int slotId) {
52
        super(element, baseX, baseY, maxWidth, maxHeight, gui, container);
×
53
        this.slotId = slotId;
×
54
    }
×
55

56
    @Override
57
    public void init(int guiLeft, int guiTop) {
58
        super.init(guiLeft, guiTop);
×
59

60
        this.inputNbt = new ButtonCheckbox(guiLeft + getX() + 2, guiTop + getY() + 2, 20, 10,
×
61
                Component.translatable(L10NValues.GUI_RECIPE_STRICTNBT), (entry) ->  {
×
62
            // Only allow one checkbox to be true at the same time
63
            if (this.inputNbt.isChecked()) {
×
64
                this.inputTags.setChecked(false);
×
65
            }
66
            saveGuiToState();
×
67
            loadStateToGui();
×
68
        });
×
69
        this.inputReusable = new ButtonCheckbox(guiLeft + getX() + 2, guiTop + getY() + 12, 20, 10,
×
70
                Component.translatable(L10NValues.GUI_RECIPE_REUSABLE), (entry) -> {
×
71
            saveGuiToState();
×
72
            loadStateToGui();
×
73
        });
×
74
        this.inputTags = new ButtonCheckbox(guiLeft + getX() + 2, guiTop + getY() + 22, 20, 10,
×
75
                Component.translatable(L10NValues.GUI_RECIPE_TAGVARIANTS), (entry) -> {
×
76
            // Only allow one checkbox to be true at the same time
77
            if (this.inputTags.isChecked()) {
×
78
                this.inputNbt.setChecked(false);
×
79
            }
80
            saveGuiToState();
×
81
            loadStateToGui();
×
82
            if (this.inputTags.isChecked()) {
×
83
                this.inputTagsDropdown.setFocused(true);
×
84
            }
85
        });
×
86
        this.inputTagsDropdown = new WidgetTextFieldDropdown<>(Minecraft.getInstance().font,
×
87
                guiLeft + getX() + 2, guiTop + getY() + 33,
×
88
                134, 14,
89
                Component.translatable("gui.cyclopscore.search"), true,
×
90
                Sets.newHashSet());
×
91
        this.inputTagsDropdown.setDropdownEntryListener((entry) -> saveGuiToState());
×
92
        this.inputTagsDropdown.setMaxLength(64);
×
93
        this.inputTagsDropdown.setDropdownSize(4);
×
94
        this.inputTagsDropdown.setBordered(false);
×
95
        this.inputTagsDropdown.setTextColor(16777215);
×
96
        this.inputTagsDropdown.setCanLoseFocus(true);
×
97
        this.inputSave = new ButtonImage(guiLeft + getX() + 116, guiTop + getY() + 72,
×
98
                Component.translatable("gui.integrateddynamics.button.save"),
×
99
                (button) -> {
100
            // If tag checkbox is checked, only allow exiting if a valid tag has been set
101
            if (!this.inputTags.isChecked() || this.inputTagsDropdown.getSelectedDropdownPossibility() != null) {
×
102
                element.lastGui.setRecipeSubGui();
×
103
            } else {
104
                this.inputTagsDropdown.setFocused(true);
×
105
            }
106
                }, Images.OK);
×
107

108
        // Load button states
109
        loadStateToGui();
×
110
        // Show dropdown if a tag was already set
111
        if (this.inputTags.isChecked()) {
×
112
            this.inputTagsDropdown.setFocused(true);
×
113
        }
114
    }
×
115

116
    public ItemStack getSlotContents() {
117
        return container.slots.get(slotId + ValueTypeRecipeLPElement.SLOT_OFFSET).getItem();
×
118
    }
119

120
    public ItemMatchProperties getSlotProperties() {
121
        return getElement().getInputStacks().get(slotId);
×
122
    }
123

124
    private Set<IDropdownEntry<ResourceLocation>> getDropdownEntries() {
125
        LinkedHashSet<IDropdownEntry<ResourceLocation>> set = Sets.newLinkedHashSet();
×
126
        if (getSlotContents().isEmpty()) {
×
127
            BuiltInRegistries.ITEM.listTagIds()
×
128
                    .forEach(registeredTag -> set.add(new DropdownEntry(registeredTag.location())));
×
129

130
        } else {
131
            getSlotContents().getItem().builtInRegistryHolder().tags()
×
132
                    .forEach(registeredTag -> set.add(new DropdownEntry(registeredTag.location())));
×
133
        }
134
        return set;
×
135
    }
136

137
    public void loadStateToGui() {
138
        ItemMatchProperties props = getSlotProperties();
×
139
        this.inputNbt.setChecked(props.isNbt());
×
140
        this.inputTags.setChecked(props.getItemTag() != null);
×
141
        this.inputReusable.setChecked(props.isReusable());
×
142
        this.inputTagsDropdown.setVisible(this.inputTags.isChecked());
×
143

144
        if (this.inputTags.isChecked()) {
×
145
            Set<IDropdownEntry<ResourceLocation>> dropdownEntries = getDropdownEntries();
×
146
            this.inputTagsDropdown.setPossibilities(dropdownEntries);
×
147
            if (props.getItemTag() != null) {
×
148
                this.inputTagsDropdown.selectPossibility(dropdownEntries.stream()
×
149
                        .filter(e -> e.getMatchString().equals(props.getItemTag()))
×
150
                        .findFirst()
×
151
                        .orElse(null));
×
152
            } else {
153
                if (!dropdownEntries.isEmpty()) {
×
154
                    this.inputTagsDropdown.selectPossibility(dropdownEntries.iterator().next());
×
155
                } else {
156
                    this.inputTagsDropdown.selectPossibility(null);
×
157
                }
158
            }
159
        } else {
×
160
            this.inputTagsDropdown.setValue("");
×
161
            this.inputTagsDropdown.setPossibilities(Collections.emptySet());
×
162
        }
163
    }
×
164

165
    public void saveGuiToState() {
166
        boolean nbt = this.inputNbt.isChecked();
×
167
        String tag = this.inputTags.isChecked() ? this.inputTagsDropdown.getValue() : null;
×
168
        getSlotProperties().setNbt(nbt);
×
169
        getSlotProperties().setItemTag(tag);
×
170
        getSlotProperties().setReusable(this.inputReusable.isChecked());
×
171
        element.sendSlotPropertiesToServer(slotId, getSlotProperties());
×
172
    }
×
173

174
    @Override
175
    protected boolean drawRenderPattern() {
176
        return false;
×
177
    }
178

179
    @Override
180
    public void renderBg(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, float partialTicks, int mouseX, int mouseY) {
181
        super.renderBg(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, partialTicks, mouseX, mouseY);
×
182

183
        drawSlot(guiGraphics, getX() + guiLeft + 116, getY() + guiTop + 2);
×
184

185
        this.inputNbt.render(guiGraphics, mouseX, mouseY, partialTicks);
×
186
        guiGraphics.drawString(fontRenderer, IModHelpers.get().getL10NHelpers().localize(L10NValues.GUI_RECIPE_STRICTNBT), guiLeft + getX() + 24, guiTop + getY() + 3, 0, false);
×
187
        this.inputReusable.render(guiGraphics, mouseX, mouseY, partialTicks);
×
188
        guiGraphics.drawString(fontRenderer, IModHelpers.get().getL10NHelpers().localize(L10NValues.GUI_RECIPE_REUSABLE), guiLeft + getX() + 24, guiTop + getY() + 13, 0, false);
×
189
        this.inputTags.render(guiGraphics, mouseX, mouseY, partialTicks);
×
190
        guiGraphics.drawString(fontRenderer, IModHelpers.get().getL10NHelpers().localize(L10NValues.GUI_RECIPE_TAGVARIANTS), guiLeft + getX() + 24, guiTop + getY() + 23, 0, false);
×
191
        this.inputSave.render(guiGraphics, mouseX, mouseY, partialTicks);
×
192
        this.inputTagsDropdown.render(guiGraphics, mouseX, mouseY, partialTicks);
×
193
    }
×
194

195
    @Override
196
    public void drawGuiContainerForegroundLayer(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, int mouseX, int mouseY) {
197
        super.drawGuiContainerForegroundLayer(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, mouseX, mouseY);
×
198

199
        if (this.inputTagsDropdown.isFocused()) {
×
200
            int i = this.inputTagsDropdown.getHoveredVisiblePossibility(mouseX, mouseY);
×
201
            if (i >= 0) {
×
202
                IDropdownEntry<ResourceLocation> hoveredPossibility = this.inputTagsDropdown.getVisiblePossibility(i);
×
203
                drawTagsTooltip(guiGraphics, hoveredPossibility, guiLeft, guiTop, mouseX + 10, mouseY - 20, 6, IModHelpers.get().getGuiHelpers().getSlotSize());
×
204
            }
205
        }
206
    }
×
207

208
    protected void drawTagsTooltip(GuiGraphics guiGraphics, IDropdownEntry<ResourceLocation> hoveredPossibility, int guiLeft, int guiTop,
209
                                   int mouseX, int mouseY, int columns, int offset) {
210
        int x = mouseX - guiLeft;
×
211
        int y = mouseY - guiTop;
×
212
        List<Item> items = BuiltInRegistries.ITEM.get(TagKey.create(Registries.ITEM, hoveredPossibility.getValue()))
×
213
                .stream()
×
214
                .flatMap(HolderSet.ListBacked::stream)
×
215
                .map(Holder::value)
×
216
                .toList();
×
217

218
        // Draw background
219
        IModHelpers.get().getGuiHelpers().drawTooltipBackground(guiGraphics.pose(), x, y, Math.min(items.size(), columns) * offset,
×
220
                ((items.size() % columns == 0 ? 0 : 1) + (items.size() / columns)) * offset);
×
221

222
        // Draw item grid
223
        guiGraphics.pose().pushPose();
×
224
        guiGraphics.pose().translate(0, 0, 1000);
×
225
        int passed = 0;
×
226
        for (Item item : items) {
×
227
            guiGraphics.renderItem(new ItemStack(item), x, y);
×
228
            x += offset;
×
229
            if (passed++ % columns == columns - 1) {
×
230
                y += offset;
×
231
                x = mouseX - guiLeft;
×
232
            }
233
        }
×
234
        guiGraphics.pose().popPose();
×
235
    }
×
236

237
    @Override
238
    public boolean charTyped(char typedChar, int keyCode) {
239
        if (inputTagsDropdown.isFocused()) {
×
240
            if (inputTagsDropdown.charTyped(typedChar, keyCode)) {
×
241
                return true;
×
242
            }
243
        }
244
        return super.charTyped(typedChar, keyCode);
×
245
    }
246

247
    @Override
248
    public boolean keyPressed(int typedChar, int keyCode, int modifiers) {
249
        if (inputTagsDropdown.isFocused()) {
×
250
            inputTagsDropdown.keyPressed(typedChar, keyCode, modifiers);
×
251
            return true;
×
252
        }
253
        return super.keyPressed(typedChar, keyCode, modifiers);
×
254
    }
255

256
    @Override
257
    public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
258
        return inputNbt.mouseClicked(mouseX, mouseY, mouseButton)
×
259
                || inputReusable.mouseClicked(mouseX, mouseY, mouseButton)
×
260
                || inputTags.mouseClicked(mouseX, mouseY, mouseButton)
×
261
                || inputTagsDropdown.mouseClicked(mouseX, mouseY, mouseButton)
×
262
                || inputSave.mouseClicked(mouseX, mouseY, mouseButton)
×
263
                || super.mouseClicked(mouseX, mouseY, mouseButton);
×
264
    }
265

266
    public static class DropdownEntry implements IDropdownEntry<ResourceLocation> {
267
        private final ResourceLocation tag;
268

269
        public DropdownEntry(ResourceLocation tag) {
×
270
            this.tag = tag;
×
271
        }
×
272

273
        @Override
274
        public String getMatchString() {
275
            return this.tag.toString();
×
276
        }
277

278
        @Override
279
        public MutableComponent getDisplayString() {
280
            return Component.literal(this.tag.toString());
×
281
        }
282

283
        @Override
284
        public List<MutableComponent> getTooltip() {
285
            return Collections.emptyList();
×
286
        }
287

288
        @Override
289
        public ResourceLocation getValue() {
290
            return this.tag;
×
291
        }
292
    }
293
}
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