use of org.spongepowered.api.item.potion.PotionType in project Sponge 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 org.spongepowered.api.item.potion.PotionType 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);
}
Aggregations