Class CustomBlock
java.lang.Object
com.github.darksoulq.abyssallib.world.block.CustomBlock
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
FieldsModifier and TypeFieldDescriptionThe physical and interaction properties of this block. -
Constructor Summary
ConstructorsConstructorDescriptionCustomBlock(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 TypeMethodDescriptionstatic ItemasItem(CustomBlock block) Gets the Item associated with a CustomBlock type.clone()Clones this custom block instance.createBlockEntity(org.bukkit.Location loc) Creates a new block entity instance for this block.booleanCompares this block to another object.booleanChecks if this block should generate a corresponding item.getDrops()Gets the custom loot table for this block.Gets the active block entity.intgetExpToDrop(org.bukkit.entity.Player player, int fortuneLevel, boolean silkTouch) Calculates the experience to drop based on block properties.net.kyori.adventure.key.KeygetId()Gets the unique identifier of this block.getItem()Provides the supplier for the item representation of this block.org.bukkit.LocationGets the location of this block.org.bukkit.MaterialGets the base material of this block.inthashCode()Generates a hash code for this block.booleanhasTag(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.onInteract(BlockInteractionEvent event) Called when a player interacts with the block.voidonLanded(org.bukkit.entity.Entity entity) Called when an entity lands on the block (fall damage calculation).Called when leaves decay.voidonLoad()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.voidCalled during a random world tick.intonRedstone(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.voidonSteppedOn(org.bukkit.entity.LivingEntity entity) Called when an entity steps onto the block.voidonTick()Called every server tick.voidonUnLoad()Called when the block is unloaded (chunk unload or server stop).voidplace(org.bukkit.block.Block block, boolean loading) Places the block at the specified Bukkit block location.voidplaceForWorldGen(org.bukkit.block.Block block) Places the block at the specified Bukkit block location during world generation.static CustomBlockresolve(org.bukkit.block.Block block) Retrieves the CustomBlock instance associated with a Bukkit Block.static CustomBlockresolve(org.bukkit.Location loc) Retrieves the CustomBlock instance at a specific location.voidsetEntity(BlockEntity entity) Sets the active block entity for this block instance.voidsetLocation(org.bukkit.Location location) Sets the location of this block.
-
Field Details
-
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 identifiermaterial- 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
-
createBlockEntity
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
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.- Specified by:
getLocationin interfaceLocatable- Returns:
- the location
-
setLocation
public void setLocation(org.bukkit.Location location) Sets the location of this block.- Parameters:
location- the new location
-
getEntity
-
place
public void place(org.bukkit.block.Block block, boolean loading) Places the block at the specified Bukkit block location.- Parameters:
block- the target blockloading- true if this is being loaded from disk, false if newly placed
-
placeForWorldGen
public void placeForWorldGen(org.bukkit.block.Block block) Places the block at the specified Bukkit block location during world generation. This bypasses all chunk-loading event triggers and regional tick scheduling, allowing the block to remain dormant until naturally loaded by the server.- Parameters:
block- the target block
-
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 blockfortuneLevel- the fortune enchantment levelsilkTouch- 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
Retrieves the CustomBlock instance associated with a Bukkit Block.- Parameters:
block- the bukkit block- Returns:
- the custom block, or null
-
resolve
Retrieves the CustomBlock instance at a specific location.- Parameters:
loc- the location- Returns:
- the custom block, or null
-
asItem
Gets the Item associated with a CustomBlock type.- Parameters:
block- the custom block- Returns:
- the item, or null
-
equals
-
hashCode
-
clone
-
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). -
onTick
public void onTick()Called every server tick. Override to provide active logic. -
onRandomTick
public void onRandomTick()Called during a random world tick. -
onInteract
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 playerloc- the locationstack- 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 playerloc- the locationtool- 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 anyblockCause- 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 strengthnewCurrent- new signal strength- Returns:
- the adjusted signal strength
-
onProjectileHit
Called when a projectile hits the block.- Parameters:
projectile- the projectile- Returns:
- ActionResult
-
onNeighborUpdate
Called when a neighbor block changes or a physics update occurs.- Parameters:
source- the block causing the update- Returns:
- ActionResult
-
onPistonMove
Called when the block is moved by a piston.- Parameters:
direction- the direction of movement- Returns:
- ActionResult
-
onBoneMeal
Called when the block is fertilized with Bone Meal.- Parameters:
player- the player using bone meal- Returns:
- ActionResult
-
onFade
Called when the block fades (e.g. ice melting).- Parameters:
block- the block instancenewState- the state being transitioned to- Returns:
- ActionResult
-
onForm
Called when the block forms (e.g. snow forming).- Parameters:
block- the block instancenewState- the state being transitioned to- Returns:
- ActionResult
-
onGrow
Called when the block grows (e.g. crops).- Parameters:
block- the block instancenewState- 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 ignitionignitingEntity- the entity causing ignitionignitingBlock- 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 instancesource- the source of the spreadnewState- the state being transitioned to- Returns:
- ActionResult
-
onLeavesDecay
-
onSpongeAbsorb
Called when a sponge absorbs water.- Parameters:
spongedBlocks- the list of affected block states- Returns:
- ActionResult
-
onSignChange
Called when a sign is changed.- Parameters:
player- the player changing the signside- the side of the sign affected- Returns:
- ActionResult
-