Class CustomBlock

java.lang.Object
com.github.darksoulq.abyssallib.world.block.CustomBlock
All Implemented Interfaces:
Cloneable

public class CustomBlock extends Object implements Cloneable
Represents a custom block type in the AbyssalLib framework.

This class defines the behavior, properties, and event hooks for custom blocks. To create a custom block, extend this class or use the default implementation with modified BlockProperties.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The physical and interaction properties of this block.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomBlock(net.kyori.adventure.key.Key id)
    Constructs a new CustomBlock with the given identifier.
    CustomBlock(net.kyori.adventure.key.Key id, org.bukkit.Material material)
    Constructs a new CustomBlock with the given identifier and base material.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Item
    Gets the Item associated with a CustomBlock type.
    Clones this custom block instance.
    createBlockEntity(org.bukkit.Location loc)
    Creates a new block entity instance for this block.
    boolean
    Compares this block to another object.
    boolean
    Checks if this block should generate a corresponding item.
    Gets the custom loot table for this block.
    Gets the active block entity.
    int
    getExpToDrop(org.bukkit.entity.Player player, int fortuneLevel, boolean silkTouch)
    Calculates the experience to drop based on block properties.
    net.kyori.adventure.key.Key
    Gets the unique identifier of this block.
    Provides the supplier for the item representation of this block.
    org.bukkit.Location
    Gets the location of this block.
    org.bukkit.Material
    Gets the base material of this block.
    int
    Generates a hash code for this block.
    boolean
    hasTag(net.kyori.adventure.key.Key id)
    Checks if this block possesses a specific tag.
    onBoneMeal(org.bukkit.entity.Player player)
    Called when the block is fertilized with Bone Meal.
    onBreak(org.bukkit.entity.Player player, org.bukkit.Location loc, org.bukkit.inventory.ItemStack tool)
    Called when the block is broken by a player.
    onDestroyedByExplosion(org.bukkit.entity.Entity eCause, org.bukkit.block.Block blockCause)
    Called when the block is destroyed by an explosion.
    onFade(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
    Called when the block fades (e.g.
    onForm(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
    Called when the block forms (e.g.
    onGrow(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
    Called when the block grows (e.g.
    onIgnite(org.bukkit.event.block.BlockIgniteEvent.IgniteCause cause, org.bukkit.entity.Entity ignitingEntity, org.bukkit.block.Block ignitingBlock)
    Called when the block ignites.
    Called when a player interacts with the block.
    void
    onLanded(org.bukkit.entity.Entity entity)
    Called when an entity lands on the block (fall damage calculation).
    Called when leaves decay.
    void
    Called when the block is loaded from disk.
    onNeighborUpdate(org.bukkit.block.Block source)
    Called when a neighbor block changes or a physics update occurs.
    onPistonMove(org.bukkit.block.BlockFace direction)
    Called when the block is moved by a piston.
    onPlace(org.bukkit.entity.Player player, org.bukkit.Location loc, org.bukkit.inventory.ItemStack stack)
    Called when the block is placed by a player.
    onProjectileHit(org.bukkit.entity.Projectile projectile)
    Called when a projectile hits the block.
    int
    onRedstone(int oldCurrent, int newCurrent)
    Called when the block receives a redstone update.
    onSignChange(org.bukkit.entity.Player player, org.bukkit.block.sign.Side side)
    Called when a sign is changed.
    onSpongeAbsorb(List<org.bukkit.block.BlockState> spongedBlocks)
    Called when a sponge absorbs water.
    onSpread(org.bukkit.block.Block block, org.bukkit.block.Block source, org.bukkit.block.BlockState newState)
    Called when the block spreads (e.g.
    void
    onSteppedOn(org.bukkit.entity.LivingEntity entity)
    Called when an entity steps onto the block.
    void
    Called when the block is unloaded (chunk unload or server stop).
    void
    place(org.bukkit.block.Block block, boolean loading)
    Places the block at the specified Bukkit block location.
    resolve(org.bukkit.block.Block block)
    Retrieves the CustomBlock instance associated with a Bukkit Block.
    resolve(org.bukkit.Location loc)
    Retrieves the CustomBlock instance at a specific location.
    void
    Sets the active block entity for this block instance.
    void
    setLocation(org.bukkit.Location location)
    Sets the location of this block.

    Methods inherited from class Object

    getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • properties

      public BlockProperties properties
      The physical and interaction properties of this block.
  • Constructor Details

    • CustomBlock

      public CustomBlock(net.kyori.adventure.key.Key id)
      Constructs a new CustomBlock with the given identifier.
      Parameters:
      id - the unique identifier
    • CustomBlock

      public CustomBlock(net.kyori.adventure.key.Key id, org.bukkit.Material material)
      Constructs a new CustomBlock with the given identifier and base material.
      Parameters:
      id - the unique identifier
      material - the base vanilla material
  • Method Details

    • getId

      public net.kyori.adventure.key.Key getId()
      Gets the unique identifier of this block.
      Returns:
      the block identifier
    • getMaterial

      public org.bukkit.Material getMaterial()
      Gets the base material of this block.
      Returns:
      the material
    • generateItem

      public boolean generateItem()
      Checks if this block should generate a corresponding item.
      Returns:
      true if an item should be generated
    • getItem

      public Supplier<Item> getItem()
      Provides the supplier for the item representation of this block.
      Returns:
      the item supplier
    • createBlockEntity

      public BlockEntity createBlockEntity(org.bukkit.Location loc)
      Creates a new block entity instance for this block. Override this to provide custom logic.
      Parameters:
      loc - the location of the block
      Returns:
      a new BlockEntity, or null
    • setEntity

      @Internal public void setEntity(BlockEntity entity)
      Sets the active block entity for this block instance.
      Parameters:
      entity - the entity to set
    • getLocation

      public org.bukkit.Location getLocation()
      Gets the location of this block.
      Returns:
      the location
    • setLocation

      public void setLocation(org.bukkit.Location location)
      Sets the location of this block.
      Parameters:
      location - the new location
    • getEntity

      public BlockEntity getEntity()
      Gets the active block entity.
      Returns:
      the entity, or null
    • place

      public void place(org.bukkit.block.Block block, boolean loading)
      Places the block at the specified Bukkit block location.
      Parameters:
      block - the target block
      loading - true if this is being loaded from disk, false if newly placed
    • getDrops

      public LootTable getDrops()
      Gets the custom loot table for this block.
      Returns:
      the loot table, or null
    • getExpToDrop

      public int getExpToDrop(org.bukkit.entity.Player player, int fortuneLevel, boolean silkTouch)
      Calculates the experience to drop based on block properties.
      Parameters:
      player - the player breaking the block
      fortuneLevel - the fortune enchantment level
      silkTouch - whether silk touch is used
      Returns:
      amount of XP to drop
    • hasTag

      public boolean hasTag(net.kyori.adventure.key.Key id)
      Checks if this block possesses a specific tag.
      Parameters:
      id - the tag identifier
      Returns:
      true if tagged
    • resolve

      public static CustomBlock resolve(org.bukkit.block.Block block)
      Retrieves the CustomBlock instance associated with a Bukkit Block.
      Parameters:
      block - the bukkit block
      Returns:
      the custom block, or null
    • resolve

      public static CustomBlock resolve(org.bukkit.Location loc)
      Retrieves the CustomBlock instance at a specific location.
      Parameters:
      loc - the location
      Returns:
      the custom block, or null
    • asItem

      public static Item asItem(CustomBlock block)
      Gets the Item associated with a CustomBlock type.
      Parameters:
      block - the custom block
      Returns:
      the item, or null
    • equals

      public boolean equals(Object o)
      Compares this block to another object.
      Overrides:
      equals in class Object
      Parameters:
      o - the other object
      Returns:
      true if equal
    • hashCode

      public int hashCode()
      Generates a hash code for this block.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • clone

      public CustomBlock clone()
      Clones this custom block instance.
      Returns:
      a clone of the block
    • onLoad

      public void onLoad()
      Called when the block is loaded from disk.
    • onUnLoad

      public void onUnLoad()
      Called when the block is unloaded (chunk unload or server stop).
    • onInteract

      public ActionResult onInteract(BlockInteractionEvent event)
      Called when a player interacts with the block.
      Parameters:
      event - the interaction event
      Returns:
      ActionResult to control the outcome
    • onPlace

      public ActionResult onPlace(org.bukkit.entity.Player player, org.bukkit.Location loc, org.bukkit.inventory.ItemStack stack)
      Called when the block is placed by a player.
      Parameters:
      player - the player
      loc - the location
      stack - the item stack used
      Returns:
      ActionResult
    • onBreak

      public ActionResult onBreak(org.bukkit.entity.Player player, org.bukkit.Location loc, org.bukkit.inventory.ItemStack tool)
      Called when the block is broken by a player.
      Parameters:
      player - the player
      loc - the location
      tool - the tool used
      Returns:
      ActionResult
    • onDestroyedByExplosion

      public ActionResult onDestroyedByExplosion(@Nullable org.bukkit.entity.Entity eCause, @Nullable org.bukkit.block.Block blockCause)
      Called when the block is destroyed by an explosion.
      Parameters:
      eCause - the entity that caused the explosion, if any
      blockCause - the block that caused the explosion, if any
      Returns:
      ActionResult
    • onLanded

      public void onLanded(org.bukkit.entity.Entity entity)
      Called when an entity lands on the block (fall damage calculation).
      Parameters:
      entity - the entity
    • onSteppedOn

      public void onSteppedOn(org.bukkit.entity.LivingEntity entity)
      Called when an entity steps onto the block.
      Parameters:
      entity - the entity
    • onRedstone

      public int onRedstone(int oldCurrent, int newCurrent)
      Called when the block receives a redstone update.
      Parameters:
      oldCurrent - previous signal strength
      newCurrent - new signal strength
      Returns:
      the adjusted signal strength
    • onProjectileHit

      public ActionResult onProjectileHit(org.bukkit.entity.Projectile projectile)
      Called when a projectile hits the block.
      Parameters:
      projectile - the projectile
      Returns:
      ActionResult
    • onNeighborUpdate

      public ActionResult onNeighborUpdate(org.bukkit.block.Block source)
      Called when a neighbor block changes or a physics update occurs.
      Parameters:
      source - the block causing the update
      Returns:
      ActionResult
    • onPistonMove

      public ActionResult onPistonMove(org.bukkit.block.BlockFace direction)
      Called when the block is moved by a piston.
      Parameters:
      direction - the direction of movement
      Returns:
      ActionResult
    • onBoneMeal

      public ActionResult onBoneMeal(org.bukkit.entity.Player player)
      Called when the block is fertilized with Bone Meal.
      Parameters:
      player - the player using bone meal
      Returns:
      ActionResult
    • onFade

      public ActionResult onFade(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
      Called when the block fades (e.g. ice melting).
      Parameters:
      block - the block instance
      newState - the state being transitioned to
      Returns:
      ActionResult
    • onForm

      public ActionResult onForm(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
      Called when the block forms (e.g. snow forming).
      Parameters:
      block - the block instance
      newState - the state being transitioned to
      Returns:
      ActionResult
    • onGrow

      public ActionResult onGrow(org.bukkit.block.Block block, org.bukkit.block.BlockState newState)
      Called when the block grows (e.g. crops).
      Parameters:
      block - the block instance
      newState - the state being transitioned to
      Returns:
      ActionResult
    • onIgnite

      public ActionResult onIgnite(org.bukkit.event.block.BlockIgniteEvent.IgniteCause cause, org.bukkit.entity.Entity ignitingEntity, org.bukkit.block.Block ignitingBlock)
      Called when the block ignites.
      Parameters:
      cause - the reason for ignition
      ignitingEntity - the entity causing ignition
      ignitingBlock - the block causing ignition
      Returns:
      ActionResult
    • onSpread

      public ActionResult onSpread(org.bukkit.block.Block block, org.bukkit.block.Block source, org.bukkit.block.BlockState newState)
      Called when the block spreads (e.g. fire, mushrooms).
      Parameters:
      block - the block instance
      source - the source of the spread
      newState - the state being transitioned to
      Returns:
      ActionResult
    • onLeavesDecay

      public ActionResult onLeavesDecay()
      Called when leaves decay.
      Returns:
      ActionResult
    • onSpongeAbsorb

      public ActionResult onSpongeAbsorb(List<org.bukkit.block.BlockState> spongedBlocks)
      Called when a sponge absorbs water.
      Parameters:
      spongedBlocks - the list of affected block states
      Returns:
      ActionResult
    • onSignChange

      public ActionResult onSignChange(org.bukkit.entity.Player player, org.bukkit.block.sign.Side side)
      Called when a sign is changed.
      Parameters:
      player - the player changing the sign
      side - the side of the sign affected
      Returns:
      ActionResult