Search in sources :

Example 51 with NbtElement

use of net.minecraft.nbt.NbtElement in project Hypnotic-Client by Hypnotic-Development.

the class Nametags method drawInv.

private void drawInv(LivingEntity player, float posX, float posY, EventRenderGUI eventRender2D) {
    int itemWidth = 16;
    int totalCount = getItems(player).size();
    float startX = (posX - ((totalCount * itemWidth) / 2.f));
    posY = (posY - 28);
    count = 0;
    for (ItemStack itemStack : getItems(player)) {
        if (!(itemStack.getItem() instanceof AirBlockItem)) {
            float newX = startX + (count * 16);
            RenderUtils.drawItem(itemStack, newX, posY);
            if (itemStack.hasEnchantments()) {
                float scale = 0.5f;
                MatrixStack matrixStack = eventRender2D.getMatrices();
                matrixStack.push();
                matrixStack.scale(scale, scale, 1);
                int enchCount = 1;
                for (NbtElement tag : itemStack.getEnchantments()) {
                    try {
                        NbtCompound compoundTag = (NbtCompound) tag;
                        float newY = ((posY - ((10 * scale) * enchCount) + 0.5f) / scale);
                        float newerX = (newX / scale);
                        String name = getEnchantName(compoundTag);
                        float nameWidth = font.getStringWidth(name);
                        RenderUtils.fill(eventRender2D.getMatrices(), newerX, newY - 1, newerX + nameWidth, newY + 9, 0x35000000);
                        font.draw(eventRender2D.getMatrices(), name, newerX, newY - 3, -1);
                        enchCount++;
                    } catch (Exception ignored) {
                    }
                }
                matrixStack.pop();
            }
            count++;
        }
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) MatrixStack(net.minecraft.client.util.math.MatrixStack) NbtElement(net.minecraft.nbt.NbtElement) ItemStack(net.minecraft.item.ItemStack) AirBlockItem(net.minecraft.item.AirBlockItem)

Aggregations

NbtElement (net.minecraft.nbt.NbtElement)51 NbtList (net.minecraft.nbt.NbtList)44 NbtCompound (net.minecraft.nbt.NbtCompound)22 Identifier (net.minecraft.util.Identifier)20 ItemStack (net.minecraft.item.ItemStack)6 Field (java.lang.reflect.Field)2 Block (net.minecraft.block.Block)2 Enchantment (net.minecraft.enchantment.Enchantment)2 StatusEffect (net.minecraft.entity.effect.StatusEffect)2 Item (net.minecraft.item.Item)2 SoundEvent (net.minecraft.sound.SoundEvent)2 DyeColor (net.minecraft.util.DyeColor)2 RecipePair (top.theillusivec4.polymorph.api.common.base.RecipePair)2 RecipePairImpl (top.theillusivec4.polymorph.common.impl.RecipePairImpl)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Module (mathax.client.systems.modules.Module)1 Module (meteordevelopment.meteorclient.systems.modules.Module)1