Yet more TextComponent nonsense

1.16 just keeps on giving
This commit is contained in:
simibubi 2020-10-20 21:03:43 +02:00
parent 41148a5e39
commit 12e5b95157
9 changed files with 825 additions and 768 deletions

File diff suppressed because it is too large Load diff

View file

@ -60,9 +60,9 @@
},
{
"when": {
"south": "false",
"up": "true",
"down": "false",
"south": "false",
"north": "true"
},
"apply": {
@ -71,9 +71,9 @@
},
{
"when": {
"south": "true",
"up": "true",
"down": "false",
"south": "true",
"north": "false"
},
"apply": {
@ -82,9 +82,9 @@
},
{
"when": {
"south": "false",
"up": "false",
"down": "true",
"south": "false",
"north": "true"
},
"apply": {
@ -93,9 +93,9 @@
},
{
"when": {
"south": "true",
"up": "false",
"down": "true",
"south": "true",
"north": "false"
},
"apply": {
@ -104,9 +104,9 @@
},
{
"when": {
"south": "false",
"up": "true",
"down": "true",
"south": "false",
"north": "false"
},
"apply": {
@ -115,9 +115,9 @@
},
{
"when": {
"south": "false",
"up": "true",
"down": "false",
"south": "false",
"north": "false"
},
"apply": {
@ -126,9 +126,9 @@
},
{
"when": {
"south": "false",
"up": "false",
"down": "true",
"south": "false",
"north": "false"
},
"apply": {
@ -137,9 +137,9 @@
},
{
"when": {
"up": "false",
"down": "false",
"south": "true",
"up": "false",
"down": "false",
"north": "true"
},
"apply": {
@ -148,9 +148,9 @@
},
{
"when": {
"south": "false",
"up": "false",
"down": "false",
"south": "false",
"north": "true"
},
"apply": {
@ -159,9 +159,9 @@
},
{
"when": {
"south": "true",
"up": "false",
"down": "false",
"south": "true",
"north": "false"
},
"apply": {
@ -170,9 +170,9 @@
},
{
"when": {
"south": "false",
"up": "false",
"down": "false",
"south": "false",
"north": "false"
},
"apply": {
@ -181,8 +181,8 @@
},
{
"when": {
"south": "true",
"west": "true",
"south": "true",
"north": "false",
"east": "false"
},
@ -192,8 +192,8 @@
},
{
"when": {
"south": "true",
"west": "false",
"south": "true",
"north": "false",
"east": "true"
},
@ -203,8 +203,8 @@
},
{
"when": {
"south": "false",
"west": "true",
"south": "false",
"north": "true",
"east": "false"
},
@ -214,8 +214,8 @@
},
{
"when": {
"south": "false",
"west": "false",
"south": "false",
"north": "true",
"east": "true"
},
@ -225,8 +225,8 @@
},
{
"when": {
"south": "true",
"west": "false",
"south": "true",
"north": "true",
"east": "false"
},
@ -236,8 +236,8 @@
},
{
"when": {
"south": "true",
"west": "false",
"south": "true",
"north": "false",
"east": "false"
},
@ -247,8 +247,8 @@
},
{
"when": {
"south": "false",
"west": "false",
"south": "false",
"north": "true",
"east": "false"
},
@ -258,8 +258,8 @@
},
{
"when": {
"south": "false",
"west": "true",
"south": "false",
"north": "false",
"east": "true"
},
@ -269,8 +269,8 @@
},
{
"when": {
"south": "false",
"west": "true",
"south": "false",
"north": "false",
"east": "false"
},
@ -280,8 +280,8 @@
},
{
"when": {
"south": "false",
"west": "false",
"south": "false",
"north": "false",
"east": "true"
},
@ -291,8 +291,8 @@
},
{
"when": {
"south": "false",
"west": "false",
"south": "false",
"north": "false",
"east": "false"
},
@ -303,8 +303,8 @@
{
"when": {
"up": "true",
"down": "false",
"west": "false",
"down": "false",
"east": "true"
},
"apply": {
@ -314,8 +314,8 @@
{
"when": {
"up": "true",
"down": "false",
"west": "true",
"down": "false",
"east": "false"
},
"apply": {
@ -325,8 +325,8 @@
{
"when": {
"up": "false",
"down": "true",
"west": "false",
"down": "true",
"east": "true"
},
"apply": {
@ -336,8 +336,8 @@
{
"when": {
"up": "false",
"down": "true",
"west": "true",
"down": "true",
"east": "false"
},
"apply": {
@ -347,8 +347,8 @@
{
"when": {
"up": "true",
"down": "true",
"west": "false",
"down": "true",
"east": "false"
},
"apply": {
@ -358,8 +358,8 @@
{
"when": {
"up": "true",
"down": "false",
"west": "false",
"down": "false",
"east": "false"
},
"apply": {
@ -369,8 +369,8 @@
{
"when": {
"up": "false",
"west": "false",
"down": "true",
"west": "false",
"east": "false"
},
"apply": {
@ -380,8 +380,8 @@
{
"when": {
"up": "false",
"down": "false",
"west": "true",
"down": "false",
"east": "true"
},
"apply": {
@ -391,8 +391,8 @@
{
"when": {
"up": "false",
"down": "false",
"west": "false",
"down": "false",
"east": "true"
},
"apply": {
@ -402,8 +402,8 @@
{
"when": {
"up": "false",
"down": "false",
"west": "true",
"down": "false",
"east": "false"
},
"apply": {
@ -413,8 +413,8 @@
{
"when": {
"up": "false",
"down": "false",
"west": "false",
"down": "false",
"east": "false"
},
"apply": {

View file

@ -29,8 +29,8 @@
},
{
"when": {
"sticky_south": "true",
"axis": "x"
"axis": "x",
"sticky_south": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_x_sticky",
@ -39,8 +39,8 @@
},
{
"when": {
"sticky_south": "true",
"axis": "y"
"axis": "y",
"sticky_south": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_y_sticky"
@ -48,8 +48,8 @@
},
{
"when": {
"sticky_south": "true",
"axis": "z"
"axis": "z",
"sticky_south": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_x_sticky",
@ -59,8 +59,8 @@
},
{
"when": {
"sticky_south": "false",
"axis": "x"
"axis": "x",
"sticky_south": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_x",
@ -69,8 +69,8 @@
},
{
"when": {
"sticky_south": "false",
"axis": "y"
"axis": "y",
"sticky_south": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_y"
@ -78,8 +78,8 @@
},
{
"when": {
"sticky_south": "false",
"axis": "z"
"axis": "z",
"sticky_south": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_x",
@ -149,8 +149,8 @@
},
{
"when": {
"sticky_north": "true",
"axis": "x"
"axis": "x",
"sticky_north": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_x_sticky"
@ -158,8 +158,8 @@
},
{
"when": {
"sticky_north": "true",
"axis": "y"
"axis": "y",
"sticky_north": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_y_sticky",
@ -168,8 +168,8 @@
},
{
"when": {
"sticky_north": "true",
"axis": "z"
"axis": "z",
"sticky_north": "true"
},
"apply": {
"model": "create:block/radial_chassis_side_x_sticky",
@ -178,8 +178,8 @@
},
{
"when": {
"sticky_north": "false",
"axis": "x"
"axis": "x",
"sticky_north": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_x"
@ -187,8 +187,8 @@
},
{
"when": {
"sticky_north": "false",
"axis": "y"
"axis": "y",
"sticky_north": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_y",
@ -197,8 +197,8 @@
},
{
"when": {
"sticky_north": "false",
"axis": "z"
"axis": "z",
"sticky_north": "false"
},
"apply": {
"model": "create:block/radial_chassis_side_x",

View file

@ -383,11 +383,10 @@ public abstract class KineticTileEntity extends SmartTileEntity
if (overStressed && AllConfigs.CLIENT.enableOverstressedTooltip.get()) {
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<ITextComponent> cutString = TooltipHelper.cutTextComponent(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE);
ITextComponent hint = Lang.translate("gui.contraptions.network_overstressed");
List<ITextComponent> cutString = TooltipHelper.cutTextComponent(hint, GRAY, TextFormatting.WHITE);
for (int i = 0; i < cutString.size(); i++)
tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i)));
tooltip.add(componentSpacing.copy().append(cutString.get(i)));
return true;
}
@ -395,9 +394,9 @@ public abstract class KineticTileEntity extends SmartTileEntity
tooltip.add(componentSpacing.copy().append(Lang.translate("tooltip.speedRequirement").formatted(GOLD)));
ITextComponent hint = Lang.translate("gui.contraptions.not_fast_enough", I18n.format(getBlockState().getBlock()
.getTranslationKey()));
List<ITextComponent> cutString = TooltipHelper.cutTextComponent(componentSpacing.copy().append(hint), GRAY, TextFormatting.WHITE);
List<ITextComponent> cutString = TooltipHelper.cutTextComponent(hint, GRAY, TextFormatting.WHITE);
for (int i = 0; i < cutString.size(); i++)
tooltip.add((i == 0 ? StringTextComponent.EMPTY : componentSpacing).copy().append(cutString.get(i)));
tooltip.add(componentSpacing.copy().append(cutString.get(i)));
return true;
}

View file

@ -40,7 +40,7 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour {
@Override
public void visitNewPosition(MovementContext context, BlockPos pos) {
super.visitNewPosition(context, pos);
Vec3d facingVec = new Vec3d(context.state.get(SawBlock.FACING).getDirectionVec());
Vector3d facingVec = Vector3d.of(context.state.get(SawBlock.FACING).getDirectionVec());
facingVec = context.rotation.apply(facingVec);
Direction closestToFacing = Direction.getFacingFromVector(facingVec.x, facingVec.y, facingVec.z);

View file

@ -21,6 +21,7 @@ import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
//TODO colors get purged with current approach, proper checklist item with UI is needed
public class MaterialChecklist {
public Map<Item, Integer> gathered;
@ -92,9 +93,9 @@ public class MaterialChecklist {
Collections.sort(keys, (item1, item2) -> {
Locale locale = Locale.ENGLISH;
String name1 =
new TranslationTextComponent(item1.getTranslationKey()).getUnformattedComponentText().toLowerCase(locale);
new TranslationTextComponent(item1.getTranslationKey()).getString().toLowerCase(locale);
String name2 =
new TranslationTextComponent(item2.getTranslationKey()).getUnformattedComponentText().toLowerCase(locale);
new TranslationTextComponent(item2.getTranslationKey()).getString().toLowerCase(locale);
return name1.compareTo(name2);
});
@ -117,7 +118,7 @@ public class MaterialChecklist {
}
itemsWritten++;
string.append(unfinishedEntry(new ItemStack(item), amount));
string.append(unfinishedEntry(new ItemStack(item), amount).getString());
}
for (Item item : completed) {
@ -129,7 +130,7 @@ public class MaterialChecklist {
}
itemsWritten++;
string.append(gatheredEntry(new ItemStack(item), getRequiredAmount(item)));
string.append(gatheredEntry(new ItemStack(item), getRequiredAmount(item)).getString());
}
string.append("\"}");
@ -154,8 +155,9 @@ public class MaterialChecklist {
int stacks = amount / 64;
int remainder = amount % 64;
TranslationTextComponent tc = new TranslationTextComponent(item.getTranslationKey());
return tc.append(" \\u2714\n x" + amount).formatted(TextFormatting.DARK_GREEN).append(new StringTextComponent(" | "
+ stacks + "\\u25A4 +" + remainder + "\n").formatted(TextFormatting.GRAY));
return tc.append(" \\u2714\n " + "---");
//.formatted(TextFormatting.DARK_GREEN).append(new StringTextComponent(" | "
//+ "-" + "\\u25A4 +" + "--" + "\n").formatted(TextFormatting.GRAY));
// return TextFormatting.DARK_GREEN + tc.getFormattedText() + " \\u2714\n x" + amount + TextFormatting.GRAY + " | "
// + stacks + "\\u25A4 +" + remainder + "\n";
}

View file

@ -1,5 +1,11 @@
package com.simibubi.create.content.schematics.block;
import static com.simibubi.create.foundation.gui.AllGuiTextures.SCHEMATIC_TABLE;
import static com.simibubi.create.foundation.gui.AllGuiTextures.SCHEMATIC_TABLE_PROGRESS;
import java.nio.file.Paths;
import java.util.List;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlocks;
@ -14,6 +20,7 @@ import com.simibubi.create.foundation.gui.widgets.Label;
import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.client.gui.IHasContainer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
@ -22,13 +29,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import java.nio.file.Paths;
import java.util.List;
import static com.simibubi.create.foundation.gui.AllGuiTextures.SCHEMATIC_TABLE;
import static com.simibubi.create.foundation.gui.AllGuiTextures.SCHEMATIC_TABLE_PROGRESS;
public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicTableContainer>
implements IHasContainer<SchematicTableContainer> {
@ -107,7 +107,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
if (container.getTileEntity().isUploading)
textRenderer.drawWithShadow(matrixStack, uploading, mainLeft + 11, mainTop + 3, 0xffffff);
else if (container.getSlot(1).getHasStack())
else if (container.getSlot(1)
.getHasStack())
textRenderer.drawWithShadow(matrixStack, finished, mainLeft + 11, mainTop + 3, 0xffffff);
else
textRenderer.drawWithShadow(matrixStack, title, mainLeft + 11, mainTop + 3, 0xffffff);
@ -125,8 +126,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
* MathHelper.lerp(partialTicks, lastChasingProgress, chasingProgress));
int height = SCHEMATIC_TABLE_PROGRESS.height;
RenderSystem.disableLighting();
drawTexture(matrixStack, mainLeft + 70, mainTop + 58, SCHEMATIC_TABLE_PROGRESS.startX, SCHEMATIC_TABLE_PROGRESS.startY, width,
height);
drawTexture(matrixStack, mainLeft + 70, mainTop + 58, SCHEMATIC_TABLE_PROGRESS.startX,
SCHEMATIC_TABLE_PROGRESS.startY, width, height);
}
@ -148,7 +149,8 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
if (schematicsLabel != null) {
schematicsLabel.colored(0xCCDDFF);
schematicsLabel.text = new StringTextComponent(container.getTileEntity().uploadingSchematic);
String uploadingSchematic = container.getTileEntity().uploadingSchematic;
schematicsLabel.text = uploadingSchematic == null ? null : new StringTextComponent(uploadingSchematic);
}
if (schematicsArea != null)
schematicsArea.visible = false;

View file

@ -1,10 +1,14 @@
package com.simibubi.create.foundation.gui.widgets;
import java.util.Objects;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.Create;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
@ -37,6 +41,7 @@ public class Label extends AbstractSimiWidget {
public Label withSuffix(String s) {
suffix = s;
Create.logger.info("Suffix is now " + Objects.toString(s));
return this;
}
@ -51,7 +56,7 @@ public class Label extends AbstractSimiWidget {
String trim = "...";
int trimWidth = fontRenderer.getStringWidth(trim);
String raw = newText.getUnformattedComponentText();
String raw = newText.getString();
StringBuilder builder = new StringBuilder(raw);
int startIndex = trimFront ? 0 : raw.length() - 1;
int endIndex = !trimFront ? 0 : raw.length() - 1;
@ -75,10 +80,14 @@ public class Label extends AbstractSimiWidget {
return;
RenderSystem.color4f(1, 1, 1, 1);
IFormattableTextComponent copy = text.copy();
if (suffix != null && !suffix.isEmpty())
copy.append(suffix);
if (hasShadow)
font.drawWithShadow(matrixStack, text.copy().append(suffix), x, y, color);
font.drawWithShadow(matrixStack, copy, x, y, color);
else
font.draw(matrixStack, text.copy().append(suffix), x, y, color);
font.draw(matrixStack, copy, x, y, color);
}
}

View file

@ -1,7 +1,5 @@
package com.simibubi.create.foundation.item;
import static net.minecraft.util.text.TextFormatting.DARK_GRAY;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -44,9 +42,8 @@ public class TooltipHelper {
public static IFormattableTextComponent holdShift(Palette color, boolean highlighted) {
TextFormatting colorFormat = highlighted ? color.hColor : color.color;
return Lang.translate("tooltip.holdKey", DARK_GRAY)
.append(Lang.translate("tooltip.keyShift")
.formatted(colorFormat));
return Lang.translate("tooltip.holdKey", Lang.translate("tooltip.keyShift")
.formatted(colorFormat)).formatted(TextFormatting.DARK_GRAY);
}
public static void referTo(IItemProvider item, Supplier<? extends IItemProvider> itemWithTooltip) {
@ -103,21 +100,23 @@ public class TooltipHelper {
return lines;
}
public static List<ITextComponent> cutStringTextComponent(String c, TextFormatting defaultColor, TextFormatting highlightColor) {
public static List<ITextComponent> cutStringTextComponent(String c, TextFormatting defaultColor,
TextFormatting highlightColor) {
return cutTextComponent(new StringTextComponent(c), defaultColor, highlightColor, 0);
}
public static List<ITextComponent> cutTextComponent(ITextComponent c, TextFormatting defaultColor, TextFormatting highlightColor) {
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) {
public static List<ITextComponent> cutStringTextComponent(String c, TextFormatting defaultColor,
TextFormatting highlightColor, int indent) {
return cutTextComponent(new StringTextComponent(c), defaultColor, highlightColor, indent);
}
public static List<ITextComponent> cutTextComponent(ITextComponent c, TextFormatting defaultColor, TextFormatting highlightColor,
int 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(" ");
@ -143,7 +142,8 @@ public class TooltipHelper {
firstWord = true;
}
currentLine.append(new StringTextComponent((firstWord ? "" : " ") + word.replace("_", "")).formatted(word.matches("_([^_]+)_") ? highlightColor : defaultColor));
currentLine.append(new StringTextComponent((firstWord ? "" : " ") + word.replace("_", ""))
.formatted(word.matches("_([^_]+)_") ? highlightColor : defaultColor));
firstWord = false;
}
@ -272,7 +272,8 @@ public class TooltipHelper {
public static String getUnformattedDeepText(ITextComponent component) {
StringBuilder b = new StringBuilder();
b.append(component.getString());
component.getSiblings().forEach(c -> {
component.getSiblings()
.forEach(c -> {
b.append(getUnformattedDeepText(c));
});
return b.toString();