Java Code Examples for net.minecraft.nbt.NBTException#printStackTrace()

The following examples show how to use net.minecraft.nbt.NBTException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NBTTagCompoundDeserializer.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public NBTTagCompound deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
    try
    {
        return JsonToNBT.getTagFromJson(json.getAsString());
    } catch (NBTException e)
    {
        e.printStackTrace();
    }

    throw new JsonParseException("Failed to parse nbt");
}
 
Example 2
Source File: GiveCommand.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void exec(String input) {
    if (!this.clamp(input, 2)) {
        this.printUsage();
        return;
    }

    final Minecraft mc = Minecraft.getMinecraft();

    if (!mc.player.isCreative()) {
        Seppuku.INSTANCE.errorChat("Creative mode is required to use this command.");
        return;
    }

    final String[] split = input.split(" ");

    final Item item = this.findItem(split[1]);

    if(item != null) {
        int amount = 1;
        int meta = 0;

        if(split.length >= 3) {
            if(StringUtil.isInt(split[2])) {
                amount = Integer.parseInt(split[2]);
            }else{
                Seppuku.INSTANCE.errorChat("Unknown number " + "\247f\"" + split[2] + "\"");
            }
        }

        if(split.length >= 4) {
            if(StringUtil.isInt(split[3])) {
                meta = Integer.parseInt(split[3]);
            }else{
                Seppuku.INSTANCE.errorChat("Unknown number " + "\247f\"" + split[3] + "\"");
            }
        }

        final ItemStack itemStack = new ItemStack(item, amount, meta);

        if(split.length >= 5) {
            final String s = this.buildString(split, 4);

            try {
                itemStack.setTagCompound(JsonToNBT.getTagFromJson(s));
            } catch (NBTException e) {
                e.printStackTrace();
            }
        }

        final int slot = this.findEmptyhotbar();
        mc.player.connection.sendPacket(new CPacketCreativeInventoryAction(36 + (slot != -1 ? slot : mc.player.inventory.currentItem), itemStack));
        Seppuku.INSTANCE.logChat("Gave you " + amount + " " + itemStack.getDisplayName());
    }else{
        final ResourceLocation similar = this.findSimilarItem(split[1]);

        if(similar != null) {
            Seppuku.INSTANCE.errorChat("Unknown item " + "\247f\"" + split[1] + "\"");
            Seppuku.INSTANCE.logChat("Did you mean " + "\247c" + similar.getPath() + "\247f?");
        }
    }
}