Added icons for each trait and display known traits on item tooltips
|
@ -16,8 +16,11 @@ import java.util.stream.Collectors;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.minelittlepony.unicopia.client.gui.ItemTraitsTooltipRenderer;
|
||||
import com.minelittlepony.unicopia.util.InventoryUtil;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -25,7 +28,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
@ -93,14 +95,12 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
|
|||
return MathHelper.clamp(get(trait), min, max);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendTooltip(List<Text> tooltip) {
|
||||
if (isEmpty()) {
|
||||
return;
|
||||
}
|
||||
tooltip.add(new LiteralText("Traits:"));
|
||||
traits.forEach((trait, amount) -> {
|
||||
tooltip.add(new LiteralText(trait.name().toLowerCase() + ": " + amount));
|
||||
});
|
||||
tooltip.add(1, new ItemTraitsTooltipRenderer(this));
|
||||
}
|
||||
|
||||
public NbtCompound toNbt() {
|
||||
|
|
|
@ -36,10 +36,12 @@ public enum Trait {
|
|||
public static final Map<String, Trait> REGISTRY = Arrays.stream(values()).collect(Collectors.toMap(Trait::name, Function.identity()));
|
||||
|
||||
private final Identifier id;
|
||||
private final Identifier sprite;
|
||||
private final TraitGroup group;
|
||||
|
||||
Trait(TraitGroup group) {
|
||||
this.id = new Identifier("unicopia", "spell/trait/" + name().toLowerCase());
|
||||
this.sprite = new Identifier("unicopia", "textures/gui/trait/" + name().toLowerCase() + ".png");
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
@ -50,4 +52,8 @@ public enum Trait {
|
|||
public TraitGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public Identifier getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.jetbrains.annotations.Nullable;
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
@ -66,6 +68,7 @@ public class TraitDiscovery implements NbtSerialisable {
|
|||
return items.getOrDefault(Registry.ITEM.getId(item), SpellTraits.EMPTY);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip) {
|
||||
getKnownTraits(stack.getItem()).appendTooltip(tooltip);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package com.minelittlepony.unicopia.client.gui;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.tooltip.TooltipComponent;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.CharacterVisitor;
|
||||
import net.minecraft.text.OrderedText;
|
||||
|
||||
public class ItemTraitsTooltipRenderer extends BaseText implements OrderedText, TooltipComponent {
|
||||
|
||||
private final SpellTraits traits;
|
||||
|
||||
public ItemTraitsTooltipRenderer(SpellTraits traits) {
|
||||
this.traits = traits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return getRows() * 8 + 2 + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(TextRenderer textRenderer) {
|
||||
return getColumns() * 8 + 2;
|
||||
}
|
||||
|
||||
private int getColumns() {
|
||||
return Math.max(2, (int)Math.ceil(Math.sqrt(traits.entries().size() + 1)));
|
||||
}
|
||||
|
||||
private int getRows() {
|
||||
return (int)Math.ceil((traits.entries().size() + 1) / getColumns());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matrices, ItemRenderer itemRenderer, int z, TextureManager textureManager) {
|
||||
|
||||
int columns = getColumns();
|
||||
|
||||
var entries = traits.stream().toList();
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
int xx = x + (i % columns);
|
||||
int yy = y + (i / columns);
|
||||
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());
|
||||
matrices.push();
|
||||
|
||||
xx += 19 - 2 - textRenderer.getWidth(string);
|
||||
yy += 6 + 3;
|
||||
|
||||
matrices.translate(xx, yy, itemRenderer.zOffset + 200.0F);
|
||||
matrices.scale(0.5F, 0.5F, 1);
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
|
||||
textRenderer.draw(string, 0, 0, 16777215, true, matrices.peek().getModel(), immediate, false, 0, 15728880);
|
||||
immediate.draw();
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(CharacterVisitor visitor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderedText asOrderedText() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseText copy() {
|
||||
return new ItemTraitsTooltipRenderer(traits);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.minelittlepony.unicopia.mixin.client;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.gui.tooltip.TooltipComponent;
|
||||
import net.minecraft.text.OrderedText;
|
||||
|
||||
@Mixin(TooltipComponent.class)
|
||||
interface MixinTooltipComponent {
|
||||
@Inject(method = "of", at = @At("HEAD"), cancellable = true)
|
||||
private static void onOf(OrderedText text, CallbackInfoReturnable<TooltipComponent> info) {
|
||||
if (text instanceof TooltipComponent) {
|
||||
info.setReturnValue((TooltipComponent)text);
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/unicopia/textures/gui/trait/air.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/blood.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/chaos.png
Normal file
After Width: | Height: | Size: 223 B |
After Width: | Height: | Size: 210 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/earth.png
Normal file
After Width: | Height: | Size: 520 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/famine.png
Normal file
After Width: | Height: | Size: 431 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/fire.png
Normal file
After Width: | Height: | Size: 561 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/focus.png
Normal file
After Width: | Height: | Size: 243 B |
After Width: | Height: | Size: 404 B |
After Width: | Height: | Size: 557 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/ice.png
Normal file
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 501 B |
After Width: | Height: | Size: 284 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/life.png
Normal file
After Width: | Height: | Size: 603 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/order.png
Normal file
After Width: | Height: | Size: 226 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/poison.png
Normal file
After Width: | Height: | Size: 338 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/power.png
Normal file
After Width: | Height: | Size: 492 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/rot.png
Normal file
After Width: | Height: | Size: 485 B |
After Width: | Height: | Size: 464 B |
BIN
src/main/resources/assets/unicopia/textures/gui/trait/water.png
Normal file
After Width: | Height: | Size: 333 B |
|
@ -43,6 +43,7 @@
|
|||
"client.MixinKeyboardInput",
|
||||
"client.MixinLightmapTextureManager",
|
||||
"client.MixinMouse",
|
||||
"client.MixinTooltipComponent",
|
||||
"client.MixinWorldRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
|
|