Fixed traits not appearing correctly in tooltips

This commit is contained in:
Sollace 2021-11-17 22:33:35 +02:00
parent c8fc88711d
commit 8124731f58
3 changed files with 8 additions and 5 deletions

View file

@ -148,7 +148,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
return of(block.asItem());
}
private static Optional<SpellTraits> getEmbeddedTraits(ItemStack stack) {
public static Optional<SpellTraits> getEmbeddedTraits(ItemStack stack) {
if (!(stack.hasTag() && stack.getTag().contains("spell_traits", NbtElement.COMPOUND_TYPE))) {
return Optional.empty();
}

View file

@ -78,7 +78,10 @@ public class TraitDiscovery implements NbtSerialisable {
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip) {
getKnownTraits(stack.getItem()).appendTooltip(tooltip);
SpellTraits.getEmbeddedTraits(stack)
.flatMap(embedded -> SpellTraits.fromEntries(embedded.entries().stream().filter(e -> isKnown(e.getKey()))))
.orElseGet(() -> getKnownTraits(stack.getItem()))
.appendTooltip(tooltip);
}
@Override

View file

@ -52,14 +52,14 @@ public class ItemTraitsTooltipRenderer extends BaseText implements OrderedText,
var entries = traits.stream().toList();
for (int i = 0; i < entries.size(); i++) {
int xx = x + (i % columns);
int yy = y + (i / columns);
int xx = x + (i % columns) * 10;
int yy = y + (i / columns) * 10;
Entry<Trait, Float> entry = entries.get(i);
RenderSystem.setShaderTexture(0, entry.getKey().getSprite());
DrawableHelper.drawTexture(matrices, xx, yy, 1, 0, 0, 8, 8, 8, 8);
String string = String.valueOf(entry.getValue());
String string = String.format("%.2f", entry.getValue());
matrices.push();
xx += 19 - 2 - textRenderer.getWidth(string);