Java Code Examples for net.minecraft.nbt.NBTTagCompound#isEmpty()
The following examples show how to use
net.minecraft.nbt.NBTTagCompound#isEmpty() .
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: SchematicBase.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
protected List<EntityInfo> readEntitiesFromListTag(NBTTagList tagList) { List<EntityInfo> entityList = new ArrayList<>(); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound entityData = tagList.getCompoundTagAt(i); Vec3d posVec = NBTUtils.readVec3dFromListTag(entityData); if (posVec != null && entityData.isEmpty() == false) { entityList.add(new EntityInfo(posVec, entityData)); } } return entityList; }
Example 2
Source File: SchematicBase.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
protected Map<BlockPos, NBTTagCompound> readBlockEntitiesFromListTag(NBTTagList tagList) { Map<BlockPos, NBTTagCompound> tileMap = new HashMap<>(); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound tag = tagList.getCompoundTagAt(i); BlockPos pos = NBTUtils.readBlockPos(tag); NBTUtils.removeBlockPosFromTag(tag); if (pos != null && tag.isEmpty() == false) { tileMap.put(pos, tag); } } return tileMap; }
Example 3
Source File: SpongeSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected List<EntityInfo> readEntitiesFromTag(NBTTagCompound tag) { List<EntityInfo> entities = new ArrayList<>(); NBTTagList tagList = tag.getTagList("Entities", Constants.NBT.TAG_COMPOUND); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound entityData = tagList.getCompoundTagAt(i); Vec3d pos = NBTUtils.readVec3dFromListTag(entityData); if (pos != null && entityData.isEmpty() == false) { entityData.setString("id", entityData.getString("Id")); // Remove the Sponge tags from the data that is kept in memory entityData.removeTag("Id"); entities.add(new EntityInfo(pos, entityData)); } } return entities; }
Example 4
Source File: LitematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
private List<EntityInfo> readEntitiesFromNBT_v1(NBTTagList tagList) { List<EntityInfo> entityList = new ArrayList<>(); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound tag = tagList.getCompoundTagAt(i); Vec3d posVec = NBTUtils.readVec3d(tag); NBTTagCompound entityData = tag.getCompoundTag("EntityData"); if (posVec != null && entityData.isEmpty() == false) { // Update the correct position to the Entity NBT, where it is stored in version 2 NBTUtils.writeVec3dToListTag(posVec, entityData); entityList.add(new EntityInfo(posVec, entityData)); } } return entityList; }
Example 5
Source File: LitematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
private Map<BlockPos, NBTTagCompound> readTileEntitiesFromNBT_v1(NBTTagList tagList) { Map<BlockPos, NBTTagCompound> tileMap = new HashMap<>(); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound tag = tagList.getCompoundTagAt(i); NBTTagCompound tileNbt = tag.getCompoundTag("TileNBT"); // Note: This within-schematic relative position is not inside the tile tag! BlockPos pos = NBTUtils.readBlockPos(tag); if (pos != null && tileNbt.isEmpty() == false) { tileMap.put(pos, tileNbt); } } return tileMap; }
Example 6
Source File: NBTUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
/** * Remove a compound tag by the name <b>tagName</b>. If <b>containerTagName</b> is not null, then * the tag is removed from inside a tag by that name. */ public static void removeCompoundTag(@Nonnull ItemStack stack, @Nullable String containerTagName, @Nonnull String tagName) { NBTTagCompound nbt = getCompoundTag(stack, containerTagName, false); if (nbt != null && nbt.hasKey(tagName, Constants.NBT.TAG_COMPOUND)) { nbt.removeTag(tagName); if (nbt.isEmpty()) { if (containerTagName != null) { stack.getTagCompound().removeTag(containerTagName); } else { stack.setTagCompound(null); } } } }
Example 7
Source File: NBTUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns a copy of the compound tag <b>tag</b>, but excludes top-level members matching <b>exclude</b>. * If the resulting tag has no other keys, then null is returned instead of an empty compound. * @param tag * @param copyTags If true, the sub-tags are copied. If false, they are referenced directly. * @param exclude the keys/tags to exclude * @return */ @Nullable public static NBTTagCompound getCompoundExcludingTags(@Nonnull NBTTagCompound tag, boolean copyTags, String... exclude) { NBTTagCompound newTag = new NBTTagCompound(); Set<String> excludeSet = Sets.newHashSet(exclude); for (String key : tag.getKeySet()) { if (excludeSet.contains(key) == false) { newTag.setTag(key, copyTags ? tag.getTag(key).copy() : tag.getTag(key)); } } return newTag.isEmpty() ? null : newTag; }
Example 8
Source File: SpongeSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<BlockPos, NBTTagCompound> readBlockEntitiesFromTag(NBTTagCompound tag) { Map<BlockPos, NBTTagCompound> blockEntities = new HashMap<>(); String tagName = this.version == 1 ? "TileEntities" : "BlockEntities"; NBTTagList tagList = tag.getTagList(tagName, Constants.NBT.TAG_COMPOUND); final int size = tagList.tagCount(); for (int i = 0; i < size; ++i) { NBTTagCompound beTag = tagList.getCompoundTagAt(i); BlockPos pos = NBTUtils.readBlockPosFromArrayTag(beTag, "Pos"); if (pos != null && beTag.isEmpty() == false) { beTag.setString("id", beTag.getString("Id")); // Remove the Sponge tags from the data that is kept in memory beTag.removeTag("Id"); beTag.removeTag("Pos"); if (this.version == 1) { beTag.removeTag("ContentVersion"); } blockEntities.put(pos, beTag); } } return blockEntities; }
Example 9
Source File: NBTUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the root compound tag in the given ItemStack. An empty compound will be stripped completely. */ @Nonnull public static ItemStack setRootCompoundTag(@Nonnull ItemStack stack, @Nullable NBTTagCompound nbt) { if (nbt != null && nbt.isEmpty()) { nbt = null; } stack.setTagCompound(nbt); return stack; }
Example 10
Source File: ItemEnderPart.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void addTooltipLines(ItemStack stack, EntityPlayer player, List<String> list, boolean verbose) { String preWh = TextFormatting.WHITE.toString(); String preRed = TextFormatting.RED.toString(); String rst = TextFormatting.RESET.toString() + TextFormatting.GRAY.toString(); String strOwner = I18n.format("enderutilities.tooltip.item.owner"); // Set to private and not the owner OwnerData ownerData = OwnerData.getOwnerDataFromItem(stack); if (ownerData != null && ownerData.canAccess(player) == false) { list.add(String.format("%s: %s%s%s - %s%s%s", strOwner, preWh, ownerData.getOwnerName(), rst, preRed, I18n.format("enderutilities.tooltip.item.private"), rst)); return; } int meta = stack.getMetadata(); NBTTagCompound nbt = stack.getTagCompound(); if (meta >= 50 && meta <= 54 && (nbt == null || nbt.isEmpty())) { list.add(I18n.format("enderutilities.tooltip.item.memorycard.nodata")); return; } if (meta == 50) // Memory Card (misc) { ArrayList<String> listDataTypes = new ArrayList<String>(); Iterator<String> iter = nbt.getKeySet().iterator(); while (iter.hasNext()) { String key = iter.next(); if (key != null && key.equals("display") == false && key.equals("RepairCost") == false) { listDataTypes.add(" " + key); } } if (listDataTypes.size() > 0) { list.add(I18n.format("enderutilities.tooltip.item.memorycard.datatypecount", listDataTypes.size())); list.addAll(listDataTypes); } else { list.add(I18n.format("enderutilities.tooltip.item.memorycard.nodata")); } } else if (meta >= 51 && meta <= 54) // Memory Card (items) { ArrayList<String> lines = new ArrayList<String>(); int itemCount = UtilItemModular.getFormattedItemListFromContainerItem(stack, lines, 20); if (lines.size() > 0) { NBTTagList tagList = NBTUtils.getStoredItemsList(stack, false); int stackCount = tagList != null ? tagList.tagCount() : 0; list.add(I18n.format("enderutilities.tooltip.item.memorycard.items.stackcount", stackCount, itemCount)); list.addAll(lines); } else { list.add(I18n.format("enderutilities.tooltip.item.memorycard.noitems")); } } // Print the owner data after the contents if the player can access/see the contents if (ownerData != null) { String mode = ownerData.getIsPublic() ? I18n.format("enderutilities.tooltip.item.public") : I18n.format("enderutilities.tooltip.item.private"); String modeColor = ownerData.getIsPublic() ? TextFormatting.GREEN.toString() : preRed; list.add(String.format("%s: %s%s%s - %s%s%s", strOwner, preWh, ownerData.getOwnerName(), rst, modeColor, mode, rst)); } }