From fdf9fdcd78243e800dc91850337dced922e9001e Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sun, 4 Oct 2020 10:35:58 +0200 Subject: [PATCH] Fixed some text component stuff i messed up earlier --- .../contraptions/base/KineticTileEntity.java | 6 ++--- .../goggles/GoggleConfigScreen.java | 25 ++++++++++--------- .../goggles/GoggleOverlayRenderer.java | 3 ++- .../goggles/IHaveGoggleInformation.java | 1 + .../relays/gauge/GaugeTileEntity.java | 2 +- .../relays/gauge/SpeedGaugeTileEntity.java | 6 ++--- .../relays/gauge/StressGaugeTileEntity.java | 20 +++++++-------- .../block/chute/ChuteTileEntity.java | 7 +++--- .../block/redstone/AnalogLeverTileEntity.java | 2 +- .../client/SchematicPromptScreen.java | 2 -- .../gui/widgets/AbstractSimiWidget.java | 3 ++- .../tileEntity/behaviour/ValueBox.java | 4 +-- 12 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 762fc5e20..d38d8b860 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -377,7 +377,7 @@ public abstract class KineticTileEntity extends SmartTileEntity boolean notFastEnough = !isSpeedRequirementFulfilled() && getSpeed() != 0; if (overStressed && AllConfigs.CLIENT.enableOverstressedTooltip.get()) { - tooltip.add(ITextComponent.of(spacing + GOLD + Lang.translate("gui.stressometer.overstressed"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.overstressed").formatted(GOLD))); ITextComponent hint = Lang.translate("gui.contraptions.network_overstressed", I18n.format(getBlockState().getBlock() .getTranslationKey())); List cutString = TooltipHelper.cutString(new StringTextComponent(spacing).append(hint), GRAY, TextFormatting.WHITE); @@ -405,8 +405,8 @@ public abstract class KineticTileEntity extends SmartTileEntity float stressAtBase = calculateStressApplied(); if (calculateStressApplied() != 0 && StressImpact.isEnabled()) { - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.goggles.kinetic_stats"))); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("tooltip.stressImpact"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.goggles.kinetic_stats"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("tooltip.stressImpact").formatted(TextFormatting.GRAY))); float stressTotal = stressAtBase * Math.abs(getSpeed()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java index de94addc8..e98f24b03 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java @@ -13,6 +13,7 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; public class GoggleConfigScreen extends AbstractSimiScreen { @@ -22,19 +23,19 @@ public class GoggleConfigScreen extends AbstractSimiScreen { private final List tooltip; public GoggleConfigScreen() { - String spacing = " "; + ITextComponent spacing = ITextComponent.of(" "); tooltip = new ArrayList<>(); - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.config.overlay1"))); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay2"))); - tooltip.add(ITextComponent.of("")); - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.config.overlay3"))); - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.config.overlay4"))); - tooltip.add(ITextComponent.of("")); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay5"))); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay6"))); - tooltip.add(ITextComponent.of("")); - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.config.overlay7"))); - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.config.overlay8"))); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay1"))); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay2").formatted(TextFormatting.GRAY))); + tooltip.add(StringTextComponent.EMPTY); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay3"))); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay4"))); + tooltip.add(StringTextComponent.EMPTY); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay5").formatted(TextFormatting.GRAY))); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay6").formatted(TextFormatting.GRAY))); + tooltip.add(StringTextComponent.EMPTY); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay7"))); + tooltip.add(spacing.copy().append(Lang.translate("gui.config.overlay8"))); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java index b9a7056a2..2db016878 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java @@ -18,6 +18,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; @@ -62,7 +63,7 @@ public class GoggleOverlayRenderer { if (hoveringInformation) { boolean goggleAddedInformation = !tooltip.isEmpty(); if (goggleAddedInformation) - tooltip.add(ITextComponent.of("")); + tooltip.add(StringTextComponent.EMPTY); IHaveHoveringInformation hte = (IHaveHoveringInformation) te; if (!hte.addToTooltip(tooltip, mc.player.isSneaking())) hoveringInformation = false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java index a97ee29dd..25dd3e328 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java @@ -12,6 +12,7 @@ public interface IHaveGoggleInformation { DecimalFormat decimalFormat = new DecimalFormat("#.##"); String spacing = " "; + ITextComponent componentSpacing = ITextComponent.of(spacing); /** * this method will be called when looking at a TileEntity that implemented this interface diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java index 932b18b81..294e9efb2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java @@ -47,7 +47,7 @@ public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInf @Override public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - tooltip.add(ITextComponent.of(spacing + Lang.translate("gui.gauge.info_header"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.gauge.info_header"))); return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/SpeedGaugeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/SpeedGaugeTileEntity.java index e0bc95006..47c61aaf9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/SpeedGaugeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/SpeedGaugeTileEntity.java @@ -50,10 +50,10 @@ public class SpeedGaugeTileEntity extends GaugeTileEntity{ public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { super.addToGoggleTooltip(tooltip, isPlayerSneaking); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.speedometer.title"))); - tooltip.add(ITextComponent.of(spacing + SpeedLevel.getFormattedSpeedText(speed, overStressed))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.speedometer.title").formatted(TextFormatting.GRAY))); + tooltip.add(componentSpacing.copy().append(SpeedLevel.getFormattedSpeedText(speed, overStressed))); if (overStressed) - tooltip.add(ITextComponent.of(spacing + TextFormatting.DARK_RED + Lang.translate("gui.stressometer.overstressed"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.overstressed").formatted(TextFormatting.DARK_RED))); return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java index eb6a925c3..a3e723ba4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/StressGaugeTileEntity.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; public class StressGaugeTileEntity extends GaugeTileEntity { @@ -66,27 +67,26 @@ public class StressGaugeTileEntity extends GaugeTileEntity { double capacity = getNetworkCapacity(); double stressFraction = getNetworkStress() / (capacity == 0 ? 1 : capacity); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.stressometer.title"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.title").formatted(TextFormatting.GRAY))); if (getTheoreticalSpeed() == 0) tooltip.add(ITextComponent.of(TextFormatting.DARK_GRAY + ItemDescription.makeProgressBar(3, -1) + Lang.translate("gui.stressometer.no_rotation"))); else { - tooltip.add(ITextComponent.of(spacing + StressImpact.getFormattedStressText(stressFraction))); + tooltip.add(componentSpacing.copy().append(StressImpact.getFormattedStressText(stressFraction))); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GRAY + Lang.translate("gui.stressometer.capacity"))); + tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.capacity").formatted(TextFormatting.GRAY))); double remainingCapacity = capacity - getNetworkStress(); double remainingCapacityAtBase = remainingCapacity / Math.abs(getTheoreticalSpeed()); - String capacityString = spacing + StressImpact.of(stressFraction).getRelativeColor() + "%s" - + Lang.translate("generic.unit.stress") + " " + TextFormatting.DARK_GRAY + "%s"; - - tooltip.add(ITextComponent.of(String.format(capacityString, IHaveGoggleInformation.format(remainingCapacityAtBase), - Lang.translate("gui.goggles.base_value")))); - tooltip.add(ITextComponent.of(String.format(capacityString, IHaveGoggleInformation.format(remainingCapacity), - Lang.translate("gui.goggles.at_current_speed")))); + tooltip.add(componentSpacing.copy().append(new StringTextComponent(IHaveGoggleInformation.format(remainingCapacityAtBase)) + .append(Lang.translate("generic.unit.stress")).append(" ").formatted(StressImpact.of(stressFraction).getRelativeColor())) + .append(Lang.translate("gui.goggles.base_value").formatted(TextFormatting.DARK_GRAY))); + tooltip.add(componentSpacing.copy().append(new StringTextComponent(IHaveGoggleInformation.format(remainingCapacity)) + .append(Lang.translate("generic.unit.stress")).append(" ").formatted(StressImpact.of(stressFraction).getRelativeColor())) + .append(Lang.translate("gui.goggles.at_current_speed").formatted(TextFormatting.DARK_GRAY))); } return true; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java index b14ac9b8a..dd990e97c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java @@ -45,6 +45,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; @@ -632,9 +633,9 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor @Override public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - tooltip.add(ITextComponent.of(spacing + TextFormatting.GOLD + "Pull: " + TextFormatting.WHITE + pull)); - tooltip.add(ITextComponent.of(spacing + TextFormatting.GOLD + "Push: " + TextFormatting.WHITE + push)); - tooltip.add(ITextComponent.of(TextFormatting.YELLOW + "-> Item Motion: " + TextFormatting.WHITE + getItemMotion())); + tooltip.add(componentSpacing.copy().append(new StringTextComponent("Pull: ").formatted(TextFormatting.GOLD).append(new StringTextComponent(String.valueOf(pull)).formatted(TextFormatting.WHITE)))); + tooltip.add(componentSpacing.copy().append(new StringTextComponent("Push: ").formatted(TextFormatting.GOLD).append(new StringTextComponent(String.valueOf(push)).formatted(TextFormatting.WHITE)))); + tooltip.add(new StringTextComponent("-> Item Motion: ").formatted(TextFormatting.YELLOW).append(new StringTextComponent(String.valueOf(getItemMotion())).formatted(TextFormatting.WHITE))); return true; } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java index 4138f0b0a..0a0df2bdc 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java @@ -70,7 +70,7 @@ public class AnalogLeverTileEntity extends SmartTileEntity implements IHaveGoggl @Override public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - tooltip.add(ITextComponent.of(spacing).copy().append(Lang.translate("tooltip.analogStrength", this.state))); + tooltip.add(componentSpacing.copy().append(Lang.translate("tooltip.analogStrength", this.state))); return true; } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java index 50c739b99..355ad200e 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.schematics.client; -import static com.simibubi.create.foundation.gui.AllGuiTextures.ADJUSTABLE_CRATE; - import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.matrix.MatrixStack; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java index 149c25fb8..2c84c9ccf 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java @@ -7,13 +7,14 @@ import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.gui.widget.Widget; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; public abstract class AbstractSimiWidget extends Widget { protected List toolTip; public AbstractSimiWidget(int xIn, int yIn, int widthIn, int heightIn) { - super(xIn, yIn, widthIn, heightIn, ITextComponent.of("")); + super(xIn, yIn, widthIn, heightIn, StringTextComponent.EMPTY); toolTip = new LinkedList<>(); } diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java index 1bfd4cfcd..23306468d 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java @@ -23,8 +23,8 @@ import net.minecraft.util.text.StringTextComponent; public class ValueBox extends ChasingAABBOutline { - protected ITextComponent label = ITextComponent.of("Value Box"); - protected ITextComponent sublabel = ITextComponent.of(""); + protected ITextComponent label; + protected ITextComponent sublabel = StringTextComponent.EMPTY; protected ITextComponent scrollTooltip = StringTextComponent.EMPTY; protected Vector3d labelOffset = Vector3d.ZERO;