net.minecraft.nbt.StringNbtReader Java Examples

The following examples show how to use net.minecraft.nbt.StringNbtReader. 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 vote down vote up
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 vote down vote up
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 vote down vote up
@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 vote down vote up
@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 vote down vote up
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: CmdSkull.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@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")) {
		item.setTag(StringNbtReader.parse("{SkullOwner:{Id:\"" + UUID.randomUUID() + "\",Properties:{textures:[{Value:\""
				+ Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"" + args[1] + "\"}}}").getBytes())
				+ "\"}]}}}"));
	}
	
	mc.player.inventory.addPickBlock(item);
}
 
Example #7
Source File: CmdNBT.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
    if (args[0].isEmpty()) {
        BleachLogger.errorMessage("Invalid Syntax!");
        BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
        return;
    }
    ItemStack item = mc.player.inventory.getMainHandStack();

    if (args[0].equalsIgnoreCase("get")) {
    	BleachLogger.infoMessage("§6§lNBT:\n" + item.getTag() + "");
    } else if (args[0].equalsIgnoreCase("copy")) {
        mc.keyboard.setClipboard(item.getTag() + "");
        BleachLogger.infoMessage("§6Copied\n§f" + (item.getTag() + "\n") + "§6to clipboard.");
    } else if (args[0].equalsIgnoreCase("set")) {
        try {
            if (args[1].isEmpty()) {
                BleachLogger.errorMessage("Invalid Syntax!");
                BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
                return;
            }
            item.setTag(StringNbtReader.parse(args[1]));
            BleachLogger.infoMessage("§6Set NBT of " + item.getItem().getName() + "to\n§f" + (item.getTag()));
        } catch (Exception e) {
            BleachLogger.errorMessage("Invalid Syntax!");
            BleachLogger.infoMessage(getSyntax());
        }
    } else if (args[0].equalsIgnoreCase("wipe")) {
        item.setTag(new CompoundTag());
    }

}
 
Example #8
Source File: CmdNBT.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
    if (args[0].isEmpty()) {
        BleachLogger.errorMessage("Invalid Syntax!");
        BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
        return;
    }
    ItemStack item = mc.player.inventory.getMainHandStack();

    if (args[0].equalsIgnoreCase("get")) {
    	BleachLogger.infoMessage("\u00a76\u00a7lNBT:\n" + item.getTag() + "");
    } else if (args[0].equalsIgnoreCase("copy")) {
        mc.keyboard.setClipboard(item.getTag() + "");
        BleachLogger.infoMessage("\u00a76Copied\n\u00a7f" + (item.getTag() + "\n") + "\u00a76to clipboard.");
    } else if (args[0].equalsIgnoreCase("set")) {
        try {
            if (args[1].isEmpty()) {
                BleachLogger.errorMessage("Invalid Syntax!");
                BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
                return;
            }
            item.setTag(StringNbtReader.parse(args[1]));
            BleachLogger.infoMessage("\u00a76Set NBT of " + item.getItem().getName() + "to\n\u00a7f" + (item.getTag()));
        } catch (Exception e) {
            BleachLogger.errorMessage("Invalid Syntax!");
            BleachLogger.infoMessage(getSyntax());
        }
    } else if (args[0].equalsIgnoreCase("wipe")) {
        item.setTag(new CompoundTag());
    }

}
 
Example #9
Source File: CmdNBT.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
    if (args[0].isEmpty()) {
        BleachLogger.errorMessage("Invalid Syntax!");
        BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
        return;
    }
    ItemStack item = mc.player.inventory.getMainHandStack();

    if (args[0].equalsIgnoreCase("get")) {
    	BleachLogger.infoMessage("§6§lNBT:\n" + item.getTag() + "");
    } else if (args[0].equalsIgnoreCase("copy")) {
        mc.keyboard.setClipboard(item.getTag() + "");
        BleachLogger.infoMessage("§6Copied\n§f" + (item.getTag() + "\n") + "§6to clipboard.");
    } else if (args[0].equalsIgnoreCase("set")) {
        try {
            if (args[1].isEmpty()) {
                BleachLogger.errorMessage("Invalid Syntax!");
                BleachLogger.infoMessage(CommandManager.prefix + getSyntax());
                return;
            }
            item.setTag(StringNbtReader.parse(args[1]));
            BleachLogger.infoMessage("§6Set NBT of " + item.getItem().getName() + "to\n§f" + (item.getTag()));
        } catch (Exception e) {
            BleachLogger.errorMessage("Invalid Syntax!");
            BleachLogger.infoMessage(getSyntax());
        }
    } else if (args[0].equalsIgnoreCase("wipe")) {
        item.setTag(new CompoundTag());
    }

}
 
Example #10
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
public NBTSerializableValue(String nbtString)
{
    nbtSupplier = () ->
    {
        try
        {
            return (new StringNbtReader(new StringReader(nbtString))).parseTag();
        }
        catch (CommandSyntaxException e)
        {
            throw new InternalExpressionException("Incorrect NBT data: "+nbtString);
        }
    };
    owned = true;
}
 
Example #11
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static NBTSerializableValue parseString(String nbtString)
{
    Tag tag;
    try
    {
        tag = (new StringNbtReader(new StringReader(nbtString))).parseTag();
    }
    catch (CommandSyntaxException e)
    {
       throw new InternalExpressionException("Incorrect NBT tag: nbtString");
    }
    NBTSerializableValue value = new NBTSerializableValue(tag);
    value.nbtString = nbtString;
    return value;
}
 
Example #12
Source File: GiveCmd.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@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.");
}