Minecraft Fabric 教程 #3 添加方块

简介: 创建方块,注册,创建方块物品,添加纹理,掉落物,创建一个Block类

首发于Enaium的个人博客


创建方块

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);
    }
}

运行游戏发现无法找到方块是因为没有创建方块物品 但是可以使用命令在创建这个方块

创建方块物品

直接注册就行

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.json

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

models/block/end_heart_block.json

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

models/item/end_heart_block.json

{
  "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.json

{
  "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());
目录
相关文章
Minecraft Fabric 教程 #8 添加附魔书
这就创建了一个FireBoom附魔书 onTargetDamaged //当目标被攻击 在mc FireballEntity类有一个 方法就是当火球碰撞了就创建一个火焰爆炸的效果
78 0
Minecraft Fabric 教程 #9 添加盔甲
参数一 材料名字 参数二 耐久倍数 参数三 盔甲数也就是穿上盔甲加的盔甲值 参数四 使用的时候发出的声音 参数五 耐性
72 0
Minecraft Fabric 教程 #9 添加盔甲
Minecraft Fabric 进阶教程 #2 绘制界面
绘制界面不需用注入Mixin
108 0
Minecraft Fabric 教程 #5 添加语言文件
lang也就是你模组的翻译比如 中文简体 zh_cn 中文正體 zh_tw 英文 en_us
82 0
|
开发框架 .NET 区块链
Hyperledger fabric部署链码(五)初始化与链码升级
fabric部署chaincode-go(智能合约)系列之五
202 0
|
测试技术 Go 区块链
Hyperledger fabric 测试环境部署
Hyperledger fabric 测试环境部署及相关问题解答
266 3
Hyperledger fabric 测试环境部署
|
JavaScript 测试技术 Go
Hyperledger fabric部署链码(一)打包链码
fabric部署chaincode-go(智能合约)系列之一
244 0