Java Code Examples for net.minecraft.nbt.ListTag#size()
The following examples show how to use
net.minecraft.nbt.ListTag#size() .
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: MixinEnchantedBookItem.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
@Override public String getCreatorModId(ItemStack itemStack) { final Item item = itemStack.getItem(); final Identifier defaultId = Registry.ITEM.getDefaultId(); final Identifier id = Registry.ITEM.getId(item); if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) { return null; } else { final String namespace = id.getNamespace(); if ("minecraft".equals(namespace)) { final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack); if (enchantments.size() == 1) { final Identifier enchantmentId = Identifier.tryParse(enchantments.getCompound(0).getString("id")); if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) { return enchantmentId.getNamespace(); } } } return namespace; } }
Example 2
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
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 3
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
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 4
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
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: CandyComponent.java From the-hallow with MIT License | 5 votes |
@Override public void fromTag(CompoundTag tag) { ListTag list = tag.getList("entities", 10); for (int i = 0; i < list.size(); i++) { CompoundTag item = list.getCompound(i); lastGivenCandy.put(item.getUuid("uuid"), item.getLong("time")); } }
Example 6
Source File: Items_1_12_2.java From multiconnect with MIT License | 5 votes |
private static void oldEnchantmentListToNew(ListTag enchantments) { for (int i = 0; i < enchantments.size(); i++) { CompoundTag ench = enchantments.getCompound(i); int id = ench.getInt("id"); Identifier name = Registry.ENCHANTMENT.getId(Registry.ENCHANTMENT.get(id)); if (name == null) { enchantments.remove(i); i--; } else { ench.putString("id", name.toString()); } } }
Example 7
Source File: Items_1_12_2.java From multiconnect with MIT License | 5 votes |
private static void newEnchantmentListToOld(ListTag enchantments) { for (int i = 0; i < enchantments.size(); i++) { CompoundTag ench = enchantments.getCompound(i); Identifier name = Identifier.tryParse(ench.getString("id")); Enchantment enchObj = Registry.ENCHANTMENT.get(name); if (enchObj == null) { enchantments.remove(i); i--; } else { ench.putInt("id", Registry.ENCHANTMENT.getRawId(enchObj)); } } }
Example 8
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static List<List<String>> getTextInBook(ItemStack item) { List<String> pages = new ArrayList<>(); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.containsKey("pages")) { ListTag nbt2 = nbt.getList("pages", 8); for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i)); } List<List<String>> finalPages = new ArrayList<>(); for (String s: pages) { String buffer = ""; List<String> pageBuffer = new ArrayList<>(); for (char c: s.toCharArray()) { if (MinecraftClient.getInstance().textRenderer.getStringWidth(buffer) > 114 || buffer.endsWith("\n")) { pageBuffer.add(buffer.replace("\n", "")); buffer = ""; } buffer += c; } pageBuffer.add(buffer); finalPages.add(pageBuffer); } return finalPages; }
Example 9
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static List<List<String>> getTextInBook(ItemStack item) { List<String> pages = new ArrayList<>(); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.contains("pages")) { ListTag nbt2 = nbt.getList("pages", 8); for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i)); } List<List<String>> finalPages = new ArrayList<>(); for (String s: pages) { String buffer = ""; List<String> pageBuffer = new ArrayList<>(); for (char c: s.toCharArray()) { if (MinecraftClient.getInstance().textRenderer.getWidth(buffer) > 114 || buffer.endsWith("\n")) { pageBuffer.add(buffer.replace("\n", "")); buffer = ""; } buffer += c; } pageBuffer.add(buffer); finalPages.add(pageBuffer); } return finalPages; }
Example 10
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static List<List<String>> getTextInBook(ItemStack item) { List<String> pages = new ArrayList<>(); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.contains("pages")) { ListTag nbt2 = nbt.getList("pages", 8); for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i)); } List<List<String>> finalPages = new ArrayList<>(); for (String s: pages) { String buffer = ""; List<String> pageBuffer = new ArrayList<>(); for (char c: s.toCharArray()) { if (MinecraftClient.getInstance().textRenderer.getStringWidth(buffer) > 114 || buffer.endsWith("\n")) { pageBuffer.add(buffer.replace("\n", "")); buffer = ""; } buffer += c; } pageBuffer.add(buffer); finalPages.add(pageBuffer); } return finalPages; }
Example 11
Source File: ShapeDispatcher.java From fabric-carpet with MIT License | 5 votes |
public Value decode(Tag tag) { ListTag ltag = (ListTag)tag; List<Value> points = new ArrayList<>(); for (int i=0, ll = ltag.size(); i<ll; i++) { ListTag ptag = ltag.getList(i); points.add(ListValue.of( new NumericValue(ptag.getDouble(0)), new NumericValue(ptag.getDouble(1)), new NumericValue(ptag.getDouble(2)) )); } return ListValue.wrap(points); }
Example 12
Source File: ShapesRenderer.java From fabric-carpet with MIT License | 5 votes |
public void addShapes(ListTag tag) { for (int i=0, count = tag.size(); i < count; i++) { addShape(tag.getCompound(i)); } }
Example 13
Source File: CarpetClient.java From fabric-carpet with MIT License | 5 votes |
public static void onClientCommand(Tag t) { CarpetSettings.LOG.info("Server Response:"); CompoundTag tag = (CompoundTag)t; CarpetSettings.LOG.info(" - id: "+tag.getString("id")); CarpetSettings.LOG.info(" - code: "+tag.getInt("code")); if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error")); if (tag.contains("output")) { ListTag outputTag = (ListTag) tag.get("output"); for (int i = 0; i < outputTag.size(); i++) CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString()); } }