Java Code Examples for net.minecraft.nbt.JsonToNBT#getTagFromJson()
The following examples show how to use
net.minecraft.nbt.JsonToNBT#getTagFromJson() .
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: OreDictUtil.java From AgriCraft with MIT License | 6 votes |
@Nonnull private static Optional<ItemStack> addNbtData(@Nonnull ItemStack stack, @Nullable String tags) { // Step 0. Validate. Preconditions.checkNotNull(stack, "The itemstack to add NBT data to may not be null"); // Step 1. Abort if tags are null. if (Strings.isNullOrEmpty(tags)) { return Optional.of(stack); } // Step 2. Get the tag instance. final NBTTagCompound tag = StackHelper.getTag(stack); // Step 3. Parse the tags. try { final NBTTagCompound added = JsonToNBT.getTagFromJson(tags); tag.merge(added); stack.setTagCompound(tag); return Optional.of(stack); } catch (NBTException e) { AgriCore.getLogger("agricraft").error("Unable to parse NBT Data: \"{0}\".\nCause: {1}", tags, e); return Optional.empty(); } }
Example 2
Source File: WeightedRandomLoot.java From minecraft-roguelike with GNU General Public License v3.0 | 6 votes |
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()); }
Example 3
Source File: NBTTagCompoundDeserializer.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@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 4
Source File: SpawnPotential.java From minecraft-roguelike with GNU General Public License v3.0 | 5 votes |
public SpawnPotential(JsonObject entry) throws Exception{ this.weight = entry.has("weight") ? entry.get("weight").getAsInt() : 1; if(!entry.has("name")){ throw new Exception("Spawn potential missing name"); } this.name = entry.get("name").getAsString(); this.equip = entry.has("equip") ? entry.get("equip").getAsBoolean() : false; if(entry.has("nbt")){ String metadata = entry.get("nbt").getAsString(); this.nbt = JsonToNBT.getTagFromJson(metadata); } }