Add ItemStack#copyDataFrom (#12224)
This commit is contained in:
@ -79,7 +79,7 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
|
||||
RegistryKey<BlockType> BLOCK = create("block");
|
||||
/**
|
||||
* @apiNote use preferably only in the context of registry entries.
|
||||
* @see io.papermc.paper.registry.data
|
||||
* @see io.papermc.paper.registry.keys.ItemTypeKeys
|
||||
*/
|
||||
@ApiStatus.Experimental // Paper - already required for registry builders
|
||||
RegistryKey<ItemType> ITEM = create("item");
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -1306,6 +1307,31 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
||||
this.craftDelegate.resetData(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies component values and component removals from the provided ItemStack.
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>{@code
|
||||
* Set<DataComponentType> types = Set.of(
|
||||
* DataComponentTypes.CONSUMABLE,
|
||||
* DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE,
|
||||
* DataComponentTypes.RARITY
|
||||
* );
|
||||
*
|
||||
* ItemStack source = ItemStack.of(Material.ENCHANTED_GOLDEN_APPLE);
|
||||
* ItemStack target = ItemStack.of(Material.GOLDEN_CARROT);
|
||||
*
|
||||
* target.copyDataFrom(source, types::contains);
|
||||
* }</pre>
|
||||
*
|
||||
* @param source the item stack to copy from
|
||||
* @param filter predicate for which components to copy
|
||||
*/
|
||||
@org.jetbrains.annotations.ApiStatus.Experimental
|
||||
public void copyDataFrom(final @NotNull ItemStack source, final @NotNull Predicate<io.papermc.paper.datacomponent.@NotNull DataComponentType> filter) {
|
||||
this.craftDelegate.copyDataFrom(source, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the data component type is overridden from the default for the
|
||||
* item type.
|
||||
|
||||
Reference in New Issue
Block a user