Skip to content

Commit 26c2e68

Browse files
committed
Revert some changes to click handling that caused crashes
1 parent 8763cba commit 26c2e68

20 files changed

+57
-73
lines changed

src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class GuiResizeControls extends GuiSideHolder {
3030
public <GUI extends IGuiWrapper & ResizeController> GuiResizeControls(GUI gui, int y) {
3131
super(gui, -26, y, 39, true, false);
3232
expandButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 5, 19, 9, 19, 9, PLUS,
33-
(element, mouseX, mouseY) -> ((GuiResizeControls) element).handleResize(ResizeType.EXPAND_Y, Screen.hasShiftDown())));
33+
(element, mouseX, mouseY) -> handleResize(ResizeType.EXPAND_Y, Screen.hasShiftDown())));
3434
shrinkButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 25, 19, 9, 19, 9, MINUS,
35-
(element, mouseX, mouseY) -> ((GuiResizeControls) element).handleResize(ResizeType.SHRINK_Y, Screen.hasShiftDown())));
35+
(element, mouseX, mouseY) -> handleResize(ResizeType.SHRINK_Y, Screen.hasShiftDown())));
3636
updateButtonState();
3737
active = true;
3838
}

src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class GuiColorWindow extends GuiWindow {
4242
private final boolean handlesAlpha;
4343
@Nullable
4444
private final Consumer<Color> updatePreviewColor;
45-
private final Consumer<Color> callback;
4645
@Nullable
4746
private final Runnable previewReset;
4847

@@ -59,7 +58,6 @@ public GuiColorWindow(IGuiWrapper gui, int x, int y, boolean handlesAlpha, Consu
5958
@Nullable Consumer<Color> updatePreviewColor, @Nullable Runnable previewReset) {
6059
super(gui, x, y, (handlesAlpha ? 184 : 158) + (armorPreview == null ? 0 : 83), handlesAlpha ? 152 : 140, WindowType.COLOR);
6160
interactionStrategy = InteractionStrategy.NONE;
62-
this.callback = callback;
6361
this.handlesAlpha = handlesAlpha;
6462
this.updatePreviewColor = updatePreviewColor;
6563
this.previewReset = previewReset;
@@ -88,9 +86,8 @@ public GuiColorWindow(IGuiWrapper gui, int x, int y, boolean handlesAlpha, Consu
8886
.setBackground(BackgroundType.ELEMENT_HOLDER)
8987
.setMaxLength(this.handlesAlpha ? 15 : 11);
9088
addChild(new TranslationButton(gui, relativeX + 98 + extraWidth, relativeY + height - 21, 54, 14, MekanismLang.BUTTON_CONFIRM, (element, mouseX, mouseY) -> {
91-
GuiColorWindow colorWindow = (GuiColorWindow) element;
92-
colorWindow.callback.accept(colorWindow.getColor());
93-
return colorWindow.close(element, mouseX, mouseY);
89+
callback.accept(getColor());
90+
return close(element, mouseX, mouseY);
9491
}));
9592

9693
if (armorPreview != null) {

src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
public class GuiConfirmationDialog extends GuiWindow {
1313

1414
private final WrappedTextRenderer wrappedTextRenderer;
15-
private final Runnable onConfirm;
1615

1716
private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int height, Component title, Runnable onConfirm, DialogType type) {
1817
super(gui, x, y, width, height, WindowType.CONFIRMATION);
1918
this.wrappedTextRenderer = new WrappedTextRenderer(this, title);
20-
this.onConfirm = onConfirm;
2119
active = true;
2220

2321
addChild(new TranslationButton(gui, relativeX + width / 2 - 51, relativeY + height - 24, 50, 18, MekanismLang.BUTTON_CANCEL, this::close));
2422
addChild(new TranslationButton(gui, relativeX + width / 2 + 1, relativeY + height - 24, 50, 18, MekanismLang.BUTTON_CONFIRM, (element, mouseX, mouseY) -> {
25-
GuiConfirmationDialog confirmation = (GuiConfirmationDialog) element;
26-
confirmation.onConfirm.run();
27-
return confirmation.close(element, mouseX, mouseY);
23+
onConfirm.run();
24+
return close(element, mouseX, mouseY);
2825
}, type.getColorSupplier()));
2926
}
3027

src/main/java/mekanism/client/gui/element/window/GuiCraftingWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public GuiCraftingWindow(IGuiWrapper gui, int x, int y, QIOItemViewerContainer c
4444
slots.add(addChild(new GuiVirtualSlot(this, SlotType.NORMAL, gui, relativeX + 100, relativeY + 36,
4545
this.container.getCraftingWindowSlot(this.index, 9))));
4646
addChild(new MekanismImageButton(gui, relativeX + width - 20, relativeY + height - 20, 14, getButtonLocation("clear_sides"),
47-
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketQIOClearCraftingWindow(((GuiCraftingWindow) element).index, Screen.hasShiftDown()))))
47+
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketQIOClearCraftingWindow(index, Screen.hasShiftDown()))))
4848
.setTooltip(MekanismLang.CRAFTING_WINDOW_CLEAR);
4949
}
5050

src/main/java/mekanism/client/gui/element/window/GuiRobitRename.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public class GuiRobitRename extends GuiWindow {
1818
public GuiRobitRename(IGuiWrapper gui, int x, int y, EntityRobit robit) {
1919
super(gui, x, y, 172, 58, WindowType.RENAME);
2020
this.robit = robit;
21-
addChild(new TranslationButton(gui, relativeX + 56, relativeY + 32, 60, 20, MekanismLang.BUTTON_CONFIRM,
22-
(element, mouseX, mouseY) -> ((GuiRobitRename) element).changeName()));
21+
addChild(new TranslationButton(gui, relativeX + 56, relativeY + 32, 60, 20, MekanismLang.BUTTON_CONFIRM, (element, mouseX, mouseY) -> changeName()));
2322
nameChangeField = addChild(new GuiTextField(gui, this, relativeX + 21, relativeY + 17, width - 42, 12));
2423
nameChangeField.setMaxLength(PacketRobitName.MAX_NAME_LENGTH);
2524
nameChangeField.setCanLoseFocus(false);

src/main/java/mekanism/client/gui/element/window/GuiRobitSkinSelect.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ public GuiRobitSkinSelect(GuiRobitMain gui, int x, int y, EntityRobit robit) {
2727
selection = addChild(new GuiRobitSkinSelectScroll(gui(), relativeX + 6, relativeY + 18, this.robit, () -> gui.getMenu().getUnlockedSkins()));
2828
addChild(new TranslationButton(gui, relativeX + width / 2 - 61, relativeY + 165, 60, 20, MekanismLang.BUTTON_CANCEL, this::close));
2929
addChild(new TranslationButton(gui, relativeX + width / 2 + 1, relativeY + 165, 60, 20, MekanismLang.BUTTON_CONFIRM, (element, mouseX, mouseY) -> {
30-
GuiRobitSkinSelect select = (GuiRobitSkinSelect) element;
31-
ResourceKey<RobitSkin> selectedSkin = select.selection.getSelectedSkin();
32-
if (selectedSkin != select.robit.getSkin()) {
33-
PacketUtils.sendToServer(new PacketRobitSkin(select.robit, selectedSkin));
30+
ResourceKey<RobitSkin> selectedSkin = selection.getSelectedSkin();
31+
if (selectedSkin != this.robit.getSkin()) {
32+
PacketUtils.sendToServer(new PacketRobitSkin(this.robit, selectedSkin));
3433
}
35-
return select.close(element, mouseX, mouseY);
34+
return close(element, mouseX, mouseY);
3635
}));
3736
gui.getMenu().startTracking(MekanismContainer.SKIN_SELECT_WINDOW, gui.getMenu());
3837
PacketUtils.sendToServer(new PacketGuiInteract(GuiInteractionEntity.CONTAINER_TRACK_SKIN_SELECT, this.robit, MekanismContainer.SKIN_SELECT_WINDOW));

src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,16 @@ public GuiSideConfiguration(IGuiWrapper gui, int x, int y, TILE tile, SelectedWi
7878
addChild(tab);
7979
configTabs.add(tab);
8080
}
81-
ejectButton = addChild(new MekanismImageButton(gui, relativeX + 136, relativeY + 6, 14, getButtonLocation("auto_eject"), (element, mouseX, mouseY) -> {
82-
GuiSideConfiguration<?> self = (GuiSideConfiguration<?>) element;
83-
return PacketUtils.sendToServer(new PacketEjectConfiguration(self.tile.getBlockPos(), self.currentType));
84-
})).setTooltip(MekanismLang.AUTO_EJECT);
81+
ejectButton = addChild(new MekanismImageButton(gui, relativeX + 136, relativeY + 6, 14, getButtonLocation("auto_eject"),
82+
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketEjectConfiguration(this.tile.getBlockPos(), currentType))))
83+
.setTooltip(MekanismLang.AUTO_EJECT);
8584
addChild(new TooltipToggleButton(gui, relativeX + 136, relativeY + 95, 14, getButtonLocation("clear_sides"),
8685
() -> getTargetType(DataType::getNext) == DataType.NONE, (element, mouseX, mouseY) -> {
87-
//TODO - 1.20.4: Fix how this cast causing a crash because it really is a toggle button
88-
GuiSideConfiguration<?> self = (GuiSideConfiguration<?>) element;
89-
DataType targetType = self.getTargetType(DataType::getNext);
90-
return PacketUtils.sendToServer(new PacketBatchConfiguration(self.tile.getBlockPos(), Screen.hasShiftDown() ? null : self.currentType, targetType));
86+
DataType targetType = getTargetType(DataType::getNext);
87+
return PacketUtils.sendToServer(new PacketBatchConfiguration(this.tile.getBlockPos(), Screen.hasShiftDown() ? null : currentType, targetType));
9188
}, (element, mouseX, mouseY) -> {
92-
GuiSideConfiguration<?> self = (GuiSideConfiguration<?>) element;
93-
DataType targetType = self.getTargetType(DataType::getPrevious);
94-
return PacketUtils.sendToServer(new PacketBatchConfiguration(self.tile.getBlockPos(), Screen.hasShiftDown() ? null : self.currentType, targetType));
89+
DataType targetType = getTargetType(DataType::getPrevious);
90+
return PacketUtils.sendToServer(new PacketBatchConfiguration(this.tile.getBlockPos(), Screen.hasShiftDown() ? null : currentType, targetType));
9591
}, MultiLineTooltip.createMulti(MekanismLang.SIDE_CONFIG_CLEAR.translate(), MekanismLang.SIDE_CONFIG_CLEAR_ALL.translate()),
9692
Tooltip.create(MekanismLang.SIDE_CONFIG_INCREMENT.translate())));
9793
addSideDataButton(RelativeSide.BOTTOM, 68, 92);

src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public GuiTransporterConfig(IGuiWrapper gui, int x, int y, TILE tile, SelectedWi
4242
() -> Collections.singletonList(MekanismLang.STRICT_INPUT_ENABLED.translate(OnOff.of(tile.getEjector().hasStrictInput())))));
4343
addChild(new GuiSlot(SlotType.NORMAL, gui, relativeX + 111, relativeY + 48));
4444
addChild(new MekanismImageButton(gui, relativeX + 136, relativeY + 6, 14, 16, getButtonLocation("exclamation"),
45-
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.STRICT_INPUT, ((GuiTransporterConfig<?>) element).tile))))
45+
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.STRICT_INPUT, this.tile))))
4646
.setTooltip(MekanismLang.STRICT_INPUT);
4747
addChild(new ColorButton(gui, relativeX + 112, relativeY + 49, 16, 16, () -> this.tile.getEjector().getOutputColor(),
48-
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketEjectColor(((GuiTransporterConfig<?>) element).tile.getBlockPos(), MekClickType.left(Screen.hasShiftDown()))),
49-
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketEjectColor(((GuiTransporterConfig<?>) element).tile.getBlockPos(), MekClickType.RIGHT))));
48+
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketEjectColor(this.tile.getBlockPos(), MekClickType.left(Screen.hasShiftDown()))),
49+
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketEjectColor(this.tile.getBlockPos(), MekClickType.RIGHT))));
5050
addSideDataButton(RelativeSide.BOTTOM, 41, 64 + 16);
5151
addSideDataButton(RelativeSide.TOP, 41, 34);
5252
addSideDataButton(RelativeSide.FRONT, 41, 57);

src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile,
4949
addChild(new GuiProgress(() -> this.tile.getComponent().getScaledUpgradeProgress(), ProgressType.INSTALLING, gui, relativeX + 134, relativeY + 37));
5050
addChild(new GuiProgress(() -> 0, ProgressType.UNINSTALLING, gui, relativeX + 134, relativeY + 59));
5151
removeButton = addChild(new DigitalButton(gui, relativeX + 73, relativeY + 54, 56, 12, MekanismLang.UPGRADE_UNINSTALL, (element, mouseX, mouseY) -> {
52-
GuiUpgradeWindow self = (GuiUpgradeWindow) element;
53-
if (self.scrollList.hasSelection()) {
52+
if (scrollList.hasSelection()) {
5453
return PacketUtils.sendToServer(new PacketGuiInteract(Screen.hasShiftDown() ? GuiInteraction.REMOVE_ALL_UPGRADE : GuiInteraction.REMOVE_UPGRADE,
55-
self.tile, self.scrollList.getSelection().ordinal()));
54+
this.tile, scrollList.getSelection().ordinal()));
5655
}
5756
return false;
5857
}));

src/main/java/mekanism/client/gui/element/window/filter/GuiFilter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ protected GuiFilter(IGuiWrapper gui, int x, int y, int width, int height, Compon
6969
addChild(new MekanismImageButton(gui, relativeX + 6, relativeY + 6, 11, 14, getButtonLocation("back"), (element, mouseX, mouseY) -> {
7070
//Add the window for the filter select dialog to the parent gui
7171
IGuiWrapper wrapper = element.gui();
72-
GuiFilter<?, TILE> guiFilter = (GuiFilter<?, TILE>) element;
73-
wrapper.addWindow(guiFilter.getFilterSelect(wrapper, guiFilter.tile));
72+
wrapper.addWindow(getFilterSelect(wrapper, this.tile));
7473
//And close the filter
7574
return close(element, mouseX, mouseY);
7675
})).setTooltip(MekanismLang.BACK);
@@ -124,14 +123,13 @@ protected void init() {
124123
addChild(new GuiInnerScreen(gui(), relativeX + 29, screenTop, getScreenWidth(), getScreenHeight(), this::getScreenText).clearFormat());
125124
addChild(new TranslationButton(gui(), getLeftButtonX(), screenBottom + 2, 60, 20,
126125
isNew ? MekanismLang.BUTTON_CANCEL : MekanismLang.BUTTON_DELETE, (element, mouseX, mouseY) -> {
127-
GuiFilter<FILTER, ?> self = (GuiFilter<FILTER, ?>) element;
128-
if (self.origFilter != null) {
129-
PacketUtils.sendToServer(new PacketEditFilter<>(self.tile.getBlockPos(), self.origFilter, null));
126+
if (origFilter != null) {
127+
PacketUtils.sendToServer(new PacketEditFilter<>(this.tile.getBlockPos(), origFilter, null));
130128
}
131-
return self.close(element, mouseX, mouseY);
129+
return close(element, mouseX, mouseY);
132130
}));
133131
addChild(new TranslationButton(gui(), getLeftButtonX() + 62, screenBottom + 2, 60, 20, MekanismLang.BUTTON_SAVE, (element, mouseX, mouseY) -> {
134-
((GuiFilter<?, ?>) element).validateAndSave();
132+
validateAndSave();
135133
return true;
136134
}));
137135
GuiSlot slot = addChild(new GuiSlot(SlotType.NORMAL, gui(), relativeX + 7, relativeY + getSlotOffset()).setRenderHover(true).setGhostHandler(getGhostHandler()));

0 commit comments

Comments
 (0)