Minecraft Fabric 教程 #3 添加方塊

首發於Enaium的我的博客json


建立方塊

public class ExampleMod implements ModInitializer
{
    // an instance of our new block
    public static final Block END_HEART_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).build());
    [...]
}

註冊

public class ExampleMod implements ModInitializer
{
    // block creation
    […]
 
    @Override
    public void onInitialize()
    {
        Registry.register(Registry.BLOCK, new Identifier("endarmor", "end_heart_block"), END_HEART_BLOCK);
    }
}

運行遊戲發現沒法找到方塊是由於沒有建立方塊物品 可是可使用命令在建立這個方塊ide

建立方塊物品

直接註冊就行ui

public class ExampleMod implements ModInitializer
{
    // block creation
    […]
 
    @Override
    public void onInitialize()
    {
        // block registration
        [...]
 
        Registry.register(Registry.ITEM, new Identifier("endarmor", "end_heart_block"), new BlockItem(END_HEART_BLOCK, new Item.Settings().itemGroup(ItemGroup.MISC)));
    }
}

添加紋理

Blockstate: src/main/resources/assets/endarmor/blockstates/end_heart_block.json
Block Model: src/main/resources/assets/endarmor/models/block/end_heart_block.json
Item Model: src/main/resources/assets/endarmor/models/item/end_heart_block.json
Block Texture: src/main/resources/assets/endarmor/textures/block/end_heart_block.png

blockstates/end_heart_block.jsonspa

{
  "variants": {
    "": { "model": "endarmor:block/end_heart_block" }
  }
}

models/block/end_heart_block.jsoncode

{
  "parent": "block/cube_all",
  "textures": {
    "all": "endarmor:block/end_heart_block"
  }
}

models/item/end_heart_block.jsonblog

{
  "parent": "endarmor:block/end_heart_block"
}

textures/block/end_heart_block.png遊戲

end_heart_block.png

3-1

掉落物

位置 \src\main\resources\data\endarmor\loot_tables\blocks\end_heart_block.jsonrem

{
  "type": "minecraft:block",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "endarmor:end_heart_block"
        }
      ],
      "conditions": [
        {
          "condition": "minecraft:survives_explosion"
        }
      ]
    }
  ]
}

建立一個Block類

public class ExampleBlock extends Block
{
    public ExampleBlock(Settings settings)
    {
        super(settings);
    }
}
private static final EndHeartBlock END_HEART_BLOCK = new EndHeartBlock(FabricBlockSettings.of(Material.METAL).build());
相關文章
相關標籤/搜索