Class SpawnEggBuilder

java.lang.Object
io.github.lucfr1746.llibrary.itemstack.ItemBuilder
io.github.lucfr1746.llibrary.itemstack.SpawnEggBuilder

public class SpawnEggBuilder extends ItemBuilder
The SpawnEggBuilder class extends ItemBuilder to provide additional functionality for modifying SpawnEggMeta of an ItemStack. This includes setting custom spawned entities and manipulating persistent data.
  • Constructor Details

    • SpawnEggBuilder

      public SpawnEggBuilder(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Constructs a SpawnEggBuilder using an existing ItemStack.
      Parameters:
      itemStack - the item stack to modify
      Throws:
      IllegalArgumentException - if the item is not a spawn egg
    • SpawnEggBuilder

      public SpawnEggBuilder(@NotNull @NotNull org.bukkit.entity.EntityType entityType, int amount)
      Constructs a SpawnEggBuilder with the specified EntityType. Automatically select the appropriate spawn egg material based on the entity type.
      Parameters:
      entityType - the type of entity the spawn egg will spawn
      amount - the quantity of spawn eggs in the stack
      Throws:
      IllegalArgumentException - if no spawn egg material is found for the entity type
  • Method Details

    • setSpawnedEntity

      public SpawnEggBuilder setSpawnedEntity(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Sets the entity snapshot for the spawn egg. The spawned entity will retain the state defined by the provided entity's snapshot.
      Parameters:
      entity - the entity to create a snapshot from
      Returns:
      this SpawnEggBuilder instance for chaining
    • getSpawnedEntityType

      @Nullable public @Nullable org.bukkit.entity.EntityType getSpawnedEntityType()
      Gets the entity type associated with the spawn egg.
      Returns:
      the EntityType the spawn egg will spawn, or null if not set
    • modifyPersistentData

      public SpawnEggBuilder modifyPersistentData(@NotNull @NotNull Consumer<org.bukkit.persistence.PersistentDataContainer> action)
      Modifies the persistent data container of the spawn egg. This allows adding custom NBT data or modifying existing tags.
      Parameters:
      action - a Consumer that accepts the spawn egg's PersistentDataContainer
      Returns:
      this SpawnEggBuilder instance for chaining