Minecraft Fabric模组开发教程#10 添加矿物

首发于Enaium的个人博客


注册矿物

我们都知道,在矿物被挖掘之后,会掉落经验,所以我们需要使用ExperienceDroppingBlock来创建方块对象,之后需要创建两种矿物,一种是普通的矿物,一种是深层矿物。

ExperienceDroppingBlock的构造函数需要两个参数,第一个是掉落的经验数量,这里也就是创建了一个随机为 10-17 的经验掉落,第二个参数是方块的设置,这里设置了方块的颜色,敲击音效,硬度抗性,必须使用工具,以及挖掘音效。

java 复制代码
public static final Block END_HEART_ORE = new ExperienceDroppingBlock(UniformIntProvider.create(10, 17), AbstractBlock.Settings.create().mapColor(MapColor.STONE_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(3.0f, 3.0f).sounds(BlockSoundGroup.NETHER_ORE));

深层矿物的设置和普通矿物差不多,只不过需要调用copy方法。

java 复制代码
public static final Block DEEPSLATE_END_HEART_ORE = new ExperienceDroppingBlock(UniformIntProvider.create(10, 17), AbstractBlock.Settings.copy(END_HEART_ORE).mapColor(MapColor.DEEPSLATE_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(4.5f, 3.0f).sounds(BlockSoundGroup.DEEPSLATE));

最后,我们需要注册这两个矿物。

java 复制代码
Registry.register(Registries.BLOCK, new Identifier("awesome", "end_heart_ore"), END_HEART_ORE);
Registry.register(Registries.BLOCK, new Identifier("awesome", "deepslate_end_heart_ore"), DEEPSLATE_END_HEART_ORE);

注册矿物物品

使用之前学习的方法,我们可以很容易的注册矿物物品。

矿物纹理

使用之前学习的方法,我们可以很容易的注册矿物纹理。

多语言文件

json 复制代码
{
    "item.awesome.end_heart_ore": "End Heart Ore",
    "item.awesome.deepslate_end_heart_ore": "Deepslate End Heart Ore",
    "block.awesome.end_heart_ore": "End Heart Ore",
    "block.awesome.deepslate_end_heart_ore": "Deepslate End Heart Ore"
}

掉落物

这里会比较复杂,需要考虑精准采集时运的影响,但我们可以使用原版中已经存在的配置。

我们进入到原版游戏中的data/minecraft/loot_tables/blocks/diamond_ore.jsondata/minecraft/loot_tables/blocks/deepslate_diamond_ore.json将钻石矿的掉落配置加以修改。

diff 复制代码
@@ -24,7 +24,7 @@
                   }
                 }
               ],
-              "name": "minecraft:diamond_ore"
+              "name": "awesome:end_heart_ore"
             },
             {
               "type": "minecraft:item",
@@ -38,7 +38,7 @@
                   "function": "minecraft:explosion_decay"
                 }
               ],
-              "name": "minecraft:diamond"
+              "name": "awesome:end_heart"
             }
           ]
         }
@@ -46,5 +46,5 @@
       "rolls": 1.0
     }
   ],
-  "random_sequence": "minecraft:blocks/diamond_ore"
+  "random_sequence": "awesome:blocks/end_heart_ore"
 }
diff 复制代码
@@ -24,7 +24,7 @@
                   }
                 }
               ],
-              "name": "minecraft:deepslate_diamond_ore"
+              "name": "awesome:deepslate_end_heart_ore"
             },
             {
               "type": "minecraft:item",
@@ -38,7 +38,7 @@
                   "function": "minecraft:explosion_decay"
                 }
               ],
-              "name": "minecraft:diamond"
+              "name": "awesome:end_heart"
             }
           ]
         }
@@ -46,5 +46,5 @@
       "rolls": 1.0
     }
   ],
-  "random_sequence": "minecraft:blocks/deepslate_diamond_ore"
+  "random_sequence": "awesome:blocks/deepslate_end_heart_ore"
 }

可挖掘方块

我们需要在data/minecraft/tags/blocks/mineable/pickaxe.json中添加我们的矿物。

json 复制代码
{
  "replace": false,
  "values": [
    "awesome:end_heart_ore",
    "awesome:deepslate_end_heart_ore"
  ]
}

矿物配方

首先添加熔炉的配方,还是在recipes下创建,格式就是物品ID_from_smelting_矿物ID.json,高炉的配方就是物品ID_from_blasting_矿物ID.json

熔炉

json 复制代码
{
  "type": "minecraft:smelting",
  "category": "misc",
  "cookingtime": 200,
  "experience": 1.0,
  "group": "end_heart",
  "ingredient": {
    "item": "awesome:end_heart_ore"
  },
  "result": "awesome:end_heart"
}
json 复制代码
{
  "type": "minecraft:smelting",
  "category": "misc",
  "cookingtime": 200,
  "experience": 1.0,
  "group": "end_heart",
  "ingredient": {
    "item": "awesome:deepslate_end_heart_ore"
  },
  "result": "awesome:end_heart"
}

高炉

json 复制代码
{
  "type": "minecraft:blasting",
  "category": "misc",
  "cookingtime": 100,
  "experience": 1.0,
  "group": "end_heart",
  "ingredient": {
    "item": "awesome:end_heart_ore"
  },
  "result": "awesome:end_heart"
}
json 复制代码
{
  "type": "minecraft:blasting",
  "category": "misc",
  "cookingtime": 100,
  "experience": 1.0,
  "group": "end_heart",
  "ingredient": {
    "item": "awesome:deepslate_end_heart_ore"
  },
  "result": "awesome:end_heart"
}

矿物生成

首先创建矿物的configured_feature,在data\awesome\worldgen\configured_feature中,创建配置end_heart_ore.json

其中discard_chance_on_air_exposure就是矿物在空气中曝露的概率,size就是矿物的大小,targets就是矿物生成的目标方块,predicate_type的意思就是判断tag中的方块是否符合要求,不过要注意的是state中的Name必须首字母大写。

json 复制代码
{
  "type": "minecraft:ore",
  "config": {
    "discard_chance_on_air_exposure": 0.0,
    "size": 12,
    "targets": [
      {
        "state": {
          "Name": "awesome:end_heart_ore"
        },
        "target": {
          "predicate_type": "minecraft:tag_match",
          "tag": "minecraft:stone_ore_replaceables"
        }
      },
      {
        "state": {
          "Name": "awesome:deepslate_end_heart_ore"
        },
        "target": {
          "predicate_type": "minecraft:tag_match",
          "tag": "minecraft:deepslate_ore_replaceables"
        }
      }
    ]
  }
}

然后创建placed_feature,在data\awesome\worldgen\placed_feature中,创建配置end_heart_ore.json

placement中有四个参数,第一个是minecraft:count,就是矿物的数量,第二个是minecraft:in_square,就是矿物的生成范围,第三个是minecraft:height_range,就是矿物的生成高度,第四个是minecraft:biome,表示会在群系中生成。

json 复制代码
{
  "feature": "awesome:end_heart_ore",
  "placement": [
    {
      "type": "minecraft:count",
      "count": 20
    },
    {
      "type": "minecraft:in_square"
    },
    {
      "type": "minecraft:height_range",
      "height": {
        "type": "minecraft:trapezoid",
        "max_inclusive": {
          "absolute": 70
        },
        "min_inclusive": {
          "absolute": -24
        }
      }
    },
    {
      "type": "minecraft:biome"
    }
  ]
}

最后注册PlacedFeature

java 复制代码
public static final RegistryKey<PlacedFeature> END_HEART_ORE_PLACED_FEATURE = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("awesome","end_heart_ore"));

并且在BiomeModifications中注册END_HEART_ORE_PLACED_FEATURE

java 复制代码
BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Feature.UNDERGROUND_ORES, END_HEART_ORE_PLACED_FEATURE);

相关推荐
cdut_suye6 分钟前
Linux工具使用指南:从apt管理、gcc编译到makefile构建与gdb调试
java·linux·运维·服务器·c++·人工智能·python
苹果醋318 分钟前
2020重新出发,MySql基础,MySql表数据操作
java·运维·spring boot·mysql·nginx
小蜗牛慢慢爬行20 分钟前
如何在 Spring Boot 微服务中设置和管理多个数据库
java·数据库·spring boot·后端·微服务·架构·hibernate
azhou的代码园23 分钟前
基于JAVA+SpringBoot+Vue的制造装备物联及生产管理ERP系统
java·spring boot·制造
wm10431 小时前
java web springboot
java·spring boot·后端
smile-yan1 小时前
Provides transitive vulnerable dependency maven 提示依赖存在漏洞问题的解决方法
java·maven
老马啸西风1 小时前
NLP 中文拼写检测纠正论文-01-介绍了SIGHAN 2015 包括任务描述,数据准备, 绩效指标和评估结果
java
Earnest~1 小时前
Maven极简安装&配置-241223
java·maven
皮蛋很白1 小时前
Maven 环境变量 MAVEN_HOME 和 M2_HOME 区别以及 IDEA 修改 Maven repository 路径全局
java·maven·intellij-idea
青年有志1 小时前
JavaWeb(一) | 基本概念(web服务器、Tomcat、HTTP、Maven)、Servlet 简介
java·web