Java Code Examples for us.myles.ViaVersion.api.minecraft.item.Item#getData()
The following examples show how to use
us.myles.ViaVersion.api.minecraft.item.Item#getData() .
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: ItemRewriterBase.java From ViaBackwards with MIT License | 5 votes |
protected CompoundTag createViaNBT(Item item) { CompoundTag tag = new CompoundTag(nbtTagName); tag.put(new ShortTag("id", (short) item.getIdentifier())); if (item.getAmount() != 1) { tag.put(new ByteTag("amount", item.getAmount())); } if (item.getData() != 0) { tag.put(new ShortTag("data", item.getData())); } if (item.getTag() != null) { tag.put(CONVERTER.convert("extras", CONVERTER.convert(item.getTag()))); } return tag; }
Example 2
Source File: ItemRewriter.java From ViaRewind with MIT License | 4 votes |
public static Item toClient(Item item) { if (item==null) return null; CompoundTag tag = item.getTag(); if (tag==null) item.setTag(tag = new CompoundTag("")); CompoundTag viaVersionTag = new CompoundTag("ViaRewind1_7_6_10to1_8"); tag.put(viaVersionTag); viaVersionTag.put(new ShortTag("id", (short) item.getIdentifier())); viaVersionTag.put(new ShortTag("data", item.getData())); CompoundTag display = tag.get("display"); if (display!=null && display.contains("Name")) { viaVersionTag.put(new StringTag("displayName", (String) display.get("Name").getValue())); } if (display!=null && display.contains("Lore")) { viaVersionTag.put(new ListTag("lore", ((ListTag)display.get("Lore")).getValue())); } if (tag.contains("ench") || tag.contains("StoredEnchantments")) { ListTag enchTag = tag.contains("ench") ? tag.get("ench") : tag.get("StoredEnchantments"); List<Tag> enchants = enchTag.getValue(); List<Tag> lore = new ArrayList<>(); for (Tag ench : enchants) { short id = (short) ((CompoundTag)ench).get("id").getValue(); short lvl = (short) ((CompoundTag)ench).get("lvl").getValue(); String s; if (id==8) { s = "§r§7Depth Strider "; } else { continue; } enchTag.remove(ench); s += Enchantments.ENCHANTMENTS.getOrDefault(lvl, "enchantment.level." + lvl); lore.add(new StringTag("", s)); } if (!lore.isEmpty()) { if (display==null) { tag.put(display = new CompoundTag("display")); viaVersionTag.put(new ByteTag("noDisplay")); } ListTag loreTag = display.get("Lore"); if (loreTag==null) display.put(loreTag = new ListTag("Lore", StringTag.class)); lore.addAll(loreTag.getValue()); loreTag.setValue(lore); } } if (item.getIdentifier()==387 && tag.contains("pages")) { ListTag pages = tag.get("pages"); ListTag oldPages = new ListTag("pages", StringTag.class); viaVersionTag.put(oldPages); for (int i = 0; i<pages.size(); i++) { StringTag page = pages.get(i); String value = page.getValue(); oldPages.add(new StringTag(page.getName(), value)); value = ChatUtil.jsonToLegacy(value); page.setValue(value); } } ReplacementRegistry1_7_6_10to1_8.replace(item); if (viaVersionTag.size()==2 && (short)viaVersionTag.get("id").getValue()==item.getIdentifier() && (short)viaVersionTag.get("data").getValue()==item.getData()) { item.getTag().remove("ViaRewind1_7_6_10to1_8"); if (item.getTag().isEmpty()) item.setTag(null); } return item; }
Example 3
Source File: BedRewriter.java From ViaVersion with MIT License | 4 votes |
public static void toClientItem(Item item) { if (item == null) return; if (item.getIdentifier() == 355 && item.getData() == 0) { item.setData((short) 14); } }
Example 4
Source File: BedRewriter.java From ViaVersion with MIT License | 4 votes |
public static void toServerItem(Item item) { if (item == null) return; if (item.getIdentifier() == 355 && item.getData() == 14) { item.setData((short) 0); } }
Example 5
Source File: ParticleMapping.java From ViaBackwards with MIT License | 4 votes |
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) { Item item = protocol.getBlockItemPackets().handleItemToClient(newItem); return new int[]{item.getIdentifier(), item.getData()}; }
Example 6
Source File: LegacyBlockItemRewriter.java From ViaBackwards with MIT License | 4 votes |
@Override @Nullable public Item handleItemToClient(Item item) { if (item == null) return null; MappedLegacyBlockItem data = replacementData.get(item.getIdentifier()); if (data == null) { // Just rewrite the id return super.handleItemToClient(item); } if (item.getTag() == null) { item.setTag(new CompoundTag("")); } // Backup data for toServer short originalData = item.getData(); item.getTag().put(createViaNBT(item)); item.setIdentifier(data.getId()); // Keep original data if mapped data is set to -1 if (data.getData() != -1) { item.setData(data.getData()); } // Set display name if (data.getName() != null) { CompoundTag tag = item.getTag().get("display"); if (tag == null) { item.getTag().put(tag = new CompoundTag("display")); } StringTag nameTag = tag.get("Name"); if (nameTag == null) { tag.put(nameTag = new StringTag("Name", data.getName())); } // Handle colors String value = nameTag.getValue(); if (value.contains("%vb_color%")) { tag.put(new StringTag("Name", value.replace("%vb_color%", BlockColors.get(originalData)))); } } return item; }