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

The following examples show how to use net.minecraft.nbt.CompoundTag#getCompound() . 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: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public void fromTag(CompoundTag tag) {
    CompoundTag compoundTag = tag.getCompound("security");

    if (compoundTag.contains("owner")) {
        if (!this.hasOwner()) {
            this.owner = compoundTag.getUuid("owner");
        }
    }

    if (compoundTag.contains("team")) {
        if (!this.hasTeam()) {
            this.team = new Identifier(compoundTag.getString("team"));
        }
    }

    this.username = compoundTag.getString("username");
    this.publicity = Publicity.valueOf(compoundTag.getString("publicity"));
}
 
Example 2
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 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.containsKey("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.containsKey("Items")) {
			ListTag nbt3 = (ListTag) nbt2.getTag("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompoundTag(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompoundTag(i)));
			}
		}
	}
	
	return items;
}
 
Example 4
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 5
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 6
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "deserialize", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk"))
private static WorldChunk newWorldChunk(
		World newWorld, ChunkPos newChunkPos, Biome[] newBiomes, UpgradeData newUpgradeData, TickScheduler<Block> newTickScheduler, TickScheduler<Fluid> newTickScheduler2, long newL, @Nullable ChunkSection[] newChunkSections, @Nullable Consumer<WorldChunk> newConsumer,
		ServerWorld serverWorld, StructureManager structureManager, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, CompoundTag compoundTag) {
	WorldChunk chunk = new WorldChunk(newWorld, newChunkPos, newBiomes, newUpgradeData, newTickScheduler, newTickScheduler2, newL, newChunkSections, newConsumer);
	CompoundTag level = compoundTag.getCompound("Level");

	if (level.contains("ForgeCaps")) {
		((CapabilityProviderHolder) chunk).deserializeCaps(level.getCompound("ForgeCaps"));
	}

	return chunk;
}
 
Example 7
Source File: InventoryHelper.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean cleanUpShulkerBoxTag(ItemStack stack)
{
    boolean changed = false;
    CompoundTag tag = stack.getTag();

    if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
        return false;

    CompoundTag bet = tag.getCompound("BlockEntityTag");
    if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty())
    {
        bet.remove("Items");
        changed = true;
    }

    if (bet.isEmpty())
    {
        tag.remove("BlockEntityTag");
        changed = true;
    }
    if (tag.isEmpty())
    {
        stack.setTag(null);
        changed = true;
    }
    return changed;
}
 
Example 8
Source File: InventoryHelper.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean shulkerBoxHasItems(ItemStack stack)
{
    CompoundTag tag = stack.getTag();

    if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
        return false;

    CompoundTag bet = tag.getCompound("BlockEntityTag");
    return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty();
}
 
Example 9
Source File: BasicSolarPanelPartBlockEntity.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public void fromTag(BlockState state, CompoundTag tag) {
    super.fromTag(state, tag);
    CompoundTag base = tag.getCompound("Base");
    this.basePos = new BlockPos(base.getInt("X"), base.getInt("Y"), base.getInt("Z"));
}