Search in sources :

Example 1 with NBTBase

use of net.minecraft.nbt.NBTBase in project LogisticsPipes by RS485.

the class LogisticsSecurityTileEntity method handleListPacket.

public void handleListPacket(NBTTagCompound tag) {
    excludedCC.clear();
    NBTTagList list = tag.getTagList("list", 3);
    while (list.tagCount() > 0) {
        NBTBase base = list.removeTag(0);
        excludedCC.add(((NBTTagInt) base).func_150287_d());
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase)

Example 2 with NBTBase

use of net.minecraft.nbt.NBTBase in project PneumaticCraft by MineMaarten.

the class NBTToJsonConverter method getObject.

private JsonObject getObject(NBTTagCompound tag) {
    Set<String> keys = tag.func_150296_c();
    JsonObject jsonRoot = new JsonObject();
    for (String key : keys) {
        JsonObject keyObject = new JsonObject();
        jsonRoot.add(key, keyObject);
        NBTBase nbt = tag.getTag(key);
        keyObject.addProperty("type", nbt.getId());
        if (nbt instanceof NBTTagCompound) {
            keyObject.add("value", getObject((NBTTagCompound) nbt));
        } else if (nbt instanceof NBTPrimitive) {
            keyObject.addProperty("value", ((NBTPrimitive) nbt).func_150286_g());
        } else if (nbt instanceof NBTTagString) {
            keyObject.addProperty("value", ((NBTTagString) nbt).func_150285_a_());
        } else if (nbt instanceof NBTTagList) {
            JsonArray array = new JsonArray();
            NBTTagList tagList = (NBTTagList) nbt;
            for (int i = 0; i < tagList.tagCount(); i++) {
                array.add(getObject(tagList.getCompoundTagAt(i)));
            }
            keyObject.add("value", array);
        } else if (nbt instanceof NBTTagIntArray) {
            JsonArray array = new JsonArray();
            NBTTagIntArray intArray = (NBTTagIntArray) nbt;
            for (int i : intArray.func_150302_c()) {
                array.add(new JsonPrimitive(i));
            }
            keyObject.add("value", array);
        } else {
            throw new IllegalArgumentException("NBT to JSON converter doesn't support the nbt tag: " + NBTBase.NBTTypes[nbt.getId()] + ", tag: " + nbt);
        }
    }
    return jsonRoot;
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTBase.NBTPrimitive) JsonPrimitive(com.google.gson.JsonPrimitive) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) JsonArray(com.google.gson.JsonArray) NBTBase(net.minecraft.nbt.NBTBase) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 3 with NBTBase

use of net.minecraft.nbt.NBTBase in project MinecraftForge by MinecraftForge.

the class GameRegistry method makeItemStack.

/**
     * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
     * <p/>
     * Will return null if the item doesn't exist (because it's not from a loaded mod for example)
     * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
     *
     * @param itemName  a registry name reference
     * @param meta      the meta
     * @param stackSize the stack size
     * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
     * @return a new itemstack
     */
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) {
    if (itemName == null) {
        throw new IllegalArgumentException("The itemName cannot be null");
    }
    Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
    if (item == null) {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return ItemStack.EMPTY;
    }
    ItemStack is = new ItemStack(item, stackSize, meta);
    if (!Strings.isNullOrEmpty(nbtString)) {
        NBTBase nbttag = null;
        try {
            nbttag = JsonToNBT.getTagFromJson(nbtString);
        } catch (NBTException e) {
            FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
            throw Throwables.propagate(e);
        }
        if (!(nbttag instanceof NBTTagCompound)) {
            FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
            throw new RuntimeException("Invalid NBT JSON");
        } else {
            is.setTagCompound((NBTTagCompound) nbttag);
        }
    }
    return is;
}
Also used : Item(net.minecraft.item.Item) NBTBase(net.minecraft.nbt.NBTBase) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) NBTException(net.minecraft.nbt.NBTException) Nonnull(javax.annotation.Nonnull)

Example 4 with NBTBase

use of net.minecraft.nbt.NBTBase in project RFToolsDimensions by McJty.

the class NBTMatchingRecipe method checkMatch.

/**
     * Checks if the region of a crafting inventory is match for the recipe.
     */
private boolean checkMatch(InventoryCrafting inventoryCrafting, int x, int y, boolean reversed) {
    for (int col = 0; col < 3; ++col) {
        for (int row = 0; row < 3; ++row) {
            int i1 = col - x;
            int j1 = row - y;
            ItemStack itemstack = ItemStackTools.getEmptyStack();
            String[] nbt = null;
            if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) {
                int idx;
                if (reversed) {
                    idx = this.recipeWidth - i1 - 1 + j1 * this.recipeWidth;
                } else {
                    idx = i1 + j1 * this.recipeWidth;
                }
                itemstack = this.recipeItems[idx];
                nbt = this.matchingNBTs[idx];
            }
            ItemStack itemstack1 = inventoryCrafting.getStackInRowAndColumn(col, row);
            if (ItemStackTools.isValid(itemstack1) || ItemStackTools.isValid(itemstack)) {
                if (ItemStackTools.isEmpty(itemstack1) || ItemStackTools.isEmpty(itemstack)) {
                    return false;
                }
                if (itemstack.getItem() != itemstack1.getItem()) {
                    return false;
                }
                if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage()) {
                    return false;
                }
                NBTTagCompound compound = itemstack.getTagCompound();
                NBTTagCompound compound1 = itemstack1.getTagCompound();
                if (nbt != null) {
                    if (compound == null && compound1 != null) {
                        return false;
                    }
                    if (compound != null && compound1 == null) {
                        return false;
                    }
                    if (compound != null) {
                        for (String tagName : nbt) {
                            NBTBase tag = compound.getTag(tagName);
                            NBTBase tag1 = compound1.getTag(tagName);
                            if (tag == null && tag1 != null) {
                                return false;
                            }
                            if (tag != null && tag1 == null) {
                                return false;
                            }
                            if (tag != null) {
                                if (!tag.equals(tag1)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 5 with NBTBase

use of net.minecraft.nbt.NBTBase in project ImmersiveEngineering by BluSunrize.

the class CapabilityShader method register.

public static void register() {
    CapabilityManager.INSTANCE.register(ShaderWrapper.class, new Capability.IStorage<ShaderWrapper>() {

        @Override
        public NBTBase writeNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side) {
            NBTTagCompound nbt = new NBTTagCompound();
            ItemStack shader = instance.getShaderItem();
            if (shader != null)
                shader.writeToNBT(nbt);
            else
                nbt.setString("IE:NoShader", "");
            nbt.setString("IE:ShaderType", instance.getShaderType());
            return nbt;
        }

        @Override
        public void readNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side, NBTBase nbt) {
            NBTTagCompound tags = (NBTTagCompound) nbt;
            instance.setShaderType(tags.getString("IE:ShaderType"));
            if (!tags.hasKey("IE:NoShader"))
                instance.setShaderItem(ItemStack.loadItemStackFromNBT(tags));
        }
    }, new Callable<ShaderWrapper>() {

        @Override
        public ShaderWrapper call() throws Exception {
            return new ShaderWrapper_Direct("");
        }
    });
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) NBTBase(net.minecraft.nbt.NBTBase) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Aggregations

NBTBase (net.minecraft.nbt.NBTBase)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)15 NBTTagList (net.minecraft.nbt.NBTTagList)8 ItemStack (net.minecraft.item.ItemStack)6 NBTTagString (net.minecraft.nbt.NBTTagString)5 List (java.util.List)4 Map (java.util.Map)3 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Nonnull (javax.annotation.Nonnull)2 NBTTagByte (net.minecraft.nbt.NBTTagByte)2 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)2 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)2 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)2 NBTTagInt (net.minecraft.nbt.NBTTagInt)2 NBTTagLong (net.minecraft.nbt.NBTTagLong)2 NBTTagShort (net.minecraft.nbt.NBTTagShort)2 VisualEffectProvider (com.builtbroken.mc.client.effects.VisualEffectProvider)1