Fix even more text components, now in tooltips

This commit is contained in:
grimmauld 2020-10-06 15:54:16 +02:00
parent 0d972e144f
commit e8c458f2ad
11 changed files with 192 additions and 161 deletions

View File

@ -132,7 +132,7 @@ fc652317e03b57c76e23a805da16a28d15254029 assets/create/blockstates/fancy_scoria_
fc9ac0a7e7191b93516719455a17177fa6524ecc assets/create/blockstates/fancy_weathered_limestone_bricks_slab.json fc9ac0a7e7191b93516719455a17177fa6524ecc assets/create/blockstates/fancy_weathered_limestone_bricks_slab.json
b2a7c321b1795f20e7433f81a55ce4683de081b8 assets/create/blockstates/fancy_weathered_limestone_bricks_stairs.json b2a7c321b1795f20e7433f81a55ce4683de081b8 assets/create/blockstates/fancy_weathered_limestone_bricks_stairs.json
8e532856c3c2b4e4e59c65a2a81a694e35d14658 assets/create/blockstates/fancy_weathered_limestone_bricks_wall.json 8e532856c3c2b4e4e59c65a2a81a694e35d14658 assets/create/blockstates/fancy_weathered_limestone_bricks_wall.json
5ba9fc9e7b29c76040329367cfb45affdd473404 assets/create/blockstates/fluid_pipe.json 3d97226b5e8d8f70ed08e45e78db1faf78d5e28b assets/create/blockstates/fluid_pipe.json
f0eaab18e16c4f3f65ebf3b55b08f0dc445720fe assets/create/blockstates/fluid_tank.json f0eaab18e16c4f3f65ebf3b55b08f0dc445720fe assets/create/blockstates/fluid_tank.json
5408d92ab02af86539ac42971d4033545970bb3a assets/create/blockstates/fluid_valve.json 5408d92ab02af86539ac42971d4033545970bb3a assets/create/blockstates/fluid_valve.json
e9da1794b6ece7f9aa8bcb43d42c23a55446133b assets/create/blockstates/flywheel.json e9da1794b6ece7f9aa8bcb43d42c23a55446133b assets/create/blockstates/flywheel.json
@ -312,7 +312,7 @@ e8b0a401c10d1ba67ed71ba31bd5f9bc28571b65 assets/create/blockstates/powered_toggl
469e430d96cb0a5e1aaf6b7cc5d401d488c9e600 assets/create/blockstates/pulse_repeater.json 469e430d96cb0a5e1aaf6b7cc5d401d488c9e600 assets/create/blockstates/pulse_repeater.json
92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json 92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json
61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.json 61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.json
5d1b30c2bab556f57c78e7780fd445b08f541a50 assets/create/blockstates/radial_chassis.json 4439fc83a8c7370ab44b211a3fd48abde20a4728 assets/create/blockstates/radial_chassis.json
da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json
722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.json 722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.json
8929677f2cc5354aa19ef182af69f9f0b41eb242 assets/create/blockstates/redstone_contact.json 8929677f2cc5354aa19ef182af69f9f0b41eb242 assets/create/blockstates/redstone_contact.json

View File

@ -60,10 +60,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"down": "false", "down": "false",
"south": "false", "north": "true",
"north": "true" "up": "true",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lu_x" "model": "create:block/fluid_pipe/lu_x"
@ -71,10 +71,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"down": "false", "down": "false",
"south": "true", "north": "false",
"north": "false" "up": "true",
"south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ru_x" "model": "create:block/fluid_pipe/ru_x"
@ -82,10 +82,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "true", "down": "true",
"south": "false", "north": "true",
"north": "true" "up": "false",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ld_x" "model": "create:block/fluid_pipe/ld_x"
@ -93,10 +93,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "true", "down": "true",
"south": "true", "north": "false",
"north": "false" "up": "false",
"south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/rd_x" "model": "create:block/fluid_pipe/rd_x"
@ -104,21 +104,21 @@
}, },
{ {
"when": { "when": {
"up": "true",
"down": "true", "down": "true",
"south": "false", "north": "false",
"north": "false"
},
"apply": {
"model": "create:block/fluid_pipe/ud_x"
}
},
{
"when": {
"up": "true", "up": "true",
"down": "false", "south": "false"
"south": "false", },
"north": "false" "apply": {
"model": "create:block/fluid_pipe/ud_x"
}
},
{
"when": {
"down": "false",
"north": "false",
"up": "true",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_x" "model": "create:block/fluid_pipe/ud_x"
@ -126,10 +126,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "true", "down": "true",
"south": "false", "north": "false",
"north": "false" "up": "false",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_x" "model": "create:block/fluid_pipe/ud_x"
@ -137,10 +137,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "false", "down": "false",
"south": "true", "north": "true",
"north": "true" "up": "false",
"south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_x" "model": "create:block/fluid_pipe/lr_x"
@ -148,10 +148,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "false", "down": "false",
"south": "false", "north": "true",
"north": "true" "up": "false",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_x" "model": "create:block/fluid_pipe/lr_x"
@ -159,10 +159,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "false", "down": "false",
"south": "true", "north": "false",
"north": "false" "up": "false",
"south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_x" "model": "create:block/fluid_pipe/lr_x"
@ -170,10 +170,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"down": "false", "down": "false",
"south": "false", "north": "false",
"north": "false" "up": "false",
"south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/none_x" "model": "create:block/fluid_pipe/none_x"
@ -182,9 +182,9 @@
{ {
"when": { "when": {
"west": "true", "west": "true",
"south": "true", "east": "false",
"north": "false", "north": "false",
"east": "false" "south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lu_y" "model": "create:block/fluid_pipe/lu_y"
@ -193,9 +193,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "true", "east": "true",
"north": "false", "north": "false",
"east": "true" "south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ru_y" "model": "create:block/fluid_pipe/ru_y"
@ -204,9 +204,9 @@
{ {
"when": { "when": {
"west": "true", "west": "true",
"south": "false", "east": "false",
"north": "true", "north": "true",
"east": "false" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ld_y" "model": "create:block/fluid_pipe/ld_y"
@ -215,9 +215,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "false", "east": "true",
"north": "true", "north": "true",
"east": "true" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/rd_y" "model": "create:block/fluid_pipe/rd_y"
@ -226,9 +226,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "true", "east": "false",
"north": "true", "north": "true",
"east": "false" "south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_y" "model": "create:block/fluid_pipe/ud_y"
@ -237,9 +237,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "true", "east": "false",
"north": "false", "north": "false",
"east": "false" "south": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_y" "model": "create:block/fluid_pipe/ud_y"
@ -248,9 +248,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "false", "east": "false",
"north": "true", "north": "true",
"east": "false" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_y" "model": "create:block/fluid_pipe/ud_y"
@ -259,9 +259,9 @@
{ {
"when": { "when": {
"west": "true", "west": "true",
"south": "false", "east": "true",
"north": "false", "north": "false",
"east": "true" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_y" "model": "create:block/fluid_pipe/lr_y"
@ -270,9 +270,9 @@
{ {
"when": { "when": {
"west": "true", "west": "true",
"south": "false", "east": "false",
"north": "false", "north": "false",
"east": "false" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_y" "model": "create:block/fluid_pipe/lr_y"
@ -281,9 +281,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "false", "east": "true",
"north": "false", "north": "false",
"east": "true" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_y" "model": "create:block/fluid_pipe/lr_y"
@ -292,9 +292,9 @@
{ {
"when": { "when": {
"west": "false", "west": "false",
"south": "false", "east": "false",
"north": "false", "north": "false",
"east": "false" "south": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/none_y" "model": "create:block/fluid_pipe/none_y"
@ -302,10 +302,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"west": "false", "west": "false",
"down": "false", "down": "false",
"east": "true" "east": "true",
"up": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lu_z" "model": "create:block/fluid_pipe/lu_z"
@ -313,10 +313,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"west": "true", "west": "true",
"down": "false", "down": "false",
"east": "false" "east": "false",
"up": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ru_z" "model": "create:block/fluid_pipe/ru_z"
@ -324,10 +324,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "false", "west": "false",
"down": "true", "down": "true",
"east": "true" "east": "true",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ld_z" "model": "create:block/fluid_pipe/ld_z"
@ -335,10 +335,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "true", "west": "true",
"down": "true", "down": "true",
"east": "false" "east": "false",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/rd_z" "model": "create:block/fluid_pipe/rd_z"
@ -346,10 +346,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"west": "false", "west": "false",
"down": "true", "down": "true",
"east": "false" "east": "false",
"up": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_z" "model": "create:block/fluid_pipe/ud_z"
@ -357,10 +357,10 @@
}, },
{ {
"when": { "when": {
"up": "true",
"west": "false", "west": "false",
"down": "false", "down": "false",
"east": "false" "east": "false",
"up": "true"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_z" "model": "create:block/fluid_pipe/ud_z"
@ -368,10 +368,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "false", "west": "false",
"down": "true", "down": "true",
"east": "false" "east": "false",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/ud_z" "model": "create:block/fluid_pipe/ud_z"
@ -379,10 +379,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "true", "west": "true",
"down": "false", "down": "false",
"east": "true" "east": "true",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_z" "model": "create:block/fluid_pipe/lr_z"
@ -390,10 +390,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "false", "west": "false",
"down": "false", "down": "false",
"east": "true" "east": "true",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_z" "model": "create:block/fluid_pipe/lr_z"
@ -401,10 +401,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "true", "west": "true",
"down": "false", "down": "false",
"east": "false" "east": "false",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/lr_z" "model": "create:block/fluid_pipe/lr_z"
@ -412,10 +412,10 @@
}, },
{ {
"when": { "when": {
"up": "false",
"west": "false", "west": "false",
"down": "false", "down": "false",
"east": "false" "east": "false",
"up": "false"
}, },
"apply": { "apply": {
"model": "create:block/fluid_pipe/none_z" "model": "create:block/fluid_pipe/none_z"

View File

@ -207,8 +207,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "true", "axis": "x",
"axis": "x" "sticky_east": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x_sticky", "model": "create:block/radial_chassis_side_x_sticky",
@ -217,8 +217,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "true", "axis": "y",
"axis": "y" "sticky_east": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y_sticky", "model": "create:block/radial_chassis_side_y_sticky",
@ -227,8 +227,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "true", "axis": "z",
"axis": "z" "sticky_east": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_z_sticky" "model": "create:block/radial_chassis_side_z_sticky"
@ -236,8 +236,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "false", "axis": "x",
"axis": "x" "sticky_east": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x", "model": "create:block/radial_chassis_side_x",
@ -246,8 +246,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "false", "axis": "y",
"axis": "y" "sticky_east": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y", "model": "create:block/radial_chassis_side_y",
@ -256,8 +256,8 @@
}, },
{ {
"when": { "when": {
"sticky_east": "false", "axis": "z",
"axis": "z" "sticky_east": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_z" "model": "create:block/radial_chassis_side_z"

View File

@ -380,7 +380,7 @@ public abstract class KineticTileEntity extends SmartTileEntity
tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.overstressed").formatted(GOLD))); tooltip.add(componentSpacing.copy().append(Lang.translate("gui.stressometer.overstressed").formatted(GOLD)));
ITextComponent hint = Lang.translate("gui.contraptions.network_overstressed", I18n.format(getBlockState().getBlock() ITextComponent hint = Lang.translate("gui.contraptions.network_overstressed", I18n.format(getBlockState().getBlock()
.getTranslationKey())); .getTranslationKey()));
List<String> cutString = TooltipHelper.cutString(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE); List<ITextComponent> cutString = TooltipHelper.cutTextComponent(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE);
for (int i = 0; i < cutString.size(); i++) for (int i = 0; i < cutString.size(); i++)
tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i))); tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i)));
return true; return true;
@ -390,7 +390,7 @@ public abstract class KineticTileEntity extends SmartTileEntity
tooltip.add(componentSpacing.copy().append(Lang.translate("tooltip.speedRequirement").formatted(GOLD))); tooltip.add(componentSpacing.copy().append(Lang.translate("tooltip.speedRequirement").formatted(GOLD)));
ITextComponent hint = Lang.translate("gui.contraptions.not_fast_enough", I18n.format(getBlockState().getBlock() ITextComponent hint = Lang.translate("gui.contraptions.not_fast_enough", I18n.format(getBlockState().getBlock()
.getTranslationKey())); .getTranslationKey()));
List<String> cutString = TooltipHelper.cutString(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE); List<ITextComponent> cutString = TooltipHelper.cutTextComponent(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE);
for (int i = 0; i < cutString.size(); i++) for (int i = 0; i < cutString.size(); i++)
tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i))); tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i)));
return true; return true;

View File

@ -40,6 +40,7 @@ import net.minecraft.util.math.RayTraceContext.BlockMode;
import net.minecraft.util.math.RayTraceContext.FluidMode; import net.minecraft.util.math.RayTraceContext.FluidMode;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
@ -67,7 +68,7 @@ public class BlockzapperItem extends ZapperItem {
ITextComponent componentName = ITextComponent componentName =
Lang.translate("blockzapper.component." + Lang.asId(c.name())).formatted(TextFormatting.GRAY); Lang.translate("blockzapper.component." + Lang.asId(c.name())).formatted(TextFormatting.GRAY);
ITextComponent tierName = Lang.translate("blockzapper.componentTier." + Lang.asId(tier.name())).formatted(tier.color); ITextComponent tierName = Lang.translate("blockzapper.componentTier." + Lang.asId(tier.name())).formatted(tier.color);
ItemDescription.add(tooltip, "> " + componentName + ": " + tierName); ItemDescription.add(tooltip, new StringTextComponent("> ").append(componentName).append(": ").append(tierName));
} }
} }
} }

View File

@ -121,7 +121,7 @@ public abstract class AbstractFilterScreen<F extends AbstractFilterContainer> ex
if (!button.isHovered()) if (!button.isHovered())
return; return;
List<ITextComponent> tip = button.getToolTip(); List<ITextComponent> tip = button.getToolTip();
TooltipHelper.cutString(tooltip, GRAY, GRAY).stream().map(ITextComponent::of).forEachOrdered(tip::add); tip.addAll(TooltipHelper.cutTextComponent(tooltip, GRAY, GRAY));
} }
@Override @Override

View File

@ -74,7 +74,7 @@ public class FilterItem extends Item implements INamedContainerProvider {
List<ITextComponent> makeSummary = makeSummary(stack); List<ITextComponent> makeSummary = makeSummary(stack);
if (makeSummary.isEmpty()) if (makeSummary.isEmpty())
return; return;
ItemDescription.add(tooltip, " "); ItemDescription.add(tooltip, ITextComponent.of(" "));
ItemDescription.add(tooltip, makeSummary); ItemDescription.add(tooltip, makeSummary);
} }
} }

View File

@ -242,7 +242,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
boolean enabled = indicator.state == State.ON; boolean enabled = indicator.state == State.ON;
List<ITextComponent> tip = button.getToolTip(); List<ITextComponent> tip = button.getToolTip();
tip.add((enabled ? optionEnabled : optionDisabled).copy().formatted(TextFormatting.BLUE)); tip.add((enabled ? optionEnabled : optionDisabled).copy().formatted(TextFormatting.BLUE));
TooltipHelper.cutString(Lang.translate("gui.schematicannon.option." + tooltipKey + ".description"), GRAY, GRAY).forEach(s -> tip.add(new StringTextComponent(s).formatted(GRAY))); tip.addAll(TooltipHelper.cutTextComponent(Lang.translate("gui.schematicannon.option." + tooltipKey + ".description"), GRAY, GRAY));
} }
@ -325,15 +325,15 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
if (hoveredSlot != null && !hoveredSlot.getHasStack()) { if (hoveredSlot != null && !hoveredSlot.getHasStack()) {
if (hoveredSlot.getSlotIndex() == 0) if (hoveredSlot.getSlotIndex() == 0)
renderTooltip(matrixStack, renderTooltip(matrixStack,
TooltipHelper.cutStringToComponents(Lang.translate(_slotSchematic), TextFormatting.GRAY, TextFormatting.BLUE), TooltipHelper.cutTextComponent(Lang.translate(_slotSchematic), TextFormatting.GRAY, TextFormatting.BLUE),
mouseX, mouseY); mouseX, mouseY);
if (hoveredSlot.getSlotIndex() == 2) if (hoveredSlot.getSlotIndex() == 2)
renderTooltip(matrixStack, renderTooltip(matrixStack,
TooltipHelper.cutStringToComponents(Lang.translate(_slotListPrinter), TextFormatting.GRAY, TextFormatting.BLUE), TooltipHelper.cutTextComponent(Lang.translate(_slotListPrinter), TextFormatting.GRAY, TextFormatting.BLUE),
mouseX, mouseY); mouseX, mouseY);
if (hoveredSlot.getSlotIndex() == 4) if (hoveredSlot.getSlotIndex() == 4)
renderTooltip(matrixStack, renderTooltip(matrixStack,
TooltipHelper.cutStringToComponents(Lang.translate(_slotGunpowder), TextFormatting.GRAY, TextFormatting.BLUE), TooltipHelper.cutTextComponent(Lang.translate(_slotGunpowder), TextFormatting.GRAY, TextFormatting.BLUE),
mouseX, mouseY); mouseX, mouseY);
} }

View File

@ -1,20 +1,7 @@
package com.simibubi.create.foundation.item; package com.simibubi.create.foundation.item;
import static com.simibubi.create.foundation.item.TooltipHelper.cutString; import static com.simibubi.create.foundation.item.TooltipHelper.*;
import static net.minecraft.util.text.TextFormatting.AQUA; import static net.minecraft.util.text.TextFormatting.*;
import static net.minecraft.util.text.TextFormatting.BLUE;
import static net.minecraft.util.text.TextFormatting.DARK_GRAY;
import static net.minecraft.util.text.TextFormatting.DARK_GREEN;
import static net.minecraft.util.text.TextFormatting.DARK_PURPLE;
import static net.minecraft.util.text.TextFormatting.DARK_RED;
import static net.minecraft.util.text.TextFormatting.GOLD;
import static net.minecraft.util.text.TextFormatting.GRAY;
import static net.minecraft.util.text.TextFormatting.GREEN;
import static net.minecraft.util.text.TextFormatting.LIGHT_PURPLE;
import static net.minecraft.util.text.TextFormatting.RED;
import static net.minecraft.util.text.TextFormatting.STRIKETHROUGH;
import static net.minecraft.util.text.TextFormatting.WHITE;
import static net.minecraft.util.text.TextFormatting.YELLOW;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -83,8 +70,8 @@ public class ItemDescription {
} }
public ItemDescription withSummary(ITextComponent summary) { public ItemDescription withSummary(ITextComponent summary) {
addStrings(linesOnShift, cutString(summary, palette.color, palette.hColor)); addStrings(linesOnShift, cutTextComponent(summary, palette.color, palette.hColor));
add(linesOnShift, ""); add(linesOnShift, StringTextComponent.EMPTY);
return this; return this;
} }
@ -109,11 +96,10 @@ public class ItemDescription {
if (hasSpeedRequirement) { if (hasSpeedRequirement) {
List<ITextComponent> speedLevels = Lang.translatedOptions("tooltip.speedRequirement", "none", "medium", "high"); List<ITextComponent> speedLevels = Lang.translatedOptions("tooltip.speedRequirement", "none", "medium", "high");
int index = minimumRequiredSpeedLevel.ordinal(); int index = minimumRequiredSpeedLevel.ordinal();
String level = IFormattableTextComponent level = new StringTextComponent(makeProgressBar(3, index)).append(speedLevels.get(index)).formatted(minimumRequiredSpeedLevel.getTextColor());
minimumRequiredSpeedLevel.getTextColor() + makeProgressBar(3, index) + speedLevels.get(index);
if (hasGlasses) if (hasGlasses)
level += " (" + minimumRequiredSpeedLevel.getSpeedValue() + rpmUnit + "+)"; level.append(" (" + minimumRequiredSpeedLevel.getSpeedValue()).append(rpmUnit).append("+)");
add(linesOnShift, Lang.translate("tooltip.speedRequirement").formatted(GRAY)); add(linesOnShift, Lang.translate("tooltip.speedRequirement").formatted(GRAY));
add(linesOnShift, level); add(linesOnShift, level);
@ -127,11 +113,10 @@ public class ItemDescription {
StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH
: (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW); : (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW);
int index = impactId.ordinal(); int index = impactId.ordinal();
String level = impactId.getAbsoluteColor() + makeProgressBar(3, index) + stressLevels.get(index); IFormattableTextComponent level = new StringTextComponent(makeProgressBar(3, index)).append(stressLevels.get(index)).formatted(impactId.getAbsoluteColor());
if (hasGlasses) if (hasGlasses)
level += " (" + impacts.get(id) level.append(" (" + impacts.get(id).get()).append(stressUnit).append(")");
.get() + stressUnit + ")";
add(linesOnShift, Lang.translate("tooltip.stressImpact").formatted(GRAY)); add(linesOnShift, Lang.translate("tooltip.stressImpact").formatted(GRAY));
add(linesOnShift, level); add(linesOnShift, level);
@ -145,25 +130,24 @@ public class ItemDescription {
StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.LOW StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.LOW
: (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.HIGH); : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.HIGH);
int index = StressImpact.values().length - 2 - impactId.ordinal(); int index = StressImpact.values().length - 2 - impactId.ordinal();
String level = impactId.getAbsoluteColor() + makeProgressBar(3, index) + stressCapacityLevels.get(index); IFormattableTextComponent level = new StringTextComponent(makeProgressBar(3, index)).append(stressCapacityLevels.get(index)).formatted(impactId.getAbsoluteColor());
if (hasGlasses) if (hasGlasses)
level += " (" + capacity + stressUnit + ")"; level.append(" (" + capacity).append(stressUnit).append(")");
if (!isEngine && ((IRotate) block).showCapacityWithAnnotation()) if (!isEngine && ((IRotate) block).showCapacityWithAnnotation())
level += level.append(" ").append(Lang.translate("tooltip.capacityProvided.asGenerator").formatted(DARK_GRAY, ITALIC));
" " + DARK_GRAY + TextFormatting.ITALIC + Lang.translate("tooltip.capacityProvided.asGenerator");
add(linesOnShift, Lang.translate("tooltip.capacityProvided").formatted(GRAY)); add(linesOnShift, Lang.translate("tooltip.capacityProvided").formatted(GRAY));
add(linesOnShift, level); add(linesOnShift, level);
IFormattableTextComponent genSpeed = generatorSpeed(block, rpmUnit); IFormattableTextComponent genSpeed = generatorSpeed(block, rpmUnit);
if (!genSpeed.getUnformattedComponentText().equals("")) { if (!genSpeed.getUnformattedComponentText().equals("")) {
add(linesOnShift, GREEN + " " + genSpeed); add(linesOnShift, new StringTextComponent(" ").append(genSpeed).formatted(GREEN));
} }
} }
if (hasSpeedRequirement || hasStressImpact || hasStressCapacity) if (hasSpeedRequirement || hasStressImpact || hasStressCapacity)
add(linesOnShift, ""); add(linesOnShift, StringTextComponent.EMPTY);
return this; return this;
} }
@ -178,14 +162,14 @@ public class ItemDescription {
} }
public ItemDescription withBehaviour(String condition, String behaviour) { public ItemDescription withBehaviour(String condition, String behaviour) {
add(linesOnShift, GRAY + condition); add(linesOnShift, new StringTextComponent(condition).formatted(GRAY));
addStrings(linesOnShift, cutString(behaviour, palette.color, palette.hColor, 1)); addStrings(linesOnShift, cutStringTextComponent(behaviour, palette.color, palette.hColor, 1));
return this; return this;
} }
public ItemDescription withControl(String condition, String action) { public ItemDescription withControl(String condition, String action) {
add(linesOnCtrl, GRAY + condition); add(linesOnCtrl, new StringTextComponent(condition).formatted(GRAY));
addStrings(linesOnCtrl, cutString(action, palette.color, palette.hColor, 1)); addStrings(linesOnCtrl, cutStringTextComponent(action, palette.color, palette.hColor, 1));
return this; return this;
} }
@ -248,7 +232,7 @@ public class ItemDescription {
return palette.hColor + s + palette.color; return palette.hColor + s + palette.color;
} }
public static void addStrings(List<ITextComponent> infoList, List<String> textLines) { public static void addStrings(List<ITextComponent> infoList, List<ITextComponent> textLines) {
textLines.forEach(s -> add(infoList, s)); textLines.forEach(s -> add(infoList, s));
} }
@ -256,10 +240,6 @@ public class ItemDescription {
infoList.addAll(textLines); infoList.addAll(textLines);
} }
public static void add(List<ITextComponent> infoList, String line) {
infoList.add(new StringTextComponent(line));
}
public static void add(List<ITextComponent> infoList, ITextComponent line) { public static void add(List<ITextComponent> infoList, ITextComponent line) {
infoList.add(line); infoList.add(line);
} }

View File

@ -2,11 +2,8 @@ package com.simibubi.create.foundation.item;
import static net.minecraft.util.text.TextFormatting.DARK_GRAY; import static net.minecraft.util.text.TextFormatting.DARK_GRAY;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.mojang.bridge.game.Language; import com.mojang.bridge.game.Language;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
@ -26,9 +23,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.TieredItem; import net.minecraft.item.TieredItem;
import net.minecraft.util.text.IFormattableTextComponent; import net.minecraft.util.text.*;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
public class TooltipHelper { public class TooltipHelper {
@ -44,17 +39,12 @@ public class TooltipHelper {
.formatted(colorFormat)); .formatted(colorFormat));
} }
@Deprecated
public static List<String> cutString(ITextComponent s, TextFormatting defaultColor, TextFormatting highlightColor) { public static List<String> cutString(ITextComponent s, TextFormatting defaultColor, TextFormatting highlightColor) {
return cutString(s.getUnformattedComponentText(), defaultColor, highlightColor, 0); return cutString(s.getUnformattedComponentText(), defaultColor, highlightColor, 0);
} }
public static List<ITextComponent> cutStringToComponents(ITextComponent s, TextFormatting defaultColor, @Deprecated
TextFormatting highlightColor) {
return cutString(s.getUnformattedComponentText(), defaultColor, highlightColor, 0).stream()
.map(ITextComponent::of)
.collect(Collectors.toList());
}
public static List<String> cutString(String s, TextFormatting defaultColor, TextFormatting highlightColor, public static List<String> cutString(String s, TextFormatting defaultColor, TextFormatting highlightColor,
int indent) { int indent) {
String lineStart = defaultColor.toString(); String lineStart = defaultColor.toString();
@ -93,6 +83,57 @@ public class TooltipHelper {
return lines; return lines;
} }
public static List<ITextComponent> cutStringTextComponent(String c, TextFormatting defaultColor, TextFormatting highlightColor) {
return cutTextComponent(ITextComponent.of(c), defaultColor, highlightColor, 0);
}
public static List<ITextComponent> cutTextComponent(ITextComponent c, TextFormatting defaultColor, TextFormatting highlightColor) {
return cutTextComponent(c, defaultColor, highlightColor, 0);
}
public static List<ITextComponent> cutStringTextComponent(String c, TextFormatting defaultColor, TextFormatting highlightColor,
int indent) {
return cutTextComponent(ITextComponent.of(c), defaultColor, highlightColor, indent);
}
public static List<ITextComponent> cutTextComponent(ITextComponent c, TextFormatting defaultColor, TextFormatting highlightColor,
int indent) {
IFormattableTextComponent lineStart = StringTextComponent.EMPTY.copy();
for (int i = 0; i < indent; i++)
lineStart.append(" ");
lineStart.formatted(defaultColor);
List<ITextComponent> lines = new ArrayList<>();
String rawText = c.getUnformattedComponentText();
String[] words = rawText.split(" ");
String word;
IFormattableTextComponent currentLine = lineStart.copy();
boolean firstWord = true;
boolean lastWord;
// Apply hard wrap
for (int i = 0; i < words.length; i++) {
word = words[i];
lastWord = i == words.length - 1;
if (!lastWord && !firstWord && getComponentLength(currentLine) + word.length() > maxCharsPerLine) {
lines.add(currentLine);
currentLine = lineStart.copy();
firstWord = true;
}
currentLine.append(new StringTextComponent((firstWord ? "" : " ") + word.replace("_", "")).formatted(word.matches("_([^_]+)_") ? highlightColor : defaultColor));
firstWord = false;
}
if (!firstWord) {
lines.add(currentLine);
}
return lines;
}
private static void checkLocale() { private static void checkLocale() {
Language currentLanguage = Minecraft.getInstance() Language currentLanguage = Minecraft.getInstance()
.getLanguageManager() .getLanguageManager()
@ -201,4 +242,13 @@ public class TooltipHelper {
.getTranslationKey(stack) + ".tooltip"; .getTranslationKey(stack) + ".tooltip";
} }
private static int getComponentLength(ITextComponent component) {
AtomicInteger l = new AtomicInteger();
TextProcessing.visitFormatted(component, Style.EMPTY, (s, style, charConsumer) -> {
l.getAndIncrement();
return true;
});
return l.get();
}
} }

View File

@ -24,7 +24,7 @@ public class WipScription extends ItemDescription {
int index = new Random().nextInt(descriptions); int index = new Random().nextInt(descriptions);
ITextComponent translate = Lang.translate("tooltip.randomWipDescription" + index); ITextComponent translate = Lang.translate("tooltip.randomWipDescription" + index);
List<ITextComponent> lines = getLines(); List<ITextComponent> lines = getLines();
TooltipHelper.cutString(translate, TextFormatting.DARK_RED, TextFormatting.DARK_RED).forEach(s -> lines.add(new StringTextComponent(s).formatted(TextFormatting.DARK_RED))); lines.addAll(TooltipHelper.cutTextComponent(translate, TextFormatting.DARK_RED, TextFormatting.DARK_RED));
} }
} }