Java 类net.minecraft.nbt.JsonToNBT 实例源码

项目:InControl    文件:Tools.java   
public static ItemStack parseStack(String name) {
    if (name.contains("/")) {
        String[] split = StringUtils.split(name, "/");
        ItemStack stack = parseStackNoNBT(split[0]);
        if (ItemStackTools.isEmpty(stack)) {
            return stack;
        }
        NBTTagCompound nbt;
        try {
            nbt = JsonToNBT.getTagFromJson(split[1]);
        } catch (NBTException e) {
            InControl.logger.log(Level.ERROR, "Error parsing NBT in '" + name + "'!");
            return ItemStackTools.getEmptyStack();
        }
        stack.setTagCompound(nbt);
        return stack;
    } else {
        return parseStackNoNBT(name);
    }
}
项目:Dailies    文件:BaileyInventory.java   
private void buildReward(Reward reward) {
    Item rewardItem = Item.getItemById(reward.type);
    ItemStack rewardStack = new ItemStack(rewardItem, reward.quantity);

    if (reward.subType > 0) {
        rewardStack.setItemDamage(reward.subType);
    }

    if (reward.nbt != null) {
        try {
            rewardStack.setTagCompound(JsonToNBT.getTagFromJson(reward.nbt));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    setInventorySlotContents(REWARD_OUTPUT_INDEX, rewardStack);
}
项目:metamorph    文件:MobMorphFactory.java   
/**
 * Add an entity morph to the morph list
 */
private void addBlockMorph(MorphList morphs, World world, String json)
{
    try
    {
        BlockMorph morph = new BlockMorph();
        NBTTagCompound tag = JsonToNBT.getTagFromJson(json);

        tag.setString("Name", morph.name);
        morph.fromNBT(tag);

        morphs.addMorphVariant("block", "blocks", morph.block.getBlock().getLocalizedName(), morph);
    }
    catch (Exception e)
    {
        System.out.println("Failed to create a block morph with the data! " + json);
        e.printStackTrace();
    }
}
项目:MC-Prefab    文件:BuildEntity.java   
public NBTTagCompound getEntityDataTag()
{
    NBTTagCompound tag = null;

    if (!this.entityNBTData.equals(""))
    {
        try
        {
            tag = JsonToNBT.getTagFromJson(this.entityNBTData);
        }
        catch (NBTException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return tag;
}
项目:MC-Prefab    文件:BuildBlock.java   
public NBTTagCompound getBlockStateDataTag()
{
    NBTTagCompound tag = null;

    if (!this.blockStateData.equals(""))
    {
        try
        {
            tag = JsonToNBT.getTagFromJson(this.blockStateData);
        }
        catch (NBTException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return tag;
}
项目:MC-Prefab    文件:BuildTileEntity.java   
public NBTTagCompound getEntityDataTag()
{
    NBTTagCompound tag = null;

    if (!this.entityNBTData.equals(""))
    {
        try
        {
            tag = JsonToNBT.getTagFromJson(this.entityNBTData);
        }
        catch (NBTException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return tag;
}
项目:Minecraft-Flux    文件:SpecialEvent.java   
SpecialItem(String n, byte c, short m, @Nullable String t) {
    name = n;
    amount = c;
    meta = m;
    if (t != null) {
        NBTTagCompound nbt;
        try {
            nbt = JsonToNBT.getTagFromJson(t);
        } catch (NBTException e) {
            MCFluxReport.sendException(e, "NBT Decoding");
            nbt = null;
        }
        tag = nbt;
    } else
        tag = null;
    item = Item.getByNameOrId(name);
}
项目:CraftingHarmonics    文件:NbtTagCompoundDeserializer.java   
@Override
public Object Deserialize(Object input) {
    String json = "{}";
    if(input instanceof String) {
        json = input.toString();
    } else if(input instanceof ScriptObjectMirror) {
        json = NashornConfigProcessor.getInstance().nashorn.stringifyJsonObject((JSObject) input);
    }

    try {
        return JsonToNBT.getTagFromJson(json);
    } catch (NBTException e) {
        LogHelper.error("Unable to convert '" + json + "' to NBT tag.", e);
        return new NBTTagCompound();
    }
}
项目:LightningCraft    文件:StackHelper.java   
/** Creates a new ItemStack from the string acquired from makeStringFromItemStack or an oredict name, with an oredict index option */
public static ItemStack makeItemStackFromString(String stackString, int oreIndex) {
    if(stackString == LightningInfusionRecipe.nullIdentifier) return null;
    try { // try to load it as a regular NBT stack
        if(!isStringOreDict(stackString)) {
            return ItemStack.loadItemStackFromNBT(JsonToNBT.getTagFromJson(stackString));
        } else {
            throw new NBTException("OreDict exists");
        }
    } catch(NBTException e) { // now try to get it as an oredict entry
        List<ItemStack> list;
        if(isStringOreDict(stackString) && oreIndex < (list = OreDictionary.getOres(stackString)).size()) {
            return list.get(oreIndex); // yep
        } else {
            return null; // guess not
        }
    }
}
项目:TaleCraft    文件:NPCDialogue.java   
public void handleClickServer(EntityNPC npc){
    if(action.startsWith("action.nbt=")){
        String[] equalsplit = action.split("=");
        String nbt_json = "";
        for(int i = 1; i < equalsplit.length; i++){
            nbt_json += equalsplit[i];
        }
        NBTTagCompound newNBT;
        try {
            newNBT = JsonToNBT.getTagFromJson(nbt_json);
        } catch (NBTException e) {
            e.printStackTrace();
            return;
        }
        npc.getScriptData().merge(newNBT);
    }
}
项目:SettlerCraft    文件:Schematic.java   
public ItemStack getResourceStack() {
    if(stackOverride != null) {
        NBTTagCompound tag;
        try {
            tag = JsonToNBT.getTagFromJson(stackOverride);
        } catch (NBTException e) {
            e.printStackTrace();
            return new ItemStack(getBlock(), 1, stackMeta);
        }
        if(tag != null) {
            ItemStack stack = new ItemStack(tag);
            if(stack != null) {
                return stack;
            }
        }
    }
    return new ItemStack(getBlock(), 1, stackMeta);
}
项目:Yamcl    文件:ItemDescriptor.java   
/**
 * Get an ItemStack instance with given amount of items and NBT Tag pTag is
 * optional, and this function will return an ItemStack without NBT if pTag
 * is empty
 * 
 * @param pAmount
 * @param pTag
 * @return An itemstack with attached NBTTag, or null if the tag was invalid, or the itemdescriptor
 * couldn't be turned into a valid itemstack
 */
public ItemStack getItemStackwNBT( int pAmount, String pTag )
{
  NBTTagCompound tNBT = null;
  boolean tDamagedNBT = false;

  try
  {
    if( !pTag.isEmpty() )
      tNBT = (NBTTagCompound) JsonToNBT.func_150315_a( pTag );
  }
  catch( Exception e )
  {
    _mLog.error( String.format( "Found invalid NBT Tag: %s", pTag ) );
    tDamagedNBT = true;
  }

  if( !tDamagedNBT )
    return getItemStackwNBT( pAmount, tNBT );
  else
    return null;
}
项目:CustomAI    文件:PacketAIEStackUpdate.java   
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{
    try
    {
        byte[] readBytes = new byte[buffer.readableBytes()];
        buffer.readBytes(readBytes);
        ByteArrayInputStream bais = new ByteArrayInputStream(readBytes);
        DataInputStream inputStream = new DataInputStream(bais);

        x = inputStream.readInt();
        y = inputStream.readInt();
        z = inputStream.readInt();

        String str = inputStream.readUTF();
        if(!str.equals("null"))
            stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) JsonToNBT.func_150315_a(str));
        inputStream.close();
        bais.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
项目:CustomOreGen    文件:ValidatorBlockDescriptor.java   
protected boolean validateChildren() throws ParserException
 {
     super.validateChildren();
     this.blocks = this.validateRequiredAttribute(String.class, "Block", true);
     this.weight = this.validateNamedAttribute(Float.class, "Weight", this.weight, true);
     String nbtJson = this.validateNamedAttribute(String.class, "NBT", null, true);
     if (nbtJson != null) {
        try {
            NBTBase base = JsonToNBT.getTagFromJson(nbtJson);
            if (base instanceof NBTTagCompound) {
                this.nbt = (NBTTagCompound)base;
            } else {
                throw new ParserException("NBT is not a compound tag");
            }
} catch (NBTException e) {
    throw new ParserException("Failed to parse JSON", e);
}
     }
     return true;
 }
项目:minecraft-roguelike    文件:WeightedRandomLoot.java   
public WeightedRandomLoot(JsonObject json, int weight) throws Exception{

    this.name = json.get("name").getAsString();
    ResourceLocation location = new ResourceLocation(name);
    this.item = (Item) Item.REGISTRY.getObject(location);
    try{
        this.item.getUnlocalizedName();
    } catch (NullPointerException e){
        throw new Exception("Invalid item: " + this.name);
    }
    this.damage = json.has("meta") ? json.get("meta").getAsInt() : 0;
    this.weight = weight;
    this.enchLevel = json.has("ench") ? json.get("ench").getAsInt() : 0;

    if(json.has("min") && json.has("max")){
        min = json.get("min").getAsInt();
        max = json.get("max").getAsInt();   
    } else {
        min = 1;
        max = 1;
    }

    if(json.has("nbt")) this.nbt = JsonToNBT.getTagFromJson(json.get("nbt").getAsString());

}
项目:harshencastle    文件:EntitySoullessKnight.java   
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
    setItemStackToSlot(this.isLeftHanded() ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND, new ItemStack(HarshenItems.PROPS, 1, 0));
    try {
        setItemStackToSlot(this.isLeftHanded() ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, new ItemStack(JsonToNBT.getTagFromJson("{id:\"minecraft:shield\",Count:1b,tag:{BlockEntityTag:{Patterns:[{Pattern:\"ss\",Color:6},{Pattern:\"flo\",Color:1}],Base:8}},Damage:0s}")));
    } catch (NBTException e) {
        e.printStackTrace();
    }
       this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, 1));
       this.setLeftHanded(false);
    return livingdata;
}
项目:DecompiledMinecraft    文件:CommandTestFor.java   
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound1);

            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:DecompiledMinecraft    文件:CommandTestFor.java   
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound1);

            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:BaseClient    文件:CommandTestFor.java   
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound1);

            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:BaseClient    文件:CommandTestFor.java   
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound1);

            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:customstuff4    文件:NBTTagCompoundDeserializer.java   
@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");
}
项目:Backmemed    文件:SetNBT.java   
public SetNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
    try
    {
        NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(JsonUtils.getString(object, "tag"));
        return new SetNBT(conditionsIn, nbttagcompound);
    }
    catch (NBTException nbtexception)
    {
        throw new JsonSyntaxException(nbtexception);
    }
}
项目:Backmemed    文件:CommandTestFor.java   
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = entityToNBT(entity);

            if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:CustomWorldGen    文件:GameRegistry.java   
/**
 * 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
 */
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 null;
    }
    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;
}
项目:CustomWorldGen    文件:SetNBT.java   
public SetNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
    try
    {
        NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(JsonUtils.getString(object, "tag"));
        return new SetNBT(conditionsIn, nbttagcompound);
    }
    catch (NBTException nbtexception)
    {
        throw new JsonSyntaxException(nbtexception);
    }
}
项目:CustomWorldGen    文件:CommandTestFor.java   
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = entityToNBT(entity);

            if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
项目:FerretShinies    文件:BlindBag.java   
private void addNBTToStack(final String nbtString, final ItemStack stack, final EntityPlayer player) {
    NBTBase base;
    try {
        base = JsonToNBT.func_150315_a(nbtString);
        if (base instanceof NBTTagCompound) {
            stack.setTagCompound((NBTTagCompound) base);
        } else {
            player.addChatMessage(new ChatComponentText("Error:  Invalid NBT type provided in JSON."));
        }
    } catch (final NBTException e) {
        player.addChatMessage(new ChatComponentText("Error:  Invalid NBT JSON data: " + e.getMessage()));
    }
}
项目:TRHS_Club_Mod_2016    文件:GameRegistry.java   
/**
 * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
 *
 * 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
 */
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().func_82594_a(itemName);
    if (item == null) {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return null;
    }
    ItemStack is = new ItemStack(item,1,meta);
    if (!Strings.isNullOrEmpty(nbtString)) {
        NBTBase nbttag = null;
        try
        {
            nbttag = JsonToNBT.func_150315_a(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.func_77982_d((NBTTagCompound) nbttag);
        }
    }
    return is;
}
项目:metamorph    文件:GuiNBTMorphBuilder.java   
/**
 * Construct the morph 
 */
private void updateMorph()
{
    try
    {
        NBTTagCompound tag = new NBTTagCompound();
        String nbt = this.nbt.getText();

        if (!nbt.isEmpty())
        {
            if (!(nbt.startsWith("{") && nbt.endsWith("}")))
            {
                nbt = "{" + nbt + "}";
            }

            tag.merge(JsonToNBT.getTagFromJson(nbt));
        }

        tag.setString("Name", this.name.getText());

        this.cached = MorphManager.INSTANCE.morphFromNBT(tag);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
项目:TombManyGraves    文件:DeathInventory.java   
public boolean getDeathList(EntityPlayer player, String playerName, String timestamp)
    {
        boolean didWork = true;

        String filename = TombManyGraves.file + DeathInventoryHandler.FILE_PREFIX + "/" + playerName + "#" + timestamp + ".json";

        BufferedReader reader;

        try
        {
            reader = new BufferedReader(new FileReader(filename));
            String fileData = reader.readLine();
            allNBT = JsonToNBT.getTagFromJson(fileData);
            if (allNBT.getKeySet().size() > 0) {
                ItemStack theList = new ItemStack(ModItems.itemDeathList, 1);
                theList.setTagCompound(allNBT);
                EntityItem entityItem = new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, theList);
                player.worldObj.spawnEntityInWorld(entityItem);
            }
            else
            {
                ChatHelper.sayMessage(player.worldObj, player, playerName + " had no items upon death!");
            }
            reader.close();
        }
        catch (Exception e)
        {
//            e.printStackTrace();
            didWork = false;
        }

        return didWork;
    }
项目:TombManyGraves-NOT-FOR-1.9.4-    文件:DeathInventory.java   
public boolean dropAll(EntityPlayer player, String timestamp)
    {
        boolean didWork = true;

        String filename = TombManyGraves.file + DeathInventoryHandler.FILE_PREFIX + "/" + player.getName() + "#" + timestamp + ".json";

        BufferedReader reader;

        try
        {
            reader = new BufferedReader(new FileReader(filename));
            String fileData = reader.readLine();
            allNBT = JsonToNBT.getTagFromJson(fileData);
            InventoryPlayer inventoryPlayer = new InventoryPlayer(player);
            inventoryPlayer.readFromNBT(allNBT.getTagList("Main",10));
            InventoryHelper.dropInventoryItems(player.worldObj, player.getPosition(), inventoryPlayer);

            if (TombManyGraves.isBaublesInstalled)
            {
                InventoryBaubles inventoryBaubles = new InventoryBaubles(player);
                inventoryBaubles.readNBT(allNBT.getCompoundTag("Baubles"));
                InventoryHelper.dropInventoryItems(player.worldObj, player.getPosition(), inventoryBaubles);
            }
        }
        catch (Exception e)
        {
//            e.printStackTrace();
            didWork = false;
        }

        return didWork;
    }
项目:TombManyGraves-NOT-FOR-1.9.4-    文件:DeathInventory.java   
public boolean restoreAll(EntityPlayer player, String timestamp)
    {
        boolean didWork = true;

        String filename = TombManyGraves.file + DeathInventoryHandler.FILE_PREFIX + "/" + player.getName() + "#" + timestamp + ".json";

        BufferedReader reader;

        try
        {
            reader = new BufferedReader(new FileReader(filename));
            String fileData = reader.readLine();
            allNBT = JsonToNBT.getTagFromJson(fileData);
            player.inventory.readFromNBT(allNBT.getTagList("Main",10));

            if (TombManyGraves.isBaublesInstalled)
            {
                InventoryBaubles inventoryBaubles = new InventoryBaubles(player);
                inventoryBaubles.readNBT(allNBT.getCompoundTag("Baubles"));
                PlayerHandler.setPlayerBaubles(player,inventoryBaubles);
            }
        }
        catch (Exception e)
        {
//            e.printStackTrace();
            didWork = false;
        }

        return didWork;
    }
项目:blockbuster    文件:SubCommandRecordAdd.java   
@Override
public void executeCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    String filename = args[0];
    int tick = CommandBase.parseInt(args[1], 0);
    Record record = CommandRecord.getRecord(filename);

    if (tick < 0 || tick >= record.actions.size())
    {
        throw new CommandException("record.tick_out_range", tick);
    }

    if (!Action.TYPES.containsKey(args[2]))
    {
        throw new CommandException("record.wrong_action", args[2]);
    }

    try
    {
        Action action = Action.fromType(Action.TYPES.get(args[2]).byteValue());

        if (args.length > 3)
        {
            action.fromNBT(JsonToNBT.getTagFromJson(CommandMorph.mergeArgs(args, 3)));
        }

        record.addAction(tick, action);
        record.dirty = true;
    }
    catch (Exception e)
    {
        throw new CommandException("record.add", args[2], e.getMessage());
    }
}
项目:Toms-Mod    文件:Config.java   
private static UUID readUUID(String uuid) throws NBTException, NoSuchFieldException {
    NBTTagCompound readTag = JsonToNBT.getTagFromJson(uuid);
    if (readTag.hasUniqueId("uuid")) {
        return readTag.getUniqueId("uuid");
    } else {
        throw new NoSuchFieldException("Missing field in the Json: uuid");
    }
}
项目:TeslaEssentials    文件:TileGrinder.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}
项目:TeslaEssentials    文件:TileElectricFurnace.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}
项目:TeslaEssentials    文件:TileCharger.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}
项目:TeslaEssentials    文件:TileCapacitor.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}
项目:TeslaEssentials    文件:TileSolarPanel.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}
项目:TeslaEssentials    文件:TileFurnaceGenerator.java   
@Override
public void update(String s) {
    try {
        deserializeNBT(JsonToNBT.getTagFromJson(s));
    } catch (NBTException e) {
        e.printStackTrace();
    }
}