Custom Block

Methods in CustomBlock class you should know :

This will be the metadata string to identify your block.

If you do not set it or if it is already taken it will be generated randomly

Use getIdentifier() and setIdentifier(String identifier)

  • String identifier;

This is the name of this custom block

Use getName() and setName(String name)

  • String name = "Custom Block";

This is the id of the block, it will render to and by default its properties such as hardness, physics ... but you can manually change them

Use getBlockID() and setBlockID(int id)

  • int id = 1;

This is the maximum amount of a stack size

Use getMaxStackSize() and setMaxStackSize(int max)

  • int maxStackSize = 64;

All the locs where this block has been placed

you should not modify it to avoid persistence fails

Use getLocs() and addLocation(Location loc) and removeLocation(Location location)

Every time you create or remove a custom block without using one of these API methods you should add/remove the loc, it's use for persistence beetween reloads

  • ArrayList<Location> locs = new ArrayList<Location>();

You should set its identifier and name because if not it's a random identifier and the default name

  • public CustomBlock()

EVENTS

Fired when this block is placed Should not be overriden because it adds this block to locs

  • public void place(BlockPlaceEvent event)

Fired when this block is placed Should not be overriden because it handles block destruction out of the event

  • public void destroy(BlockBreakEvent event)

Fired when this block is powered by redstone

  • public void power(BlockRedstoneEvent event)

Fired when this block has burnt

  • public void burn(BlockBurnEvent event)

Fired when this block is burning

  • public void burning(BlockIgniteEvent event)

Fired when this block is damaged by a player ( Forgot in v2.0 : it will never fire )

  • public void damage(BlockDamageEvent event)

Fired when a player walk on this block

  • public void walk(PlayerMoveEvent event)

Fired when a player left click on this block

  • public void leftClick(PlayerInteractEvent event)

Fired when a vehicle collide with this block

  • public void collide(VehicleBlockCollisionEvent event)

Fired when this block was destroyed by an explosion @param block is the block that matches to this custom block

So if two are destroyed, this event will fire 2 times separately Should not be overriden because we remove the Location of our block

  • public void exploded(EntityExplodeEvent event, Block block)

Fired when a player right click on this block

  • public void rightClick(PlayerInteractEvent event)

Fired when an hanging is placed on this block

  • public void hanging_placed(HangingPlaceEvent event)

Fired when a projectile hit this block

  • public void projectile_hit(ProjectileHitEvent event)

Fired when some physics concern this custom block e.g: like when a sand block falls

  • public void physics(BlockPhysicsEvent event)

END EVENTS

This method handle the block placement Schould not be overriden

  • public void tryToPlace(PlayerInteractEvent event, BlockAPI plugin);

Check if a block match to this custom block

  • public boolean equals(Block block);

BlockAPI methods

Return an arraylist that contains all the custom blocks

  • public ArrayList<CustomBlock> getCustomBlocks()

Add your own custom block

  • public boolean addMyCustomBlock(CustomBlock block)

Add your own custom blocks

@return the number of attempt that failed

  • public int addMyCustomBlocks(List<CustomBlock> blockList)

Get the custom block with the specified identifier. If none was found return null

  • public CustomBlock getCustomBlock(String identifier)

Get the custom block from its name If none was found return null

  • private CustomBlock getCustomBlockFromName(String name)

Get the custom block from a book item If none match return null

  • public CustomBlock getCustomBlock(ItemStack item)

Get the custom block of this block. If none was found return null

  • public CustomBlock getCustomBlock(Block block)

Check if a specified identifier is taken if you will use your metadata value for some stuff then

you should check if your identifier is taken

  • public boolean isIdTaken(String identifier)

STATIC METHODS

Change that given block to the given custom block

  • public static Block createBlock(CustomBlock cblock, Block block)

Get a book that will match to the format of this custom block

  • public static ItemStack getBook(CustomBlock block)

Get the amount of a custom block that is represented as a book

  • public static int getCustomBlockAmount(ItemStack item)

Change the amount of a custom block that is represented as a book

  • public static ItemStack setCustomBlockAmount(ItemStack item, int amount) }

Comments

Posts Quoted:
Reply
Clear All Quotes