Modify Blocks

The basic recipe for a block object in Minecraft is listed in the Canary documentation under net.canarymod.api.world.blocks.Block.[31]

There are many interesting functions in a Block, and we won’t cover them all, but here are a few of the most useful and interesting things you can do to a block:

  • getLocation() returns the Location for this block. Only one block can exist at any location in the world, and every location contains a block, even if it’s just air.

  • getType() returns the BlockType this block is made of.

  • rightClick(Player player) simulates a right-click on the block. Useful for forcing changes to blocks like levers, buttons, and doors.

Let’s play with some blocks, Minecraft style.

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.