Java Code Examples for net.minecraft.nbt.NBTTagCompound#getKeySet()
The following examples show how to use
net.minecraft.nbt.NBTTagCompound#getKeySet() .
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: TileEntityPipeBase.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); if (compound.hasKey("PipeBlock", NBT.TAG_STRING)) { Block block = Block.REGISTRY.getObject(new ResourceLocation(compound.getString("PipeBlock"))); //noinspection unchecked this.pipeBlock = block instanceof BlockPipe ? (BlockPipe<PipeType, NodeDataType, ?>) block : null; } this.pipeType = getPipeTypeClass().getEnumConstants()[compound.getInteger("PipeType")]; NBTTagCompound blockedConnectionsTag = compound.getCompoundTag("BlockedConnectionsMap"); this.blockedConnectionsMap.clear(); for(String attachmentTypeKey : blockedConnectionsTag.getKeySet()) { int attachmentType = Integer.parseInt(attachmentTypeKey); int blockedConnections = blockedConnectionsTag.getInteger(attachmentTypeKey); this.blockedConnectionsMap.put(attachmentType, blockedConnections); } recomputeBlockedConnections(); this.insulationColor = compound.getInteger("InsulationColor"); this.coverableImplementation.readFromNBT(compound); }
Example 2
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 3
Source File: WizardryWorldStorage.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void readNBT(Capability<WizardryWorld> capability, WizardryWorld instance, EnumFacing side, NBTBase nbt) { HashMap<UUID, Integer> map = new HashMap<>(); NBTTagCompound tag = (NBTTagCompound) nbt; NBTTagCompound playerBackup = tag.getCompoundTag(BACKUP_NBT_TAG); for(String playerId : playerBackup.getKeySet()) { map.put(UUID.fromString(playerId), playerBackup.getInteger(playerId)); } instance.setBackupMap(map); }
Example 4
Source File: ItemToolTipHandler.java From AgriCraft with MIT License | 5 votes |
@SubscribeEvent public void addNbtInfo(ItemTooltipEvent event) { if (AgriCraftConfig.enableNBTTooltips) { addCategory(event, "NBT"); if (StackHelper.hasTag(event.getItemStack())) { final NBTTagCompound tag = StackHelper.getTag(event.getItemStack()); for (String key : tag.getKeySet()) { addParameter(event, key, tag.getTag(key)); } } else { addFormatted(event, " - No NBT Tags"); } } }
Example 5
Source File: CommandNbt.java From AgriCraft with MIT License | 5 votes |
private void listNbt(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull NBTTagCompound tag) throws CommandException { for (String key : tag.getKeySet()) { final NBTBase entry = tag.getTag(key); final String type = NBTBase.NBT_TYPES[entry.getId()]; MessageUtil.messagePlayer(player, "`l`3{0}`r `b{1}`r: `2{2}`r", type, key, entry); } }
Example 6
Source File: PlayerSkillData.java From TFC2 with GNU General Public License v3.0 | 5 votes |
public void readNBT(NBTTagCompound nbt) { if (nbt.hasKey("skillCompound")) { NBTTagCompound skillCompound = nbt.getCompoundTag("skillCompound"); for(String skill : skillCompound.getKeySet()) { setSkill(skill, skillCompound.getInteger(skill)); } } }
Example 7
Source File: DataConverter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Data toNova(NBTTagCompound nbt) { Data data = new Data(); if (nbt != null) { data.className = nbt.getString("class"); @SuppressWarnings("unchecked") Set<String> keys = nbt.getKeySet(); keys.stream().filter(k -> k != null && !"class".equals(k)).filter(Data.ILLEGAL_SUFFIX.asPredicate().negate()).forEach(k -> data.put(k, load(nbt, k))); } return data; }
Example 8
Source File: DataConverter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
@Override @Nonnull public Data toNova(@Nullable NBTTagCompound nbt) { Data data = new Data(); if (nbt != null) { data.className = nbt.getString("class"); Set<String> keys = nbt.getKeySet(); keys.stream() .filter(k -> k != null && !"class".equals(k)) .filter(Data.ILLEGAL_SUFFIX.asPredicate().negate()) .forEach(k -> Optional.ofNullable(load(nbt, k)).ifPresent(v -> data.put(k, v))); } return data; }
Example 9
Source File: QuestData.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
private Map<String, String> readSMap(NBTTagCompound c) { Map<String, String> m = new HashMap<String, String>(); for (String key : c.getKeySet()) { m.put(key, c.getString(key)); } return m; }
Example 10
Source File: QuestData.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
private Map<String, Integer> readIMap(NBTTagCompound c) { Map<String, Integer> m = new HashMap<String, Integer>(); for (String key : c.getKeySet()) { m.put(key, c.getInteger(key)); } return m; }
Example 11
Source File: EntityVillageLord.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); NBTTagCompound c = compound.getCompoundTag("Items"); inventories = new HashMap<UUID, VillageLordInventory>(); for (String sPlayerId : c.getKeySet()) { VillageLordInventory inv = new VillageLordInventory(this, "VillageLordInventory", getInventorySize()); inv.loadAllItems(c.getTagList(sPlayerId, 10)); inventories.put(UUID.fromString(sPlayerId), inv); } }
Example 12
Source File: SpellRing.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns a normalized NBT tag compound for information from a source. * * @param informationNbt a source NBT compound * @return normalized information NBT compound */ private static NBTTagCompound sortInformationTag(NBTTagCompound informationNbt) { ArrayList<Pair<String, Float>> sortedInformationList = new ArrayList<>(informationNbt.getSize()); for (String key : informationNbt.getKeySet()) { sortedInformationList.add(Pair.of(key, FixedPointUtils.getFixedFromNBT(informationNbt, key))); } sortedInformationList.sort(Comparator.comparing(Pair::getKey)); NBTTagCompound newInformationTag = new NBTTagCompound(); for (Pair<String, Float> entry : sortedInformationList) { FixedPointUtils.setFixedToNBT(newInformationTag, entry.getKey(), entry.getValue()); } return newInformationTag; }
Example 13
Source File: SpellData.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void deserializeNBT(NBTTagCompound nbt) { for (String key : nbt.getKeySet()) { DataField<?> field = availableFields.get(key); if (field != null) { NBTBase nbtType = nbt.getTag(key); data.put(field, field.getDataTypeProcess().deserialize(nbtType)); } } }
Example 14
Source File: SchematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
protected boolean readMCEdit2PaletteFromTag(NBTTagCompound tag) { Set<String> keys = tag.getKeySet(); for (String idStr : keys) { String key = tag.getString(idStr); int id; try { id = Integer.parseInt(idStr); } catch (NumberFormatException e) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.palette.id_not_number", idStr, key); continue; } if (id >= this.palette.length) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.mcedit2.palette.invalid_id", id, key, this.palette.length - 1); continue; } Block block = Block.REGISTRY.getObject(new ResourceLocation(key)); if (block == null) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.mcedit2.missing_block_data", key); continue; } this.palette[id] = block; } return true; }
Example 15
Source File: SchematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
protected boolean readSchematicaPaletteFromTag(NBTTagCompound tag) { Set<String> keys = tag.getKeySet(); for (String key : keys) { int id = tag.getShort(key); if (id >= this.palette.length) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.palette.invalid_id", id, key, this.palette.length - 1); continue; } Block block = Block.REGISTRY.getObject(new ResourceLocation(key)); if (block == null) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.palette.invalid_block", key); continue; } this.palette[id] = block; } return true; }
Example 16
Source File: BackpacksConfig.java From WearableBackpacks with MIT License | 5 votes |
/** Syncronizes the client settings to the ones specified * in the compound tag. (Called by MessageSyncSettings.) */ @SideOnly(Side.CLIENT) public void syncSettings(NBTTagCompound data) { if (!_connected) return; for (String key : data.getKeySet()) { NBTBase tag = data.getTag(key); Setting<?> setting = getSetting(key); if ((setting != null) && setting.doesSync()) setting.readSynced(tag); } }
Example 17
Source File: MixinNBTUtil.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
/** * @author Sk1er * @reason Not proper null checks */ @Overwrite public static GameProfile readGameProfileFromNBT(NBTTagCompound compound) { String s = null; String s1 = null; if (compound.hasKey("Name", 8)) s = compound.getString("Name"); if (compound.hasKey("Id", 8)) s1 = compound.getString("Id"); if (StringUtils.isNullOrEmpty(s) && StringUtils.isNullOrEmpty(s1)) { return null; } else { UUID uuid = null; if (s1 != null) try { uuid = UUID.fromString(s1); } catch (Throwable ignored) { } GameProfile gameprofile = new GameProfile(uuid, s); if (compound.hasKey("Properties", 10)) { NBTTagCompound nbttagcompound = compound.getCompoundTag("Properties"); for (String s2 : nbttagcompound.getKeySet()) { NBTTagList nbttaglist = nbttagcompound.getTagList(s2, 10); int bound = nbttaglist.tagCount(); for (int i = 0; i < bound; i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); String s3 = nbttagcompound1.getString("Value"); gameprofile.getProperties().put(s2, nbttagcompound1.hasKey("Signature", 8) ? new Property(s2, s3, nbttagcompound1.getString("Signature")) : new Property(s2, s3)); } } } return gameprofile; } }
Example 18
Source File: CellSavedWorldData.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { storageIndex = nbt.getInteger("index"); for (String s : nbt.getKeySet()) { Integer[] temp = new Integer[6]; for (int i = 0; i < nbt.getIntArray(s).length; i++) temp[i] = nbt.getIntArray(s)[i]; storageCells.put(s, temp); } }
Example 19
Source File: BackpackManager.java From SkyblockAddons with MIT License | 4 votes |
public static Backpack getFromItem(ItemStack stack) { if (stack == null) return null; SkyblockAddons main = SkyblockAddons.getInstance(); String id = ItemUtils.getSkyBlockItemID(stack); if (id != null) { NBTTagCompound extraAttributes = stack.getTagCompound().getCompoundTag("ExtraAttributes"); Matcher matcher = BACKPACK_ID_PATTERN.matcher(id); boolean matches = matcher.matches(); boolean isCakeBag = main.getConfigValues().isEnabled(Feature.CAKE_BAG_PREVIEW) && "NEW_YEAR_CAKE_BAG".equals(id) && EnumUtils.InventoryType.getCurrentInventoryType() != EnumUtils.InventoryType.BAKER; // If it's a backpack OR it's a cake bag and they have the setting enabled. if (matches || isCakeBag) { byte[] bytes = null; for (String key : extraAttributes.getKeySet()) { if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { bytes = extraAttributes.getByteArray(key); break; } } try { int length = 0; if (matches) { String backpackType = matcher.group(1); switch (backpackType) { // because sometimes the size of the tag is not updated (etc. when you upcraft it) case "SMALL": length = 9; break; case "MEDIUM": length = 18; break; case "LARGE": length = 27; break; case "GREATER": length = 36; break; } } ItemStack[] items = new ItemStack[length]; if (bytes != null) { NBTTagCompound nbtTagCompound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); NBTTagList list = nbtTagCompound.getTagList("i", Constants.NBT.TAG_COMPOUND); if (list.tagCount() > length) { length = list.tagCount(); items = new ItemStack[length]; } for (int i = 0; i < length; i++) { NBTTagCompound item = list.getCompoundTagAt(i); // This fixes an issue in Hypixel where enchanted potatoes have the wrong id (potato block instead of item). short itemID = item.getShort("id"); if (itemID == 142) { // Potato Block -> Potato Item item.setShort("id", (short) 392); } else if (itemID == 141) { // Carrot Block -> Carrot Item item.setShort("id", (short) 391); } ItemStack itemStack = ItemStack.loadItemStackFromNBT(item); items[i] = itemStack; } } BackpackColor color = BackpackColor.WHITE; if (extraAttributes.hasKey("backpack_color")) { try { color = BackpackColor.valueOf(extraAttributes.getString("backpack_color")); } catch (IllegalArgumentException ignored) {} } return new Backpack(items, TextUtils.stripColor(stack.getDisplayName()), color); } catch (IOException ex) { ex.printStackTrace(); } } } return null; }
Example 20
Source File: LitematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
private boolean readSubRegionsFromTag(NBTTagCompound tag, int version) { tag = tag.getCompoundTag("Regions"); for (String regionName : tag.getKeySet()) { if (tag.getTag(regionName).getId() == Constants.NBT.TAG_COMPOUND) { NBTTagCompound regionTag = tag.getCompoundTag(regionName); BlockPos regionPos = NBTUtils.readBlockPos(regionTag.getCompoundTag("Position")); BlockPos regionSize = NBTUtils.readBlockPos(regionTag.getCompoundTag("Size")); if (regionPos != null && regionSize != null) { this.subRegions.put(regionName, new SubRegion(regionPos, regionSize)); if (version >= 2) { this.blockEntities.put(regionName, this.readBlockEntitiesFromListTag(regionTag.getTagList("TileEntities", Constants.NBT.TAG_COMPOUND))); this.entities.put(regionName, this.readEntitiesFromListTag(regionTag.getTagList("Entities", Constants.NBT.TAG_COMPOUND))); } else if (version == 1) { this.blockEntities.put(regionName, this.readTileEntitiesFromNBT_v1(regionTag.getTagList("TileEntities", Constants.NBT.TAG_COMPOUND))); this.entities.put(regionName, this.readEntitiesFromNBT_v1(regionTag.getTagList("Entities", Constants.NBT.TAG_COMPOUND))); } if (version >= 3) { this.pendingBlockTicks.put(regionName, this.readBlockTicksFromNBT(regionTag.getTagList("PendingBlockTicks", Constants.NBT.TAG_COMPOUND))); } NBTBase nbtBase = regionTag.getTag("BlockStates"); // There are no convenience methods in NBTTagCompound yet in 1.12, so we'll have to do it the ugly way... if (nbtBase != null && nbtBase.getId() == Constants.NBT.TAG_LONG_ARRAY) { Vec3i size = new Vec3i(Math.abs(regionSize.getX()), Math.abs(regionSize.getY()), Math.abs(regionSize.getZ())); NBTTagList paletteTag = regionTag.getTagList("BlockStatePalette", Constants.NBT.TAG_COMPOUND); long[] blockStateArr = ((IMixinNBTTagLongArray) nbtBase).getArray(); int paletteSize = paletteTag.tagCount(); LitematicaBlockStateContainerFull container = LitematicaBlockStateContainerFull.createContainer(paletteSize, blockStateArr, size); if (container == null) { InfoUtils.printErrorMessage("litematica.error.schematic_read_from_file_failed.region_container", regionName, this.getFile() != null ? this.getFile().getName() : "<null>"); return false; } this.readPaletteFromLitematicaFormatTag(paletteTag, container.getPalette()); this.blockContainers.put(regionName, container); } else { return false; } } } } return true; }