-
Notifications
You must be signed in to change notification settings - Fork 0
BlockSettings
Every block needs some settings to control how it is controlled and displayed in the world.
There are two different types of blocks that can be created with this api. Blocks with and without a base block.
When you create a block with a base block, your custom block inherits the properties of the base block. These mainly include hitbox, blast resistance, break speed, optimal tool, etc. These cannot be changed, so you should be aware of which block you choose.
Example: If you don't want the block to be destroyed by explosions, you should probably use an obsidian block as the base block instead of a foliage block.
These blocks use AIR as their base material, so you can walk through them. To detect interactions or attacks, these blocks spawn an additional interaction entity to detect these events. This makes them a little heavier on the server side. Unlike blocks with a basic block, blocks without a basic block can define their own size. This makes it possible to create blocks that are, for example, 1.5 blocks high without placing two different blocks in the world. They are also broken instantly when left clicked once.
To create the Settings object that is passed to your block you can use the BlockSettingsBuilder builder class. You can either create an empty builder or copy the settings of another custom block.
BlockSettingsBuilder.empty() // Create an empty BlockSettingsBuilder with the default values
BlockSettingsBuilder.of(EXAMPLE_BLOCK) // Create a BlockSettingsBuilder that copies the values of another block-
setBaseBlock(Material)(Default:Material.STONE): Sets the Base block of your custom block. Ignore when creating a block without a base block -
noBaseBlock(boolean)(Default:false): Set to true if you want to create a block without a base block. Ignore otherwise -
displayMaterial(Material)(Default:Material.STICK): This defines the item that displays the custom model of the block -
breakInstantly(boolean)(Default:false): Whether or not the block should be instantly broken on attack. True for block with no base -
setName(String)(Default:Block#xxxx): The Custom name of the block that is used in error messages and messages in general -
setSize(float, float)(Default:1, 1): The custom size of the block. Only works for values > 0 and only of the block has no base -
setDropsWhenExploded(boolean)(Default:true): Whether the block drops it's drops when being exploded -
setPlaceSound(Sound)(Default:Sound.BLOCK_STONE_PLACE): The sound that is played when placing the block. Only works if the place item is an actual item -
setBreakSound(Sound)(Default:Sound.BLOCK_STONE_PLACE): The sound that is played when a block with no base is broken -
setUsesNeighborUpdateEvent(Default:false): Whether the block can listen for block updates. This is much more expensive, because the API must listen to all block changes in the world -
setUsesEntityMovementEvent(Default:false): Whether the block should listen for entities moving above it. This is much more expensive, since the API must listen for all motion events in the world