Making simple block
Well, basicly making a block is like making a custom item. Custom block has CustomBlockData that defines important information about our block.
Placed blocks represented as PlacedBlockData that contain location of this block, UUID, UUID of his owner (can be null) and item that used to place this block.
All events contain PlacedBlockData and bukkit event itself for more control. Most events can be cancelled.
Making new class
Create new class, after that implement a CustomBlock
interface and override blockData
method. blockData method require to return CustomBlockData which contains: Item that represents this block, blockID, material of this block. For work you need that item material and material of block was a block (Material#isBlock
).
Example:
public class MyFirstBlock implements CustomBlock {
@Override
public @NotNull CustomBlockData blockData() {
return new CustomBlockData(
CustomItemManager.getItemByID("itemforblock"), // CItem
"testcustomblock", // Block ID
Material.DARK_OAK_LOG // Material of block
);
}
}
And thats all.
Register custom block
Same thing like custom items. Just use CustomBlockManager for register, getting, placing custom blocks.
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Register our item first
CustomItemManager.register(new TestItemForBlock());
// Register our block AFTER our item was registered.
CustomBlockManager.register(new MyFirstBlock());
}
}
Done! Give yourself your item that represents your block and place it. You can do it with /citem
command.
Last updated
Was this helpful?