ko_kr:tutorial:blocks
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
ko_kr:tutorial:blocks [2021/04/07 04:54] – created themovieayt | ko_kr:tutorial:blocks [2021/04/07 05:14] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 블록 추가하기 ====== | ====== 블록 추가하기 ====== | ||
- | 블록을 추가하는 방법은 아이템을 추가하는 것과 비슷합니다. | + | 블록을 추가하는 방법은 |
+ | |||
+ | ===== 블록 만들기 ===== | ||
+ | Start by creating an instance of '' | ||
+ | |||
+ | 블록 인스턴스를 먼저 만듭니다. | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | /* Declare and initialize our custom block instance. | ||
+ | We set our block material to `METAL`, which requires a pickaxe to efficiently break. | ||
+ | |||
+ | | ||
+ | | ||
+ | Stone has a hardness of 1.5f and a resistance of 6.0f, while Obsidian has a hardness of 50.0f and a resistance of 1200.0f. | ||
+ | |||
+ | 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)); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Registering your Block ==== | ||
+ | |||
+ | Blocks should be registered under the '' | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registry.BLOCK, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Your custom block will //not// be accessible as an item yet, but it can be seen in-game by using the command ''/ | ||
+ | |||
+ | ==== Registering an Item for your Block ==== | ||
+ | |||
+ | In most cases, you want to be able to place your block using an item. To do this, you need to register a corresponding BlockItem in the item registry. You can do this by registering an instance of BlockItem under Registry.ITEM. The registry name of the item should usually be the same as the registry name of the block. | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registry.BLOCK, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Giving your Block Visuals ===== | ||
+ | |||
+ | At this point, your new block will appear as a purple and black checkerboard pattern in-game. This is Minecraft' | ||
+ | * A blockstate file | ||
+ | * A block model file | ||
+ | * A texture | ||
+ | * An item model file (if the block has an item associated with it). | ||
+ | |||
+ | The files should be located here: | ||
+ | |||
+ | Blockstate: src/ | ||
+ | Block Model: src/ | ||
+ | Item Model: src/ | ||
+ | Block Texture: src/ | ||
+ | |||
+ | The blockstate file determines which model a block should use depending on its blockstate. Our block doesn' | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | "": | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The block model file defines the shape and texture of your block. Our model will have '' | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In most cases, you will want the block to look the same in item form. You can make an item model that has the block model file as a parent, which makes it appear exactly like the block: | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Load up Minecraft and your block should have visuals! | ||
+ | |||
+ | ===== Configuring Block Drops ===== | ||
+ | |||
+ | To make your block drop items when broken, you will need a //loot table//. The following file will cause your block to drop its respective item form when broken: | ||
+ | |||
+ | <code JavaScript src/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Creating a Custom Block Class ===== | ||
+ | |||
+ | The above approach works well for simple items but falls short when you want a block with //unique// mechanics. We'll create a // | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleBlock extends Block { | ||
+ | |||
+ | public ExampleBlock(Settings settings) { | ||
+ | super(settings); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can override methods in the block class for custom functionality. Here's an implementation of the '' | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleBlock extends Block { | ||
+ | |||
+ | public ExampleBlock(Settings settings) { | ||
+ | super(settings); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
+ | if (!world.isClient) { | ||
+ | player.sendMessage(new LiteralText(" | ||
+ | } | ||
+ | |||
+ | return ActionResult.SUCCESS; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | To use your custom block class, replace //new Block// with //new ExampleBlock//: | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | public static final ExampleBlock EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.of(Material.STONE).hardness(4.0f)); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registry.BLOCK, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Custom VoxelShape ==== | ||
+ | |||
+ | When using block models that do not // | ||
+ | |||
+ | {{: | ||
+ | |||
+ | To fix this, we have to define the '' | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Note that the //collision shape// of the block defaults to the outline shape if it is not specified. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Next Steps ===== | ||
+ | [[tutorial: | ||
+ | |||
+ | [[tutorial: |
ko_kr/tutorial/blocks.txt · Last modified: 2023/08/14 16:13 by namutree0345