Java Code Examples for net.minecraft.nbt.CompoundNBT#put()
The following examples show how to use
net.minecraft.nbt.CompoundNBT#put() .
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: MiningProperties.java From MiningGadgets with MIT License | 6 votes |
public static CompoundNBT serializeItemStackList(List<ItemStack> stacks) { ListNBT nbtTagList = new ListNBT(); for (int i = 0; i < stacks.size(); i++) { if (stacks.get(i).isEmpty()) continue; CompoundNBT itemTag = new CompoundNBT(); stacks.get(i).write(itemTag); nbtTagList.add(itemTag); } CompoundNBT nbt = new CompoundNBT(); nbt.put("Items", nbtTagList); return nbt; }
Example 2
Source File: RenderBlockTileEntity.java From MiningGadgets with MIT License | 6 votes |
@Override public CompoundNBT write(CompoundNBT tag) { if (renderBlock!= null) tag.put("renderBlock", NBTUtil.writeBlockState(renderBlock)); tag.putInt("originalDurability", originalDurability); tag.putInt("priorDurability", priorDurability); tag.putInt("durability", durability); tag.putInt("ticksSinceMine", ticksSinceMine); if (!playerUUID.equals(null)) tag.putUniqueId("playerUUID", playerUUID); tag.put("upgrades", UpgradeTools.setUpgradesNBT(gadgetUpgrades).getList("upgrades", Constants.NBT.TAG_COMPOUND)); tag.putByte("breakType", (byte) breakType.ordinal()); tag.put("gadgetFilters", MiningProperties.serializeItemStackList(getGadgetFilters())); tag.putBoolean("gadgetIsWhitelist", isGadgetIsWhitelist()); tag.putBoolean("blockAllowed", blockAllowed); return super.write(tag); }
Example 3
Source File: PacketDurabilitySync.java From MiningGadgets with MIT License | 5 votes |
public static void encode(PacketDurabilitySync msg, PacketBuffer buffer) { List<Tuple<BlockPos, Integer>> thisList = msg.updateList; CompoundNBT tag = new CompoundNBT(); ListNBT nbtList = new ListNBT(); for (int i = 0; i < thisList.size(); i++) { CompoundNBT nbt = new CompoundNBT(); nbt.put("pos", NBTUtil.writeBlockPos(thisList.get(i).getA())); nbt.putInt("dur", thisList.get(i).getB()); nbtList.add(i, nbt); } tag.put("list", nbtList); buffer.writeCompoundTag(tag); }
Example 4
Source File: UpgradeTools.java From MiningGadgets with MIT License | 5 votes |
/** * DO NOT USE UNLESS YOU KNOW WHAT YOU'RE DOING. This method does not, and for some reason * can not, validate the upgrade you are inserting to the item. Please be sure to always * use {@link MiningGadget#applyUpgrade(ItemStack, UpgradeCard)} unless you actually require this * kind of unchecked functionality */ private static void setUpgradeNBT(CompoundNBT nbt, UpgradeCard upgrade) { ListNBT list = nbt.getList(KEY_UPGRADES, Constants.NBT.TAG_COMPOUND); CompoundNBT compound = new CompoundNBT(); compound.putString(KEY_UPGRADE, upgrade.getUpgrade().getName()); compound.putBoolean(KEY_ENABLED, upgrade.getUpgrade().isEnabled()); list.add(compound); nbt.put(KEY_UPGRADES, list); }
Example 5
Source File: UpgradeTools.java From MiningGadgets with MIT License | 5 votes |
public static CompoundNBT setUpgradesNBT(List<Upgrade> laserUpgrades) { CompoundNBT listCompound = new CompoundNBT(); ListNBT list = new ListNBT(); laserUpgrades.forEach( upgrade -> { CompoundNBT compound = new CompoundNBT(); compound.putString(KEY_UPGRADE, upgrade.getName()); compound.putBoolean(KEY_ENABLED, upgrade.isEnabled()); list.add(compound); }); listCompound.put(KEY_UPGRADES, list); return listCompound; }
Example 6
Source File: UpgradeTools.java From MiningGadgets with MIT License | 5 votes |
/** * @implNote note that this is the only instance we use getName for non-eval uses * as the gadget stores the full name and not it's base name */ public static void removeUpgrade(ItemStack tool, Upgrade upgrade) { CompoundNBT tagCompound = tool.getOrCreateTag(); ListNBT upgrades = tagCompound.getList(KEY_UPGRADES, Constants.NBT.TAG_COMPOUND); // Slightly completed but basically it just makes a new list and collects that back to an ListNBT tagCompound.put(KEY_UPGRADES, upgrades.stream() .filter(e -> !((CompoundNBT) e).getString(KEY_UPGRADE).equals(upgrade.getName())) .collect(Collectors.toCollection(ListNBT::new))); }
Example 7
Source File: EnderItemStorage.java From EnderStorage with MIT License | 5 votes |
public CompoundNBT saveToTag() { if (size != EnderStorageConfig.storageSize && open == 0) { alignSize(); } CompoundNBT compound = new CompoundNBT(); compound.put("Items", InventoryUtils.writeItemStacksToTag(items)); compound.putByte("size", (byte) size); return compound; }
Example 8
Source File: ChoppingBlockTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CompoundNBT write(CompoundNBT compound) { compound = super.write(compound); compound.put("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(slotInventory, null)); return compound; }
Example 9
Source File: ChoppingBlockTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CompoundNBT getUpdateTag() { CompoundNBT compound = new CompoundNBT(); compound.put("Item", slotInventory.getStackInSlot(0).serializeNBT()); return compound; }
Example 10
Source File: SawmillTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CompoundNBT write(CompoundNBT compound) { compound = super.write(compound); compound.put("Items", ITEMS_CAP.writeNBT(inventory, null)); compound.putInt("BurnTime", (short) this.remainingBurnTime); compound.putInt("CookTime", (short) this.cookTime); return compound; }
Example 11
Source File: DryingRackTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CompoundNBT getUpdateTag() { CompoundNBT compound = super.getUpdateTag(); compound.put("Items", items.serializeNBT()); return compound; }
Example 12
Source File: DryingRackTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CompoundNBT write(CompoundNBT compound) { compound = super.write(compound); compound.put("Items", items.serializeNBT()); compound.putIntArray("RemainingTime", dryTimeRemaining); return compound; }
Example 13
Source File: TileFrequencyOwner.java From EnderStorage with MIT License | 4 votes |
@Override public CompoundNBT write(CompoundNBT tag) { super.write(tag); tag.put("Frequency", frequency.writeToNBT(new CompoundNBT())); return tag; }
Example 14
Source File: Frequency.java From EnderStorage with MIT License | 4 votes |
public ItemStack writeToStack(ItemStack stack) { CompoundNBT tagCompound = stack.getOrCreateTag(); tagCompound.put("Frequency", write_internal(new CompoundNBT())); return stack; }
Example 15
Source File: EnderLiquidStorage.java From EnderStorage with MIT License | 4 votes |
public CompoundNBT saveToTag() { CompoundNBT compound = new CompoundNBT(); compound.put("tank", tank.writeToNBT(new CompoundNBT())); return compound; }
Example 16
Source File: Cuboid6.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public CompoundNBT writeToNBT(CompoundNBT tag) { tag.put("min", min.writeToNBT(new CompoundNBT())); tag.put("max", max.writeToNBT(new CompoundNBT())); return tag; }