Java Code Examples for us.myles.ViaVersion.api.minecraft.item.Item#setData()
The following examples show how to use
us.myles.ViaVersion.api.minecraft.item.Item#setData() .
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: ItemType.java From ViaRewind with MIT License | 5 votes |
@Override public Item read(ByteBuf buffer) throws Exception { int readerIndex = buffer.readerIndex(); short id = buffer.readShort(); if (id < 0) { return null; } Item item = new Item(); item.setIdentifier(id); item.setAmount(buffer.readByte()); item.setData(buffer.readShort()); item.setTag((compressed ? Types1_7_6_10.COMPRESSED_NBT : Types1_7_6_10.NBT).read(buffer)); return item; }
Example 2
Source File: ItemRewriter.java From ViaRewind with MIT License | 5 votes |
public static Item toServer(Item item) { if (item==null) return null; CompoundTag tag = item.getTag(); if (tag==null || !item.getTag().contains("ViaRewind1_7_6_10to1_8")) return item; CompoundTag viaVersionTag = tag.remove("ViaRewind1_7_6_10to1_8"); item.setIdentifier((short) viaVersionTag.get("id").getValue()); item.setData((Short) viaVersionTag.get("data").getValue()); if (viaVersionTag.contains("noDisplay")) tag.remove("display"); if (viaVersionTag.contains("displayName")) { CompoundTag display = tag.get("display"); if (display==null) tag.put(display = new CompoundTag("display")); StringTag name = display.get("Name"); if (name==null) display.put(new StringTag("Name", (String) viaVersionTag.get("displayName").getValue())); else name.setValue((String) viaVersionTag.get("displayName").getValue()); } else if (tag.contains("display")) { ((CompoundTag)tag.get("display")).remove("Name"); } if (item.getIdentifier()==387) { ListTag oldPages = viaVersionTag.get("pages"); tag.remove("pages"); tag.put(oldPages); } return item; }
Example 3
Source File: ItemType.java From ViaVersion with MIT License | 5 votes |
@Override public Item read(ByteBuf buffer) throws Exception { short id = buffer.readShort(); if (id < 0) { return null; } else { Item item = new Item(); item.setIdentifier(id); item.setAmount(buffer.readByte()); item.setData(buffer.readShort()); item.setTag(Type.NBT.read(buffer)); return item; } }
Example 4
Source File: ItemRewriterBase.java From ViaBackwards with MIT License | 5 votes |
@Nullable public Item handleItemToServer(Item item) { if (item == null) return null; CompoundTag tag = item.getTag(); if (tag == null) { if (toServerRewriter != null) { item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier())); } return item; } CompoundTag viaTag = tag.remove(nbtTagName); if (viaTag != null) { short id = (short) viaTag.get("id").getValue(); item.setIdentifier(id); Tag dataTag = viaTag.get("data"); short data = dataTag != null ? (short) dataTag.getValue() : 0; item.setData(data); Tag amountTag = viaTag.get("amount"); byte amount = amountTag != null ? (byte) amountTag.getValue() : 1; item.setAmount(amount); CompoundTag extras = viaTag.get("extras"); if (extras != null) { item.setTag(CONVERTER.convert("", CONVERTER.convert(extras))); } } else { // Rewrite id normally if (toServerRewriter != null) { item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier())); } } return item; }
Example 5
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 6
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 7
Source File: BlockItemPackets1_13.java From ViaBackwards with MIT License | 4 votes |
@Override public Item handleItemToClient(Item item) { if (item == null) return null; // Custom mappings/super call moved down int originalId = item.getIdentifier(); Integer rawId = null; boolean gotRawIdFromTag = false; CompoundTag tag = item.getTag(); // Use tag to get original ID and data Tag originalIdTag; if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) { rawId = (Integer) originalIdTag.getValue(); gotRawIdFromTag = true; } if (rawId == null) { // Look for custom mappings super.handleItemToClient(item); // No custom mapping found, look at VV mappings if (item.getIdentifier() == originalId) { int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); if (oldId != -1) { rawId = itemIdToRaw(oldId, item, tag); } else if (item.getIdentifier() == 362) { // base/colorless shulker box rawId = 0xe50000; // purple shulker box } else { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("Failed to get 1.12 item for " + originalId); } rawId = 0x10000; } } else { // Use the found custom mapping // Take the newly added tag if (tag == null) { tag = item.getTag(); } rawId = itemIdToRaw(item.getIdentifier(), item, tag); } } item.setIdentifier(rawId >> 16); item.setData((short) (rawId & 0xFFFF)); // NBT changes if (tag != null) { if (isDamageable(item.getIdentifier())) { Tag damageTag = tag.remove("Damage"); if (!gotRawIdFromTag && damageTag instanceof IntTag) { item.setData((short) (int) damageTag.getValue()); } } if (item.getIdentifier() == 358) { // map Tag mapTag = tag.remove("map"); if (!gotRawIdFromTag && mapTag instanceof IntTag) { item.setData((short) (int) mapTag.getValue()); } } // Shield and banner invertShieldAndBannerId(item, tag); // Display Name now uses JSON CompoundTag display = tag.get("display"); if (display != null) { StringTag name = display.get("Name"); if (name instanceof StringTag) { StringTag via = display.remove(extraNbtTag + "|Name"); name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue())); } } // ench is now Enchantments and now uses identifiers rewriteEnchantmentsToClient(tag, false); rewriteEnchantmentsToClient(tag, true); rewriteCanPlaceToClient(tag, "CanPlaceOn"); rewriteCanPlaceToClient(tag, "CanDestroy"); } return item; }
Example 8
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; }