Java Code Examples for net.minecraft.nbt.CompoundTag#get()

The following examples show how to use net.minecraft.nbt.CompoundTag#get() . 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 NbtPath parseNbtPath(CompoundTag tag, String path)
{
	String[] parts = path.split("\\.");
	
	CompoundTag base = tag;
	if(base == null)
		return null;
	
	for(int i = 0; i < parts.length - 1; i++)
	{
		String part = parts[i];
		
		if(!base.contains(part) || !(base.get(part) instanceof CompoundTag))
			return null;
		
		base = base.getCompound(part);
	}
	
	if(!base.contains(parts[parts.length - 1]))
		return null;
	
	return new NbtPath(base, parts[parts.length - 1]);
}
 
Example 2
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public static List<ItemStack> getItemsInContainer(ItemStack item) {
	List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.contains("Items")) {
			ListTag nbt3 = (ListTag) nbt2.get("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i)));
			}
		}
	}
	
	return items;
}
 
Example 3
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public static List<ItemStack> getItemsInContainer(ItemStack item) {
	List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.contains("Items")) {
			ListTag nbt3 = (ListTag) nbt2.get("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i)));
			}
		}
	}
	
	return items;
}
 
Example 4
Source File: CarpetClient.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void onClientCommand(Tag t)
{
    CarpetSettings.LOG.info("Server Response:");
    CompoundTag tag = (CompoundTag)t;
    CarpetSettings.LOG.info(" - id: "+tag.getString("id"));
    CarpetSettings.LOG.info(" - code: "+tag.getInt("code"));
    if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error"));
    if (tag.contains("output"))
    {
        ListTag outputTag = (ListTag) tag.get("output");
        for (int i = 0; i < outputTag.size(); i++)
            CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString());
    }
}