All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.block.IBlock.kt Maven / Gradle / Ivy

package walkmc.block

import org.bukkit.*
import org.bukkit.block.*
import org.bukkit.entity.*
import org.bukkit.inventory.*
import walkmc.extensions.*
import walkmc.interfaces.*
import walkmc.serializer.tag.impl.*

/**
 * Represents a custom block.
 *
 * Custom blocks can have special behavior from a block in the world.
 */
interface IBlock : Localizable {
	
	/**
	 * Returns the event information of this custom block.
	 */
	var info: BlockInfo
	
	/**
	 * Returns the block instance of this custom block.
	 */
	var block: Block
	
	/**
	 * Returns the world instance of this custom block.
	 */
	var world: World
	
	/**
	 * Returns the amount of ticks that have been executed.
	 */
	var ticks: Int
	
	/**
	 * Called when this custom block is registered.
	 *
	 * You can use this to set up data.
	 */
	fun onRegister()
	
	/**
	 * Called when this custom block ticks.
	 */
	fun onTick()
	
	/**
	 * Called when a player interacts with this custom block.
	 */
	fun onInteract(player: Player, click: Click)
	
	/**
	 * Called when a player breaks this custom block.
	 */
	fun onBreak(player: Player)
	
	/**
	 * Called when a player places this custom block.
	 *
	 * This will only be called if [item] is a part of custom block,
	 * this is, if the item has *BlockClass* tag.
	 *
	 * You can set up a custom block item by [getItem] or [setCustomBlockPart].
	 */
	fun onPlace(player: Player, item: ItemStack)
	
	/**
	 * Called when a player moves above in this custom block.
	 */
	fun onMove(player: Player)
	
	/**
	 * Called when an entity steps in this custom block.
	 */
	fun onStep(entity: Entity)
	
	/**
	 * Called when an entity jumps above this custom block.
	 */
	fun onJump(entity: Entity)
	
	/**
	 * Called when an entity falls in this custom block.
	 */
	fun onFall(entity: Entity)
	
	/**
	 * Called when an entity collides with this custom block.
	 */
	fun onCollide(entity: Entity)
	
	/**
	 * Called when a physics block check is made by the server.
	 */
	fun doPhysics()
	
	/**
	 * Returns the item used to place this custom block.
	 */
	fun getItem(): ItemStack
	
	/**
	 * Load all data of this custom block from tag.
	 */
	fun loadData(tag: CompoundTag)
	
	/**
	 * Saves all data of this cusstom block to tag.
	 */
	fun saveData(tag: CompoundTag)
	
	/**
	 * Event handler call for on load this custom block.
	 */
	fun onLoad()
	
	/**
	 * Event handler call for on enable this custom block.
	 */
	fun onEnable()
	
	/**
	 * Event handler call for on disable this custom block.
	 */
	fun onDisable()
	
	/**
	 * Register this custom block.
	 *
	 * Applying the [position] as key and this as value in the custom block map.
	 */
	fun register() {
		block.customBlock = this
	}
	
	/**
	 * Unregister this custom block.
	 *
	 * Removing the [position] key in the custom block map.
	 */
	fun unregister() {
		block.removeCustomBlock()
	}
	
	/**
	 * Applies the necessary data tag used to verify if an item stack
	 * is part from a custom block item.
	 */
	fun ItemStack.setCustomBlockPart(): ItemStack {
		applyTag { setClass("BlockClass", [email protected]) }
		return this
	}
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy