Java Code Examples for net.minecraft.nbt.ListNBT#getCompound()
The following examples show how to use
net.minecraft.nbt.ListNBT#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: UpgradeTools.java From MiningGadgets with MIT License | 6 votes |
public static List<Upgrade> getUpgradesFromTag(CompoundNBT tagCompound) { ListNBT upgrades = tagCompound.getList(KEY_UPGRADES, Constants.NBT.TAG_COMPOUND); List<Upgrade> functionalUpgrades = new ArrayList<>(); if (upgrades.isEmpty()) return functionalUpgrades; for (int i = 0; i < upgrades.size(); i++) { CompoundNBT tag = upgrades.getCompound(i); // Skip unknowns Upgrade type = getUpgradeByName(tag.getString(KEY_UPGRADE)); if( type == null ) continue; type.setEnabled(!tag.contains(KEY_ENABLED) || tag.getBoolean(KEY_ENABLED)); functionalUpgrades.add(type); } return functionalUpgrades; }
Example 2
Source File: UpgradeTools.java From MiningGadgets with MIT License | 6 votes |
public static List<Upgrade> getActiveUpgradesFromTag(CompoundNBT tagCompound) { ListNBT upgrades = tagCompound.getList(KEY_UPGRADES, Constants.NBT.TAG_COMPOUND); List<Upgrade> functionalUpgrades = new ArrayList<>(); if (upgrades.isEmpty()) return functionalUpgrades; for (int i = 0; i < upgrades.size(); i++) { CompoundNBT tag = upgrades.getCompound(i); Upgrade type = getUpgradeByName(tag.getString(KEY_UPGRADE)); if (type == null) continue; type.setEnabled(!tag.contains(KEY_ENABLED) || tag.getBoolean(KEY_ENABLED)); if (type.isEnabled()) functionalUpgrades.add(type); } return functionalUpgrades; }
Example 3
Source File: PacketDurabilitySync.java From MiningGadgets with MIT License | 5 votes |
public static PacketDurabilitySync decode(PacketBuffer buffer) { CompoundNBT tag = buffer.readCompoundTag(); ListNBT nbtList = tag.getList("list", Constants.NBT.TAG_COMPOUND); List<Tuple<BlockPos, Integer>> thisList = new ArrayList<>(); for (int i = 0; i < nbtList.size(); i++) { CompoundNBT nbt = nbtList.getCompound(i); thisList.add(new Tuple<>(NBTUtil.readBlockPos(nbt.getCompound("pos")), nbt.getInt("dur"))); } return new PacketDurabilitySync(thisList); }
Example 4
Source File: MiningProperties.java From MiningGadgets with MIT License | 5 votes |
public static List<ItemStack> deserializeItemStackList(CompoundNBT nbt) { List<ItemStack> stacks = new ArrayList<>(); ListNBT tagList = nbt.getList("Items", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < tagList.size(); i++) { CompoundNBT itemTags = tagList.getCompound(i); stacks.add(ItemStack.read(itemTags)); } return stacks; }
Example 5
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * NBT item loading function with support for stack sizes > 32K */ public static void readItemStacksFromTag(ItemStack[] items, ListNBT tagList) { for (int i = 0; i < tagList.size(); i++) { CompoundNBT tag = tagList.getCompound(i); int b = tag.getShort("Slot"); items[b] = ItemStack.read(tag); INBT quant = tag.get("Quantity"); if (quant instanceof NumberNBT) { items[b].setCount(((NumberNBT) quant).getInt()); } } }
Example 6
Source File: NBTStructureLoader.java From BoundingBoxOutlineReloaded with MIT License | 5 votes |
SimpleStructureStart(CompoundNBT compound) { super(null, 0, 0, null, new MutableBoundingBox(compound.getIntArray("BB")), 0, 0); ListNBT children = compound.getList("Children", 10); for (int index = 0; index < children.size(); ++index) { CompoundNBT child = children.getCompound(index); if (child.contains("BB")) this.components.add(new SimpleStructurePiece(child)); } }