Skip to content

Commit

Permalink
Fix offering potion effects for item stack
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Dec 18, 2023
1 parent b5a08a1 commit 726f7dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import com.google.common.collect.ImmutableList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand All @@ -39,9 +38,9 @@
import org.spongepowered.api.util.Color;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
import org.spongepowered.common.util.Constants;
import org.spongepowered.common.util.NBTCollectors;

import java.util.List;
import java.util.stream.Collectors;

@SuppressWarnings("unchecked")
public final class PotionItemStackData {
Expand All @@ -67,15 +66,10 @@ public static void register(final DataProviderRegistrator registrator) {
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);
h.removeTagKey(Constants.Item.CUSTOM_POTION_EFFECTS);
PotionUtils.setCustomEffects(h, v.stream()
.map(MobEffectInstance.class::cast)
.collect(Collectors.toList()));
})
.delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_EFFECTS))
.supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public static final class Item {
public static final String ITEM_UNBREAKABLE = "Unbreakable";
public static final String CUSTOM_MODEL_DATA = "CustomModelData";
public static final String CUSTOM_POTION_COLOR = "CustomPotionColor";
public static final String CUSTOM_POTION_EFFECTS = "CustomPotionEffects";
public static final String CUSTOM_POTION_EFFECTS = "custom_potion_effects";
public static final String LOCK = "Lock";

public static final class Book {
Expand Down

0 comments on commit 726f7dc

Please sign in to comment.