From 27be10dfbf02bb1037016eb0af9821d7475f2115 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:36:27 +0800 Subject: [PATCH 1/3] try to improve robustness of channels gui Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../structurelib/gui/GuiScreenConfigureChannels.java | 3 +-- .../structurelib/item/ItemConstructableTrigger.java | 4 +++- .../structurelib/structure/StructureUtility.java | 12 +++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java index 10dcba09..da7dfa6c 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java +++ b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java @@ -276,7 +276,7 @@ private void updateButtons() { getButtonList().get(ADD_BTN).displayString = existing ? I18n.format("item.structurelib.constructableTrigger.gui.set") : I18n.format("item.structurelib.constructableTrigger.gui.add"); - getButtonList().get(ADD_BTN).enabled = !StringUtils.isBlank(value.getText()); + getButtonList().get(ADD_BTN).enabled = !StringUtils.isBlank(value.getText()) && Integer.parseInt(value.getText()) > 0; getButtonList().get(UNSET_BTN).enabled = existing && !StringUtils.isBlank(value.getText()); if (ChannelDataAccessor.hasSubChannel(trigger, SHOW_ERROR_CHANNEL)) { @@ -293,7 +293,6 @@ private void updateButtons() { getButtonList().get(GT_NO_HATCH_BTN).displayString = "No Hatch"; } } - } private int getValue() { diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java index 6aedef93..21996079 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java @@ -7,6 +7,8 @@ import java.util.List; +import com.gtnewhorizon.structurelib.gui.GuiScreenConfigureChannels; +import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -32,7 +34,7 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla if (player.isSneaking()) { StructureLib.instance().proxy().displayConfigGUI("registries"); } else { - player.openGui(StructureLib.instance(), 0, world, player.inventory.currentItem, 0, 0); + FMLCommonHandler.instance().showGuiScreen(new GuiScreenConfigureChannels(stack)); } } return super.onItemRightClick(stack, world, player); diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java index f44e3095..cda7a1fe 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java @@ -1,5 +1,7 @@ package com.gtnewhorizon.structurelib.structure; +import static com.gtnewhorizon.structurelib.StructureLib.LOGGER; +import static com.gtnewhorizon.structurelib.StructureLib.PANIC_MODE; import static java.lang.Integer.MIN_VALUE; import java.util.Arrays; @@ -586,7 +588,7 @@ public static IStructureElementCheckOnly ofBlocksTiered(ITierConver TIER current = getter.apply(t); if (Objects.equals(notSet, current)) { if (Objects.equals(notSet, tier)) { - if (StructureLib.PANIC_MODE) { + if (PANIC_MODE) { throw new AssertionError("tierExtractor should never return notSet: " + notSet); } else { StructureLib.LOGGER.error("#########################################"); @@ -1348,6 +1350,14 @@ public static IStructureElement ofBlock(Block block, int meta, Block defa if (block == null || defaultBlock == null) { throw new IllegalArgumentException(); } + if (block == Blocks.air) { + if (PANIC_MODE) { + throw new IllegalArgumentException("ofBlock() does not accept air. use isAir() instead"); + } else { + LOGGER.warn("ofBlock() does not accept air. use isAir() instead"); + return isAir(); + } + } if (block instanceof ICustomBlockSetting) { return new IStructureElement() { From 361d2932f6b701dda14a449e5e2439e93d08f0a4 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:46:29 +0800 Subject: [PATCH 2/3] add mouse wheel scrolling for channel data Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gui/GuiScreenConfigureChannels.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java index da7dfa6c..ac4782e9 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java +++ b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java @@ -222,10 +222,27 @@ private List getButtonList() { return buttonList; } + private boolean isMouseOverValue() { + int mx = Mouse.getEventX() * this.width / this.mc.displayWidth; + int my = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + return mx >= value.xPosition && mx < value.xPosition + value.width && my >= value.yPosition && my < value.yPosition + value.height; + + } + @Override public void handleMouseInput() { int delta = Mouse.getEventDWheel(); - if (delta != 0) list.handleDWheel(delta); + if (delta != 0) { + if (isMouseOverValue()) { + if (delta > 0) { + value.setText(String.valueOf(getValue() + 1)); + } else { + value.setText(String.valueOf(Math.max(getValue() - 1, 1))); + } + } else { + list.handleDWheel(delta); + } + } super.handleMouseInput(); } From 2bde67bc203458ffc702a0d88d007bfd16981f33 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 15 Dec 2024 02:48:06 +0800 Subject: [PATCH 3/3] localize hologram trigger item GUI Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gui/GuiScreenConfigureChannels.java | 24 +++++++++++-------- .../item/ItemConstructableTrigger.java | 5 ++-- .../assets/structurelib/lang/en_US.lang | 4 ++++ .../assets/structurelib/lang/zh_CN.lang | 4 ++++ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java index ac4782e9..ea6d69ef 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java +++ b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScreenConfigureChannels.java @@ -25,6 +25,8 @@ public class GuiScreenConfigureChannels extends GuiScreen implements IGuiScreen { + private static final String I18N_PREFIX = "item.structurelib.constructableTrigger.gui."; + private static final int ADD_BTN = 0; private static final int UNSET_BTN = 1; private static final int WIPE_BTN = 2; @@ -223,9 +225,11 @@ private List getButtonList() { } private boolean isMouseOverValue() { - int mx = Mouse.getEventX() * this.width / this.mc.displayWidth; + int mx = Mouse.getEventX() * this.width / this.mc.displayWidth; int my = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - return mx >= value.xPosition && mx < value.xPosition + value.width && my >= value.yPosition && my < value.yPosition + value.height; + return mx >= value.xPosition && mx < value.xPosition + value.width + && my >= value.yPosition + && my < value.yPosition + value.height; } @@ -290,24 +294,24 @@ private void updateButtons() { // STACKOVERFLOW! String keyText = key.getText(); boolean existing = !StringUtils.isEmpty(keyText) && ChannelDataAccessor.hasSubChannel(trigger, keyText); - getButtonList().get(ADD_BTN).displayString = existing - ? I18n.format("item.structurelib.constructableTrigger.gui.set") - : I18n.format("item.structurelib.constructableTrigger.gui.add"); - getButtonList().get(ADD_BTN).enabled = !StringUtils.isBlank(value.getText()) && Integer.parseInt(value.getText()) > 0; + getButtonList().get(ADD_BTN).displayString = existing ? I18n.format(I18N_PREFIX + "set") + : I18n.format(I18N_PREFIX + "add"); + getButtonList().get(ADD_BTN).enabled = !StringUtils.isBlank(value.getText()) + && Integer.parseInt(value.getText()) > 0; getButtonList().get(UNSET_BTN).enabled = existing && !StringUtils.isBlank(value.getText()); if (ChannelDataAccessor.hasSubChannel(trigger, SHOW_ERROR_CHANNEL)) { - getButtonList().get(SHOW_ERROR_BTN).displayString = "Hide Errors"; + getButtonList().get(SHOW_ERROR_BTN).displayString = I18n.format(I18N_PREFIX + "error.hide"); } else { - getButtonList().get(SHOW_ERROR_BTN).displayString = "Show Errors"; + getButtonList().get(SHOW_ERROR_BTN).displayString = I18n.format(I18N_PREFIX + "error.show"); } // this button only exists if GT is loaded. if (StructureLib.isGTLoaded) { if (ChannelDataAccessor.hasSubChannel(trigger, GT_NO_HATCH_CHANNEL)) { - getButtonList().get(GT_NO_HATCH_BTN).displayString = "Hatches"; + getButtonList().get(GT_NO_HATCH_BTN).displayString = I18n.format(I18N_PREFIX + "gt_no_hatch.disable"); } else { - getButtonList().get(GT_NO_HATCH_BTN).displayString = "No Hatch"; + getButtonList().get(GT_NO_HATCH_BTN).displayString = I18n.format(I18N_PREFIX + "gt_no_hatch.enable"); } } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java index 21996079..118c954f 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemConstructableTrigger.java @@ -7,8 +7,6 @@ import java.util.List; -import com.gtnewhorizon.structurelib.gui.GuiScreenConfigureChannels; -import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -19,6 +17,9 @@ import com.gtnewhorizon.structurelib.StructureLib; import com.gtnewhorizon.structurelib.alignment.constructable.ChannelDataAccessor; import com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility; +import com.gtnewhorizon.structurelib.gui.GuiScreenConfigureChannels; + +import cpw.mods.fml.common.FMLCommonHandler; public class ItemConstructableTrigger extends Item { diff --git a/src/main/resources/assets/structurelib/lang/en_US.lang b/src/main/resources/assets/structurelib/lang/en_US.lang index 6375d6e8..37c06cf4 100644 --- a/src/main/resources/assets/structurelib/lang/en_US.lang +++ b/src/main/resources/assets/structurelib/lang/en_US.lang @@ -35,6 +35,10 @@ item.structurelib.constructableTrigger.gui.add=Add item.structurelib.constructableTrigger.gui.set=Set item.structurelib.constructableTrigger.gui.unset=Unset item.structurelib.constructableTrigger.gui.wipe=§4Wipe +item.structurelib.constructableTrigger.gui.error.show=Show Errors +item.structurelib.constructableTrigger.gui.error.hide=Hide Errors +item.structurelib.constructableTrigger.gui.gt_no_hatch.enable=No Hatch +item.structurelib.constructableTrigger.gui.gt_no_hatch.disable=Hatches structurelib.autoplace.built_stat=Built %s blocks structurelib.autoplace.complete=§aThis multiblock has completed! diff --git a/src/main/resources/assets/structurelib/lang/zh_CN.lang b/src/main/resources/assets/structurelib/lang/zh_CN.lang index be461bd1..3d7ec2ae 100644 --- a/src/main/resources/assets/structurelib/lang/zh_CN.lang +++ b/src/main/resources/assets/structurelib/lang/zh_CN.lang @@ -35,6 +35,10 @@ item.structurelib.constructableTrigger.gui.add=添加 item.structurelib.constructableTrigger.gui.set=替换 item.structurelib.constructableTrigger.gui.unset=删除 item.structurelib.constructableTrigger.gui.wipe=§4全部清空 +item.structurelib.constructableTrigger.gui.error.show=显示结构错误 +item.structurelib.constructableTrigger.gui.error.hide=隐藏结构错误 +item.structurelib.constructableTrigger.gui.gt_no_hatch.enable=跳过舱室 +item.structurelib.constructableTrigger.gui.gt_no_hatch.disable=放置舱室 structurelib.autoplace.built_stat=已放置 %s 个方块 structurelib.autoplace.complete=§a这个多方块结构已经完成自动搭建!