Java Code Examples for net.minecraft.nbt.StringNbtReader#parse()
The following examples show how to use
net.minecraft.nbt.StringNbtReader#parse() .
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: ModifyCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void add(ItemStack stack, String[] args) throws CmdError { String nbt = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); nbt = nbt.replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); if(!stack.hasTag()) stack.setTag(new CompoundTag()); try { CompoundTag tag = StringNbtReader.parse(nbt); stack.getTag().copyFrom(tag); }catch(CommandSyntaxException e) { ChatUtils.message(e.getMessage()); throw new CmdError("NBT data is invalid."); } }
Example 2
Source File: ModifyCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void set(ItemStack stack, String[] args) throws CmdError { String nbt = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); nbt = nbt.replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); try { CompoundTag tag = StringNbtReader.parse(nbt); stack.setTag(tag); }catch(CommandSyntaxException e) { ChatUtils.message(e.getMessage()); throw new CmdError("NBT data is invalid."); } }
Example 3
Source File: CmdSkull.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Override public void onCommand(String command, String[] args) throws Exception { ItemStack item = new ItemStack(Items.PLAYER_HEAD, 64); if (args.length < 2) { item.setTag(StringNbtReader.parse("{SkullOwner:{Name:\"" + args[0] + "\"}}")); } else if (args[0].equalsIgnoreCase("img")) { CompoundTag tag = StringNbtReader.parse("{SkullOwner:{Id:\"" + UUID.randomUUID() + "\",Properties:{textures:[{Value:\"" + Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"" + args[1] + "\"}}}").getBytes()) + "\"}]}}}"); item.setTag(tag); System.out.println(tag); } mc.player.inventory.addPickBlock(item); }
Example 4
Source File: CmdSkull.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Override public void onCommand(String command, String[] args) throws Exception { ItemStack item = new ItemStack(Items.PLAYER_HEAD, 64); if (args.length < 2) { item.setTag(StringNbtReader.parse("{SkullOwner:{Name:\"" + args[0] + "\"}}")); } else if (args[0].equalsIgnoreCase("img")) { CompoundTag tag = StringNbtReader.parse("{SkullOwner:{Id:\"" + UUID.randomUUID() + "\",Properties:{textures:[{Value:\"" + Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"" + args[1] + "\"}}}").getBytes()) + "\"}]}}}"); item.setTag(tag); System.out.println(tag); } mc.player.inventory.addPickBlock(item); }
Example 5
Source File: ServerCrasherHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private CompoundTag createNBT() { try { return StringNbtReader.parse( "{display:{Lore:['\"\u00a7r1. Place item in dispenser.\"','\"\u00a7r2. Dispense item.\"','\"\u00a7r3. Ssss... BOOM!\"'],Name:'{\"text\":\"\u00a7rServer Creeper\"}'},EntityTag:{CustomName:\"TEST\",id:\"Creeper\",CustomNameVisible:1}}"); }catch(CommandSyntaxException e) { throw new RuntimeException(e); } }
Example 6
Source File: GiveCmd.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void call(String[] args) throws CmdException { // validate input if(args.length < 1) throw new CmdSyntaxError(); if(!MC.player.abilities.creativeMode) throw new CmdError("Creative mode only."); // id/name Item item = getItem(args[0]); if(item == Items.AIR && MathUtils.isInteger(args[0])) item = Item.byRawId(Integer.parseInt(args[0])); if(item == Items.AIR) throw new CmdError("Item \"" + args[0] + "\" could not be found."); // amount int amount = 1; if(args.length >= 2) { if(!MathUtils.isInteger(args[1])) throw new CmdSyntaxError("Not a number: " + args[1]); amount = Integer.valueOf(args[1]); if(amount < 1) throw new CmdError("Amount cannot be less than 1."); if(amount > 64) throw new CmdError("Amount cannot be more than 64."); } // nbt data String nbt = null; if(args.length >= 3) nbt = String.join(" ", Arrays.copyOfRange(args, 2, args.length)); // generate item ItemStack stack = new ItemStack(item, amount); if(nbt != null) try { CompoundTag tag = StringNbtReader.parse(nbt); stack.setTag(tag); }catch(CommandSyntaxException e) { ChatUtils.message(e.getMessage()); throw new CmdSyntaxError("NBT data is invalid."); } // give item if(placeStackInHotbar(stack)) ChatUtils.message("Item" + (amount > 1 ? "s" : "") + " created."); else throw new CmdError("Please clear a slot in your hotbar."); }