tutorial:blocks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:blocks [2023/11/18 08:34] – solidblock | tutorial:blocks [2024/04/15 01:52] (current) – [Custom Shape] solidblock | ||
---|---|---|---|
Line 19: | Line 19: | ||
You can find the stats of all vanilla blocks in the class `Blocks`, where you can also reference other blocks. | You can find the stats of all vanilla blocks in the class `Blocks`, where you can also reference other blocks. | ||
*/ | */ | ||
- | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | + | |
- | public static final Block EXAMPLE_BLOCK | + | // For versions below 1.20: |
+ | | ||
+ | | ||
+ | | ||
+ | // For versions since 1.20.5: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
+ | | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Line 37: | Line 43: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | + | |
- | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); | + | |
+ | | ||
+ | | ||
+ | // For versions since 1.20.5: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
@Override | @Override | ||
Line 56: | Line 66: | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | + | |
- | public static final Block EXAMPLE_BLOCK | + | |
+ | | ||
+ | | ||
+ | // For versions since 1.20.5: | ||
+ | public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
| | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Registry.register(Registries.BLOCK, | Registry.register(Registries.BLOCK, | ||
- | Registry.register(Registries.ITEM, | + | |
+ | // Registry.register(Registries.ITEM, | ||
+ | // For versions since 1.20.5: | ||
+ | Registry.register(Registries.ITEM, | ||
} | } | ||
} | } | ||
Line 164: | Line 181: | ||
</ | </ | ||
- | For the harvest level tags ('' | + | For the harvest level tags ('' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | | + | public static final Block EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.create().strength(4.0f).requiresTool()); |
- | public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.create().strength(4.0f).requiresTool()); | + | |
</ | </ | ||
Line 193: | Line 209: | ||
} | } | ||
+ | // For versions below 1.20.5, the parameters should be " | ||
@Override | @Override | ||
- | public ActionResult onUse(BlockState state, | + | public ActionResult onUse(World world, PlayerEntity player, BlockHitResult hit) { |
if (!world.isClient) { | if (!world.isClient) { | ||
player.sendMessage(Text.literal(" | player.sendMessage(Text.literal(" | ||
Line 242: | Line 259: | ||
You can also define other types of shapes for the block. The type of shapes of blocks include: | You can also define other types of shapes for the block. The type of shapes of blocks include: | ||
* **outline shape**: the shape used as default value for most type of shapes. In the worlds, when you points to the shape, the translucent black outline is displayed according to this shape. Most times it should not be empty. | * **outline shape**: the shape used as default value for most type of shapes. In the worlds, when you points to the shape, the translucent black outline is displayed according to this shape. Most times it should not be empty. | ||
- | * **collision shape**: the shape used to calculate collisions. When entities (including players) are moving, their collision box usually cannot intersect the collision shape of blocks. Some blocks, such as fences and walls, may have a collision shape higher than one block. Some blocks, such as flowers, have an empty collision shape. Apart from modifying '' | + | * **collision shape**: the shape used to calculate collisions. When entities (including players) are moving, their collision box usually cannot intersect the collision shape of blocks. Some blocks, such as fences and walls, may have a collision shape higher than one block. Some blocks, such as flowers, have an empty collision shape. Apart from modifying '' |
* **raycasting shape**: the shape used to calculate raycasting (the process judging which block you are pointing to). You usually do not need to specify it. | * **raycasting shape**: the shape used to calculate raycasting (the process judging which block you are pointing to). You usually do not need to specify it. | ||
* **camera collision shape**: the shape used to calculate the position of camera in third-party view. Glass and powder snow have an empty camera collision shape. | * **camera collision shape**: the shape used to calculate the position of camera in third-party view. Glass and powder snow have an empty camera collision shape. |
tutorial/blocks.1700296446.txt.gz · Last modified: 2023/11/18 08:34 by solidblock