Change how traits are obfuscated and obfuscate trait descriptions if you haven't discovered it yet

This commit is contained in:
Sollace 2022-10-21 14:55:44 +02:00
parent 73159ececa
commit c5349bd242
4 changed files with 44 additions and 24 deletions

View file

@ -8,7 +8,6 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.minelittlepony.common.client.gui.Tooltip;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -65,10 +64,31 @@ public enum Trait {
private final Identifier sprite; private final Identifier sprite;
private final TraitGroup group; private final TraitGroup group;
private final Text tooltip;
private final Text obfuscatedTooltip;
Trait(TraitGroup group) { Trait(TraitGroup group) {
this.id = Unicopia.id(name().toLowerCase()); this.id = Unicopia.id(name().toLowerCase());
this.sprite = Unicopia.id("textures/gui/trait/" + name().toLowerCase() + ".png"); this.sprite = Unicopia.id("textures/gui/trait/" + name().toLowerCase() + ".png");
this.group = group; this.group = group;
Formatting corruptionColor = getGroup().getCorruption() < -0.01F
? Formatting.GREEN
: getGroup().getCorruption() > 0.25F
? Formatting.RED
: Formatting.WHITE;
MutableText tooltipText = Text.translatable("gui.unicopia.trait.label",
Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".name")
).formatted(Formatting.YELLOW)
.append(Text.translatable("gui.unicopia.trait.group", getGroup().name().toLowerCase()).formatted(Formatting.ITALIC, Formatting.GRAY))
.append(Text.literal("\n\n").formatted(Formatting.WHITE)
.append(Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".description").formatted(Formatting.GRAY))
.append("\n")
.append(Text.translatable("gui.unicopia.trait.corruption", ItemStack.MODIFIER_FORMAT.format(getGroup().getCorruption())).formatted(Formatting.ITALIC, corruptionColor)));
this.tooltip = tooltipText;
this.obfuscatedTooltip = tooltipText.copy().formatted(Formatting.OBFUSCATED);
} }
public Identifier getId() { public Identifier getId() {
@ -83,22 +103,12 @@ public enum Trait {
return sprite; return sprite;
} }
public Tooltip getTooltip() { public Text getTooltip() {
Formatting corruptionColor = getGroup().getCorruption() < -0.01F return tooltip;
? Formatting.GREEN }
: getGroup().getCorruption() > 0.25F
? Formatting.RED
: Formatting.WHITE;
return Tooltip.of( public Text getObfuscatedTooltip() {
Text.translatable("gui.unicopia.trait.label", return obfuscatedTooltip;
Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".name")
).formatted(Formatting.YELLOW)
.append(Text.translatable("gui.unicopia.trait.group", getGroup().name().toLowerCase()).formatted(Formatting.ITALIC, Formatting.GRAY))
.append(Text.literal("\n\n").formatted(Formatting.WHITE)
.append(Text.translatable("trait." + getId().getNamespace() + "." + getId().getPath() + ".description").formatted(Formatting.GRAY))
.append("\n")
.append(Text.translatable("gui.unicopia.trait.corruption", ItemStack.MODIFIER_FORMAT.format(getGroup().getCorruption())).formatted(Formatting.ITALIC, corruptionColor))), 200);
} }
public static Collection<Trait> all() { public static Collection<Trait> all() {

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.client.gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.spell.trait.*; import com.minelittlepony.unicopia.ability.magic.spell.trait.*;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
@ -17,9 +18,11 @@ import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.*; import net.minecraft.text.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComponent { public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComponent {
private static final Identifier UNKNOWN = Unicopia.id("textures/gui/trait/unknown.png");
private final SpellTraits traits; private final SpellTraits traits;
@ -100,7 +103,7 @@ public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComp
} }
} }
private static boolean isKnown(Trait trait) { public static boolean isKnown(Trait trait) {
return MinecraftClient.getInstance().player == null return MinecraftClient.getInstance().player == null
|| Pony.of(MinecraftClient.getInstance().player).getDiscoveries().isKnown(trait); || Pony.of(MinecraftClient.getInstance().player).getDiscoveries().isKnown(trait);
} }
@ -111,11 +114,7 @@ public class ItemTraitsTooltipRenderer implements Text, OrderedText, TooltipComp
int size = 12; int size = 12;
if (!isKnown(trait)) { RenderSystem.setShaderTexture(0, isKnown(trait) ? trait.getSprite() : UNKNOWN);
trait = Trait.values()[MinecraftClient.getInstance().player.getRandom().nextInt(Trait.all().size())];
}
RenderSystem.setShaderTexture(0, trait.getSprite());
matrices.push(); matrices.push();
matrices.translate(xx, yy, itemRenderer.zOffset + 300.0F); matrices.translate(xx, yy, itemRenderer.zOffset + 300.0F);

View file

@ -102,7 +102,18 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
int left = x + column * colWidth + 3 + (addLabels && row > 0 ? colWidth : 0); int left = x + column * colWidth + 3 + (addLabels && row > 0 ? colWidth : 0);
int top = y + row * rowHeight + 3; int top = y + row * rowHeight + 3;
container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+", false)); var button = container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+", false));
if (entry instanceof Traits traits) {
final Trait trait = traits.trait;
button.onClick(sender -> {
if (MinecraftClient.getInstance().currentScreen instanceof SpellbookScreen spellbook) {
spellbook.getState().setCurrentPageId(SpellbookChapterList.TRAIT_DEX_ID);
spellbook.getTraitDex().pageTo(spellbook, trait);
}
});
}
ii++; ii++;
} }
result.ifPresent(result -> { result.ifPresent(result -> {
@ -263,7 +274,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
@Override @Override
public Tooltip getTooltip() { public Tooltip getTooltip() {
return trait.getTooltip(); return Tooltip.of(ItemTraitsTooltipRenderer.isKnown(trait) ? trait.getTooltip() : trait.getObfuscatedTooltip(), 200);
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB