Search in sources :

Example 6 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project SecurityCraft by Geforce132.

the class ItemSCManual method onUpdate.

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
    if (par1ItemStack.getTagCompound() == null) {
        NBTTagList bookPages = new NBTTagList();
        par1ItemStack.setTagInfo("pages", bookPages);
        par1ItemStack.setTagInfo("author", new NBTTagString("Geforce"));
        par1ItemStack.setTagInfo("title", new NBTTagString("SecurityCraft"));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 7 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project SpongeCommon by SpongePowered.

the class NbtTranslator method setInternal.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void setInternal(NBTBase base, byte type, DataView view, String key) {
    checkNotNull(base);
    checkNotNull(view);
    checkNotNull(key);
    checkArgument(!key.isEmpty());
    checkArgument(type > NbtDataUtil.TAG_END && type <= NbtDataUtil.TAG_INT_ARRAY);
    switch(type) {
        case NbtDataUtil.TAG_BYTE:
            if (key.contains(BOOLEAN_IDENTIFER)) {
                view.set(of(key.replace(BOOLEAN_IDENTIFER, "")), (((NBTTagByte) base).getByte() != 0));
            } else {
                view.set(of(key), ((NBTTagByte) base).getByte());
            }
            break;
        case NbtDataUtil.TAG_SHORT:
            view.set(of(key), ((NBTTagShort) base).getShort());
            break;
        case NbtDataUtil.TAG_INT:
            view.set(of(key), ((NBTTagInt) base).getInt());
            break;
        case NbtDataUtil.TAG_LONG:
            view.set(of(key), ((NBTTagLong) base).getLong());
            break;
        case NbtDataUtil.TAG_FLOAT:
            view.set(of(key), ((NBTTagFloat) base).getFloat());
            break;
        case NbtDataUtil.TAG_DOUBLE:
            view.set(of(key), ((NBTTagDouble) base).getDouble());
            break;
        case NbtDataUtil.TAG_BYTE_ARRAY:
            view.set(of(key), ((NBTTagByteArray) base).getByteArray());
            break;
        case NbtDataUtil.TAG_STRING:
            view.set(of(key), ((NBTTagString) base).getString());
            break;
        case NbtDataUtil.TAG_LIST:
            NBTTagList list = (NBTTagList) base;
            byte listType = (byte) list.getTagType();
            int count = list.tagCount();
            List objectList = Lists.newArrayListWithCapacity(count);
            for (int i = 0; i < count; i++) {
                objectList.add(fromTagBase(list.get(i), listType));
            }
            view.set(of(key), objectList);
            break;
        case NbtDataUtil.TAG_COMPOUND:
            DataView internalView = view.createView(of(key));
            NBTTagCompound compound = (NBTTagCompound) base;
            for (String internalKey : compound.getKeySet()) {
                NBTBase internalBase = compound.getTag(internalKey);
                byte internalType = internalBase.getId();
                // Basically.... more recursion.
                // Reasoning: This avoids creating a new DataContainer which would
                // then be copied in to the owning DataView anyways. We can internally
                // set the actual data directly to the child view instead.
                setInternal(internalBase, internalType, internalView, internalKey);
            }
            break;
        case NbtDataUtil.TAG_INT_ARRAY:
            view.set(of(key), ((NBTTagIntArray) base).getIntArray());
            break;
        default:
            throw new IllegalArgumentException("Unknown NBT type " + type);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DataView(org.spongepowered.api.data.DataView) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 8 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Charset by CharsetMC.

the class ProjectorHandlerBook method render.

@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
    // oh boy! text!
    if (stack.hasTagCompound()) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(((surface.getCornerStart().x + surface.getCornerEnd().x) / 2) + surface.getScreenFacing().getFrontOffsetX() * 0.001f, ((surface.getCornerStart().y + surface.getCornerEnd().y) / 2) + surface.getScreenFacing().getFrontOffsetY() * 0.001f, ((surface.getCornerStart().z + surface.getCornerEnd().z) / 2) + surface.getScreenFacing().getFrontOffsetZ() * 0.001f);
        Orientation orientation = ProjectorHelper.INSTANCE.getOrientation(surface);
        Quaternion.fromOrientation(orientation).glRotate();
        GlStateManager.rotate(270.0f, 0, 0, 1);
        GlStateManager.rotate(270.0f, 0, 1, 0);
        GlStateManager.translate(0, 0, -ProjectorHelper.OFFSET);
        float scaleVal = 2f * surface.getWidth() / 146f;
        GlStateManager.scale(scaleVal, scaleVal, scaleVal);
        FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
        NBTTagList pages = stack.getTagCompound().getTagList("pages", Constants.NBT.TAG_STRING);
        if (pages.tagCount() > projector.getPage()) {
            String pageCount = I18n.format("book.pageIndicator", projector.getPage() + 1, pages.tagCount());
            renderer.drawString(pageCount, -73 + 129 - renderer.getStringWidth(pageCount), -90 + 15, 0xFF000000);
            String page = ((NBTTagString) pages.get(projector.getPage())).getString();
            ITextComponent fullComponent = ITextComponent.Serializer.jsonToComponent(page);
            if (fullComponent != null) {
                List<ITextComponent> components = GuiUtilRenderComponents.splitText(fullComponent, 116, renderer, true, true);
                for (int i = 0; i < components.size(); i++) {
                    renderer.drawString(components.get(i).getUnformattedText(), -73 + 16, -90 + 30 + i * renderer.FONT_HEIGHT, 0xFF000000);
                }
            }
        }
        GlStateManager.popMatrix();
        surface.restoreGLColor();
    }
    Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/book.png"));
    ProjectorHelper.INSTANCE.renderTexture(surface, 20, 20 + 146, 1, 1 + 180);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) NBTTagString(net.minecraft.nbt.NBTTagString) FontRenderer(net.minecraft.client.gui.FontRenderer) NBTTagString(net.minecraft.nbt.NBTTagString) Orientation(pl.asie.charset.lib.utils.Orientation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 9 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Charset by CharsetMC.

the class TileEntityDayBarrel method makeBarrel.

public static ItemStack makeBarrel(Set<BarrelUpgrade> upgrades, ItemMaterial log, ItemMaterial slab) {
    ItemStack stack = new ItemStack(CharsetStorageBarrels.barrelItem);
    NBTTagCompound compound = ItemUtils.getTagCompound(stack, true);
    compound.setString("log", log.getId());
    compound.setString("slab", slab.getId());
    if (upgrades.size() > 0) {
        NBTTagList list = new NBTTagList();
        for (BarrelUpgrade u : upgrades) list.appendTag(new NBTTagString(u.name()));
        compound.setTag("upgrades", list);
    }
    return stack;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack)

Example 10 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project TechReborn by TechReborn.

the class StackWIPHandler method addHead.

private void addHead(String name) {
    ItemStack head = new ItemStack(Items.SKULL, 1, 3);
    head.setTagCompound(new NBTTagCompound());
    head.getTagCompound().setTag("SkullOwner", new NBTTagString(name));
    devHeads.add(head);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)98 NBTTagList (net.minecraft.nbt.NBTTagList)79 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)16 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTBase (net.minecraft.nbt.NBTBase)9 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 List (java.util.List)6 Map (java.util.Map)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4