Search in sources :

Example 11 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Minestuck by mraof.

the class ItemCaptchaCard method addInformation.

@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    if (stack.hasTagCompound()) {
        NBTTagCompound nbttagcompound = stack.getTagCompound();
        NBTTagString contentID = (NBTTagString) nbttagcompound.getTag("contentID");
        NBTTagInt contentMeta = (NBTTagInt) nbttagcompound.getTag("contentMeta");
        if (contentID != null && contentMeta != null && Item.REGISTRY.containsKey(new ResourceLocation(contentID.getString()))) {
            String stackSize = nbttagcompound.getBoolean("punched") ? "" : nbttagcompound.getInteger("contentSize") + "x";
            tooltip.add("(" + stackSize + (AlchemyRecipeHandler.getDecodedItem(stack)).getDisplayName() + ")");
            if (nbttagcompound.getBoolean("punched"))
                tooltip.add("(" + I18n.translateToLocal("item.captchaCard.punched") + ")");
            return;
        } else {
            tooltip.add("(" + I18n.translateToLocal("item.captchaCard.invalid") + ")");
        }
    } else {
        tooltip.add("(" + I18n.translateToLocal("item.captchaCard.empty") + ")");
    }
}
Also used : NBTTagInt(net.minecraft.nbt.NBTTagInt) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 12 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Waystones by blay09.

the class NameGenerator method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    NBTTagList tagList = new NBTTagList();
    for (String entry : usedNames) {
        tagList.appendTag(new NBTTagString(entry));
    }
    compound.setTag(TAG_LIST_NAME, tagList);
    return compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 13 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BetterQuesting by Funwayguy.

the class ScrollingJsonEntry method setupEntry.

public void setupEntry(int px, int width) {
    btnList.clear();
    int margin = px + (width / 3);
    int ctrlSpace = MathHelper.ceil((width / 3F) * 2F);
    int n = 0;
    if (allowEdit && je != null) {
        n = 20;
        btnDel = new GuiButtonThemed(3, px + width - n, 0, 20, 20, "x");
        btnDel.packedFGColour = Color.RED.getRGB();
        btnList.add(btnDel);
    }
    if (allowEdit) {
        n = 40;
        btnAdd = new GuiButtonThemed(2, px + width - n, 0, 20, 20, "+");
        btnAdd.packedFGColour = Color.GREEN.getRGB();
        btnList.add(btnAdd);
    }
    if (je == null) {
        return;
    } else if (je.getId() == 9) {
        btnMain = new GuiButtonJson<NBTTagList>(0, margin, 0, ctrlSpace - n, 20, (NBTTagList) je, false);
        btnList.add(btnMain);
    } else if (je.getId() == 10) {
        NBTTagCompound jo = (NBTTagCompound) je;
        if (JsonHelper.isItem(jo) || JsonHelper.isFluid(jo) || JsonHelper.isEntity(jo)) {
            n += 20;
            btnAdv = new GuiButtonThemed(1, px + width - n, 0, 20, 20, "...");
            btnList.add(btnAdv);
        }
        btnMain = new GuiButtonJson<NBTTagCompound>(0, margin, 0, ctrlSpace - n, 20, jo, false);
        btnList.add(btnMain);
    } else if (je instanceof NBTPrimitive) {
        NBTPrimitive jp = (NBTPrimitive) je;
        /*if(jp.isBoolean())
			{
				btnMain = new GuiButtonJson<JsonPrimitive>(0, margin, 0, ctrlSpace - n, 20, jp, false);
				btnList.add(btnMain);
			} else if(jp.isNumber())*/
        {
            GuiNumberField num = new GuiNumberField(mc.fontRenderer, margin + 1, 0, ctrlSpace - n - 2, 18);
            num.setMaxStringLength(Integer.MAX_VALUE);
            num.setText("" + jp.getDouble());
            txtMain = num;
        }
    // else
    } else if (je.getId() == 8) {
        NBTTagString jp = (NBTTagString) je;
        GuiBigTextField txt = new GuiBigTextField(mc.fontRenderer, margin + 1, 1, ctrlSpace - n - 2, 18);
        txt.setMaxStringLength(Integer.MAX_VALUE);
        txt.setText(jp.getString());
        if (json.getId() == 10) {
            txt.enableBigEdit(new TextCallbackJsonObject((NBTTagCompound) json, key));
        } else if (json.getId() == 9) {
            txt.enableBigEdit(new TextCallbackJsonArray((NBTTagList) json, idx));
        }
        txtMain = txt;
    }
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTPrimitive) GuiButtonJson(betterquesting.api.client.gui.controls.GuiButtonJson) TextCallbackJsonArray(betterquesting.client.gui.editors.json.TextCallbackJsonArray) GuiNumberField(betterquesting.api.client.gui.controls.GuiNumberField) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GuiBigTextField(betterquesting.api.client.gui.controls.GuiBigTextField) GuiButtonThemed(betterquesting.api.client.gui.controls.GuiButtonThemed) NBTTagString(net.minecraft.nbt.NBTTagString) TextCallbackJsonObject(betterquesting.client.gui.editors.json.TextCallbackJsonObject)

Example 14 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BetterQuesting by Funwayguy.

the class NBTConverter method JSONtoNBT_Element.

/**
 * Tries to interpret the tagID from the JsonElement's contents
 */
private static NBTBase JSONtoNBT_Element(JsonElement jObj, byte id, boolean format) {
    if (jObj == null) {
        return new NBTTagString();
    }
    byte tagID = id <= 0 ? fallbackTagID(jObj) : id;
    try {
        if (tagID >= 1 && tagID <= 6) {
            return instanceNumber(jObj.getAsNumber(), tagID);
        } else if (tagID == 8) {
            return new NBTTagString(jObj.getAsString());
        } else if (tagID == 10) {
            return JSONtoNBT_Object(jObj.getAsJsonObject(), new NBTTagCompound(), format);
        } else if (// Byte array
        tagID == 7) {
            JsonArray jAry = jObj.getAsJsonArray();
            byte[] bAry = new byte[jAry.size()];
            for (int i = 0; i < jAry.size(); i++) {
                bAry[i] = jAry.get(i).getAsByte();
            }
            return new NBTTagByteArray(bAry);
        } else if (tagID == 11) {
            JsonArray jAry = jObj.getAsJsonArray();
            int[] iAry = new int[jAry.size()];
            for (int i = 0; i < jAry.size(); i++) {
                iAry[i] = jAry.get(i).getAsInt();
            }
            return new NBTTagIntArray(iAry);
        } else if (tagID == 9) {
            NBTTagList tList = new NBTTagList();
            if (jObj.isJsonArray()) {
                JsonArray jAry = jObj.getAsJsonArray();
                for (int i = 0; i < jAry.size(); i++) {
                    JsonElement jElm = jAry.get(i);
                    tList.appendTag(JSONtoNBT_Element(jElm, (byte) 0, format));
                }
            } else if (jObj.isJsonObject()) {
                JsonObject jAry = jObj.getAsJsonObject();
                for (Entry<String, JsonElement> entry : jAry.entrySet()) {
                    try {
                        String[] s = entry.getKey().split(":");
                        byte id2 = Byte.parseByte(s[s.length - 1]);
                        // String key = entry.getKey().substring(0, entry.getKey().lastIndexOf(":" + id));
                        tList.appendTag(JSONtoNBT_Element(entry.getValue(), id2, format));
                    } catch (Exception e) {
                        tList.appendTag(JSONtoNBT_Element(entry.getValue(), (byte) 0, format));
                        continue;
                    }
                }
            }
            return tList;
        }
    } catch (Exception e) {
        QuestingAPI.getLogger().log(Level.ERROR, "An error occured while parsing JsonElement to NBTBase (" + tagID + "):", e);
    }
    QuestingAPI.getLogger().log(Level.WARN, "Unknown NBT representation for " + jObj.toString() + " (ID: " + tagID + ")");
    return new NBTTagString();
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) JsonArray(com.google.gson.JsonArray) NBTTagList(net.minecraft.nbt.NBTTagList) JsonElement(com.google.gson.JsonElement) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray)

Example 15 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project RFTools by McJty.

the class EnvironmentalControllerTileEntity method writeRestorableToNBT.

@Override
public void writeRestorableToNBT(NBTTagCompound tagCompound) {
    super.writeRestorableToNBT(tagCompound);
    writeBufferToNBT(tagCompound, inventoryHelper);
    tagCompound.setInteger("radius", radius);
    tagCompound.setInteger("miny", miny);
    tagCompound.setInteger("maxy", maxy);
    tagCompound.setInteger("mode", mode.ordinal());
    NBTTagList playerTagList = new NBTTagList();
    for (String player : players) {
        playerTagList.appendTag(new NBTTagString(player));
    }
    tagCompound.setTag("players", playerTagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

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