Class ComponentMap
java.lang.Object
com.github.darksoulq.abyssallib.world.item.component.ComponentMap
Stores and manages
DataComponents for an item or entity.
Components are loaded lazily from Minecraft's data components or custom NBT,
then cached in memory. Changes can be written back to the underlying item or
entity using applyData().
-
Constructor Summary
ConstructorsConstructorDescriptionComponentMap(CustomEntity<? extends org.bukkit.entity.LivingEntity> entity) Constructs a ComponentMap for a specific custom Entity.ComponentMap(Item item) Constructs a ComponentMap for a specific custom Item.ComponentMap(org.bukkit.inventory.ItemStack stack) Constructs a ComponentMap by wrapping a Bukkit ItemStack. -
Method Summary
Modifier and TypeMethodDescriptionvoidWrites all components back to the associated item or entity.static <T,D> D encodeComponent(DataComponent<T> component, DynamicOps<D> ops) Encodes a component using the givenDynamicOps.List<DataComponent<?>> Returns every loaded component.<C extends DataComponent<?>>
CgetData(DataComponentType<C> type) Returns the component of the given type.booleanhasData(DataComponentType<?> type) Returns whether this map contains the given component type.voidload()Loads all components if they have not already been loaded.voidLoads all custom components from the associated entity.voidloadItem()Loads all components from the associated item.voidremoveData(DataComponentType<?> type) Removes a component and updates the underlying item or entity.voidsetData(DataComponent<?> component) Adds or replaces a component and applies the change immediately.
-
Constructor Details
-
ComponentMap
public ComponentMap(org.bukkit.inventory.ItemStack stack) Constructs a ComponentMap by wrapping a Bukkit ItemStack.- Parameters:
stack- TheItemStackto load components from.
-
ComponentMap
Constructs a ComponentMap for a specific custom Item.- Parameters:
item- TheIteminstance.
-
ComponentMap
Constructs a ComponentMap for a specific custom Entity.- Parameters:
entity- TheCustomEntityinstance.
-
-
Method Details
-
load
public void load()Loads all components if they have not already been loaded. -
loadItem
public void loadItem()Loads all components from the associated item.Vanilla components are read from Paper's data component API, while custom components are loaded from the
CustomComponentsNBT tag. -
loadEntity
public void loadEntity()Loads all custom components from the associated entity. -
setData
Adds or replaces a component and applies the change immediately.- Parameters:
component- the component to store
-
removeData
Removes a component and updates the underlying item or entity.- Parameters:
type- the component type
-
getData
Returns the component of the given type.- Parameters:
type- the component type- Returns:
- the component, or
nullif it is not present
-
hasData
Returns whether this map contains the given component type.- Parameters:
type- the component type- Returns:
trueif the component exists
-
applyData
public void applyData()Writes all components back to the associated item or entity.Vanilla components are applied through Paper's API, while custom components are serialized into the
CustomComponentsNBT tag. -
getAllComponents
Returns every loaded component.- Returns:
- all components in this map
-
encodeComponent
Encodes a component using the givenDynamicOps.- Type Parameters:
T- the component value typeD- the serialized data type- Parameters:
component- the component to encodeops- the target serialization format- Returns:
- the encoded value
-