use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class PotionItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.COLOR).get(h -> Color.ofRgb(PotionUtils.getColor(h))).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTag();
tag.putInt(Constants.Item.CUSTOM_POTION_COLOR, v.rgb());
}).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_COLOR)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION).create(Keys.POTION_EFFECTS).get(h -> {
final List<MobEffectInstance> effects = PotionUtils.getMobEffects(h);
return effects.isEmpty() ? null : ImmutableList.copyOf((List<PotionEffect>) (Object) effects);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTag();
final ListTag list = v.stream().map(effect -> {
final CompoundTag potionTag = new CompoundTag();
((MobEffectInstance) effect).save(potionTag);
return potionTag;
}).collect(NBTCollectors.toTagList());
tag.put(Constants.Item.CUSTOM_POTION_EFFECTS, list);
}).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_EFFECTS)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW).create(Keys.POTION_TYPE).get(h -> (PotionType) PotionUtils.getPotion(h)).set((h, v) -> {
h.getOrCreateTag();
PotionUtils.setPotion(h, (Potion) v);
}).delete(h -> {
if (h.hasTag()) {
PotionUtils.setPotion(h, Potions.EMPTY);
}
}).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW);
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class BlockTypeItemStackData method get.
// @formatter:on
private static Set<BlockType> get(final ItemStack stack, final String nbtKey) {
final CompoundTag tag = stack.getTag();
if (tag == null) {
return null;
}
final ListTag list = tag.getList(nbtKey, Constants.NBT.TAG_STRING);
if (list.isEmpty()) {
return null;
}
return NBTStreams.toStrings(list).map(ResourceLocation::tryParse).filter(Objects::nonNull).map(key -> (BlockType) Registry.BLOCK.getOptional(key).orElse(null)).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of net.minecraft.nbt.ListTag in project MinecraftForge by MinecraftForge.
the class IForgeMobEffectInstance method writeCurativeItems.
default void writeCurativeItems(CompoundTag nbt) {
ListTag list = new ListTag();
getCurativeItems().forEach(s -> list.add(s.save(new CompoundTag())));
nbt.put("CurativeItems", list);
}
use of net.minecraft.nbt.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method getLore.
@Override
public List<String> getLore(ItemTag item) {
if (!item.getItemMeta().hasLore()) {
return null;
}
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
ListTag list = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getList("Lore", 8);
List<String> outList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
BaseComponent[] lineComponent = ComponentSerializer.parse(list.getString(i));
outList.add(FormattedTextHelper.stringify(lineComponent, ChatColor.WHITE));
}
return outList;
}
use of net.minecraft.nbt.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method setLore.
@Override
public void setLore(ItemTag item, List<String> lore) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
net.minecraft.nbt.CompoundTag tag = nmsItemStack.getOrCreateTag();
net.minecraft.nbt.CompoundTag display = tag.getCompound("display");
if (!tag.contains("display")) {
tag.put("display", display);
}
if (lore == null || lore.isEmpty()) {
display.put("Lore", null);
} else {
ListTag tagList = new ListTag();
for (String line : lore) {
tagList.add(net.minecraft.nbt.StringTag.valueOf(ComponentSerializer.toString(FormattedTextHelper.parse(line, ChatColor.WHITE))));
}
display.put("Lore", tagList);
}
item.setItemStack(CraftItemStack.asBukkitCopy(nmsItemStack));
}
Aggregations