From a5dc53ba5f2618515b76dec62bb8b34275c0f445 Mon Sep 17 00:00:00 2001 From: attackeight <71084901+Attack8@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:14:56 -0400 Subject: [PATCH] Goggle Tooltip code cleanup and ModernUI compat (#6477) * Goggle Tooltip code cleanup and ModernUI compat fixes Creators-of-Create#6404 * Calculate indents based on font thanks @Tidy-Bear * exactPositioning workaround --------- Co-authored-by: zelophed --- build.gradle | 1 + .../java/com/simibubi/create/compat/Mods.java | 3 +- .../IDisplayAssemblyExceptions.java | 8 ++-- .../elevator/ElevatorContactEditPacket.java | 4 +- .../steamWhistle/WhistleBlockEntity.java | 3 +- .../goggles/GoggleOverlayRenderer.java | 47 ++++++++++++++++--- .../content/fluids/tank/BoilerData.java | 17 ++----- .../kinetics/gauge/GaugeBlockEntity.java | 2 +- .../tunnel/BrassTunnelBlockEntity.java | 17 ++----- .../analogLever/AnalogLeverBlockEntity.java | 2 +- .../create/foundation/item/TooltipHelper.java | 11 ++--- .../mixin/accessor/MouseHandlerAccessor.java | 16 +++++++ .../foundation/utility/LangBuilder.java | 34 ++++++++++---- src/main/resources/create.mixins.json | 1 + 14 files changed, 105 insertions(+), 61 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/accessor/MouseHandlerAccessor.java diff --git a/build.gradle b/build.gradle index c96b7f2ca..ca4685191 100644 --- a/build.gradle +++ b/build.gradle @@ -207,6 +207,7 @@ dependencies { // runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge") //runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924") //runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212") + // implementation fg.deobf("curse.maven:modern-ui-352491:5229350") // runtimeOnly fg.deobf("curse.maven:sophisticated-storage-619320:5194748") // runtimeOnly fg.deobf("curse.maven:sophisticated-core-618298:5296312") // runtimeOnly fg.deobf("curse.maven:functional-storage-556861:5271589") diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index 710df10b2..105256b58 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -25,7 +25,8 @@ public enum Mods { SOPHISTICATEDSTORAGE, STORAGEDRAWERS, TCONSTRUCT, - XLPACKETS; + XLPACKETS, + MODERNUI; private final String id; diff --git a/src/main/java/com/simibubi/create/content/contraptions/IDisplayAssemblyExceptions.java b/src/main/java/com/simibubi/create/content/contraptions/IDisplayAssemblyExceptions.java index c99054f41..983f67c37 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/IDisplayAssemblyExceptions.java +++ b/src/main/java/com/simibubi/create/content/contraptions/IDisplayAssemblyExceptions.java @@ -22,15 +22,13 @@ public interface IDisplayAssemblyExceptions { if (!tooltip.isEmpty()) tooltip.add(Components.immutableEmpty()); - tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy() - .append(Lang.translateDirect("gui.assembly.exception") - .withStyle(ChatFormatting.GOLD))); + Lang.translate("gui.assembly.exception").style(ChatFormatting.GOLD) + .forGoggles(tooltip); String text = e.component.getString(); Arrays.stream(text.split("\n")) .forEach(l -> TooltipHelper.cutStringTextComponent(l, Palette.GRAY_AND_WHITE) - .forEach(c -> tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy() - .append(c)))); + .forEach(c -> Lang.text(c.getString()).forGoggles(tooltip))); return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorContactEditPacket.java b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorContactEditPacket.java index 81d331d54..2a8a4487d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorContactEditPacket.java +++ b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorContactEditPacket.java @@ -27,14 +27,14 @@ public class ElevatorContactEditPacket extends BlockEntityConfigurationPacket tooltip, boolean isPlayerSneaking) { - tooltip.add(componentSpacing.plainCopy().append(Lang.translateDirect("gui.gauge.info_header"))); + Lang.translate("gui.gauge.info_header").forGoggles(tooltip); return true; } diff --git a/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelBlockEntity.java index b2f248fea..3fe40f41d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelBlockEntity.java @@ -784,20 +784,13 @@ public class BrassTunnelBlockEntity extends BeltTunnelBlockEntity implements IHa if (allStacks.isEmpty()) return false; - tooltip.add(componentSpacing.plainCopy() - .append(Lang.translateDirect("tooltip.brass_tunnel.contains")) - .withStyle(ChatFormatting.WHITE)); + Lang.translate("tooltip.brass_tunnel.contains").style(ChatFormatting.WHITE).forGoggles(tooltip); for (ItemStack item : allStacks) { - tooltip.add(componentSpacing.plainCopy() - .append(Lang.translateDirect("tooltip.brass_tunnel.contains_entry", - Components.translatable(item.getDescriptionId()) - .getString(), - item.getCount())) - .withStyle(ChatFormatting.GRAY)); + Lang.translate("tooltip.brass_tunnel.contains_entry", + Components.translatable(item.getDescriptionId()).getString(), item.getCount()) + .style(ChatFormatting.GRAY).forGoggles(tooltip); } - tooltip.add(componentSpacing.plainCopy() - .append(Lang.translateDirect("tooltip.brass_tunnel.retrieve")) - .withStyle(ChatFormatting.DARK_GRAY)); + Lang.translate("tooltip.brass_tunnel.retrieve").style(ChatFormatting.DARK_GRAY).forGoggles(tooltip); return true; } diff --git a/src/main/java/com/simibubi/create/content/redstone/analogLever/AnalogLeverBlockEntity.java b/src/main/java/com/simibubi/create/content/redstone/analogLever/AnalogLeverBlockEntity.java index 3902009ff..53b0c6b83 100644 --- a/src/main/java/com/simibubi/create/content/redstone/analogLever/AnalogLeverBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/redstone/analogLever/AnalogLeverBlockEntity.java @@ -79,7 +79,7 @@ public class AnalogLeverBlockEntity extends SmartBlockEntity implements IHaveGog @Override public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - tooltip.add(componentSpacing.plainCopy().append(Lang.translateDirect("tooltip.analogStrength", this.state))); + Lang.translate("tooltip.analogStrength", this.state).forGoggles(tooltip); return true; } diff --git a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java index af1adfc9d..e5da669a1 100644 --- a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java @@ -6,7 +6,6 @@ import java.util.LinkedList; import java.util.List; import com.google.common.base.Strings; -import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Lang; @@ -30,15 +29,11 @@ public class TooltipHelper { } public static void addHint(List tooltip, String hintKey, Object... messageParams) { - Component spacing = IHaveGoggleInformation.componentSpacing; - tooltip.add(spacing.plainCopy() - .append(Lang.translateDirect(hintKey + ".title")) - .withStyle(ChatFormatting.GOLD)); + Lang.translate(hintKey + ".title").style(ChatFormatting.GOLD).forGoggles(tooltip); Component hint = Lang.translateDirect(hintKey); List cutComponent = cutTextComponent(hint, Palette.GRAY_AND_WHITE); for (Component component : cutComponent) - tooltip.add(spacing.plainCopy() - .append(component)); + Lang.text(component.getString()).forGoggles(tooltip); } public static String makeProgressBar(int length, int filledLength) { @@ -54,7 +49,7 @@ public class TooltipHelper { public static Style styleFromColor(ChatFormatting color) { return Style.EMPTY.applyFormat(color); } - + public static Style styleFromColor(int hex) { return Style.EMPTY.withColor(hex); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/MouseHandlerAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/MouseHandlerAccessor.java new file mode 100644 index 000000000..d837c06f0 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/MouseHandlerAccessor.java @@ -0,0 +1,16 @@ +package com.simibubi.create.foundation.mixin.accessor; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.MouseHandler; + +@Mixin(MouseHandler.class) +public interface MouseHandlerAccessor { + + @Accessor("xpos") + void create$setXPos(double xPos); + + @Accessor("ypos") + void create$setYPos(double yPos); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/LangBuilder.java b/src/main/java/com/simibubi/create/foundation/utility/LangBuilder.java index 564b6131f..161f52dd4 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/LangBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/utility/LangBuilder.java @@ -2,10 +2,15 @@ package com.simibubi.create.foundation.utility; import java.util.List; +import com.simibubi.create.compat.Mods; + import joptsimple.internal.Strings; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; public class LangBuilder { @@ -29,7 +34,7 @@ public class LangBuilder { * Appends a localised component
* To add an independently formatted localised component, use add() and a nested * builder - * + * * @param langKey * @param args * @return @@ -40,7 +45,7 @@ public class LangBuilder { /** * Appends a text component - * + * * @param literalText * @return */ @@ -50,7 +55,7 @@ public class LangBuilder { /** * Appends a colored text component - * + * * @param format * @param literalText * @return @@ -61,7 +66,7 @@ public class LangBuilder { /** * Appends a colored text component - * + * * @param color * @param literalText * @return @@ -72,7 +77,7 @@ public class LangBuilder { /** * Appends the contents of another builder - * + * * @param otherBuilder * @return */ @@ -82,7 +87,7 @@ public class LangBuilder { /** * Appends a component - * + * * @param customComponent * @return */ @@ -95,7 +100,7 @@ public class LangBuilder { /** * Applies the format to all added components - * + * * @param format * @return */ @@ -107,7 +112,7 @@ public class LangBuilder { /** * Applies the color to all added components - * + * * @param color * @return */ @@ -150,11 +155,20 @@ public class LangBuilder { public void forGoggles(List tooltip, int indents) { tooltip.add(Lang.builder() - .text(Strings.repeat(' ', 4 + indents)) + .text(Strings.repeat(' ', getIndents(Minecraft.getInstance().font, 4 + indents))) .add(this) .component()); } + public static final float DEFAULT_SPACE_WIDTH = 4.0F; // space width in vanilla's default font + static int getIndents(Font font, int defaultIndents) { + int spaceWidth = font.width(" "); + if (DEFAULT_SPACE_WIDTH == spaceWidth) { + return defaultIndents; + } + return Mth.ceil(DEFAULT_SPACE_WIDTH * defaultIndents / spaceWidth); + } + // private void assertComponent() { @@ -162,4 +176,4 @@ public class LangBuilder { throw new IllegalStateException("No components were added to builder"); } -} \ No newline at end of file +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 63c44c55f..a434994ce 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -29,6 +29,7 @@ "accessor.AgeableListModelAccessor", "accessor.GameRendererAccessor", "accessor.HumanoidArmorLayerAccessor", + "accessor.MouseHandlerAccessor", "accessor.ParticleEngineAccessor", "client.BlockDestructionProgressMixin", "client.CameraMixin",