Browse Source

第一版模组(基本能正常运行)

hsj 2 days ago
parent
commit
e9fda9e6f5

+ 46 - 0
README_拆解台模组.md

@@ -45,6 +45,52 @@
 - **模组加载器**: Fabric
 - **模组加载器**: Fabric
 - **依赖**: Fabric API
 - **依赖**: Fabric API
 
 
+## 项目结构
+
+```
+src/main/resources/
+├── assets/husj/
+│   ├── blockstates/          # 方块状态定义
+│   ├── items/                # 物品模型定义 (1.21+新增)
+│   ├── models/block/         # 方块模型
+│   ├── models/item/          # 物品模型 (1.21+已弃用,使用items/)
+│   ├── textures/block/       # 方块贴图
+│   └── lang/                 # 语言文件
+├── data/husj/
+│   ├── recipe/               # 合成配方 (1.21+使用单数)
+│   ├── loot_table/blocks/    # 战利品表 (1.21+使用单数)
+│   └── advancements/         # 进度
+└── data/minecraft/tags/block/ # 方块标签
+```
+
+## Minecraft 1.21+ 版本注意事项
+
+> **重要**: Minecraft 1.21.2+ 引入了重大数据包格式变更!
+
+### 目录名称变更
+| 旧版本 (1.20及以前) | 新版本 (1.21+) |
+|-------------------|---------------|
+| `data/.../recipes/` | `data/.../recipe/` |
+| `data/.../loot_tables/` | `data/.../loot_table/` |
+
+### 物品模型系统变更
+- **旧系统**: `assets/.../models/item/xxx.json`
+- **新系统**: `assets/.../items/xxx.json`
+
+新的物品定义文件格式:
+```json
+{
+  "model": {
+    "type": "minecraft:model",
+    "model": "namespace:block/block_model"
+  }
+}
+```
+
+### 配方格式变更
+- `result` 中使用 `"id"` 替代 `"item"`
+- `key` 中可以直接使用字符串 `"minecraft:item_id"` 替代对象 `{"item": "minecraft:item_id"}`
+
 ## 开发信息
 ## 开发信息
 
 
 这个模组是基于Fabric模组加载器开发的,包含了完整的方块实体、GUI界面和拆解逻辑实现。
 这个模组是基于Fabric模组加载器开发的,包含了完整的方块实体、GUI界面和拆解逻辑实现。

+ 14 - 0
src/main/java/com/husj/Husj.java

@@ -6,6 +6,20 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityT
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
+/**
+ * 拆解台模组 (Disassembler Mod) - 主入口类
+ * 
+ * 这是一个Minecraft Fabric模组,添加了一个拆解台功能方块,可以回收矿物制成的工具和装备。
+ * 
+ * 注意:本模组适配 Minecraft 1.21.9+,使用了以下新版本特性:
+ * - 物品模型定义在 assets/husj/items/ 目录下(而非 models/item/)
+ * - 配方文件在 data/husj/recipe/ 目录下(单数,而非 recipes/)
+ * - 战利品表在 data/husj/loot_table/ 目录下(单数,而非 loot_tables/)
+ * 
+ * @author husj
+ * @version 1.0.0
+ */
+
 public class Husj implements ModInitializer {
 public class Husj implements ModInitializer {
 	public static final String MOD_ID = "husj";
 	public static final String MOD_ID = "husj";
 
 

+ 16 - 0
src/main/java/com/husj/ModBlocks.java

@@ -15,6 +15,22 @@ import net.minecraft.registry.RegistryKey;
 import net.minecraft.registry.RegistryKeys;
 import net.minecraft.registry.RegistryKeys;
 import net.minecraft.util.Identifier;
 import net.minecraft.util.Identifier;
 
 
+/**
+ * 模组方块注册类
+ * 
+ * 注册拆解台方块和对应的方块实体。
+ * 
+ * 注意:在 Minecraft 1.21+ 中,物品模型需要在 assets/husj/items/ 目录下定义,
+ * 而不是传统的 assets/husj/models/item/ 目录。
+ * 
+ * 资源文件结构:
+ * - 方块状态: assets/husj/blockstates/disassembler.json
+ * - 方块模型: assets/husj/models/block/disassembler.json
+ * - 物品定义: assets/husj/items/disassembler.json (1.21+新格式)
+ * - 合成配方: data/husj/recipe/disassembler.json (注意是单数)
+ * - 战利品表: data/husj/loot_table/blocks/disassembler.json (注意是单数)
+ */
+
 public class ModBlocks {
 public class ModBlocks {
     public static final Block DISASSEMBLER_BLOCK = registerBlock("disassembler",
     public static final Block DISASSEMBLER_BLOCK = registerBlock("disassembler",
             DisassemblerBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque().requiresTool());
             DisassemblerBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque().requiresTool());

+ 6 - 0
src/main/resources/assets/husj/items/disassembler.json

@@ -0,0 +1,6 @@
+{
+    "model": {
+        "type": "minecraft:model",
+        "model": "husj:block/disassembler"
+    }
+}

+ 4 - 1
src/main/resources/assets/husj/models/item/disassembler.json

@@ -1,3 +1,6 @@
 {
 {
-  "parent": "husj:block/disassembler"
+  "parent": "minecraft:item/generated",
+  "textures": {
+    "layer0": "minecraft:item/diamond"
+  }
 }
 }

+ 0 - 3
src/main/resources/assets/husj/textures/block/disassembler_bottom.png.mcmeta

@@ -1,3 +0,0 @@
-{
-  "comment": "拆解台底部纹理,实际游戏中需要真正的纹理图片"
-}

+ 0 - 3
src/main/resources/assets/husj/textures/block/disassembler_front.png.mcmeta

@@ -1,3 +0,0 @@
-{
-  "comment": "拆解台正面纹理,实际游戏中需要真正的纹理图片"
-}

+ 0 - 3
src/main/resources/assets/husj/textures/block/disassembler_side.png.mcmeta

@@ -1,3 +0,0 @@
-{
-  "comment": "拆解台侧面纹理,实际游戏中需要真正的纹理图片"
-}

+ 0 - 3
src/main/resources/assets/husj/textures/block/disassembler_top.png.mcmeta

@@ -1,3 +0,0 @@
-{
-  "comment": "拆解台顶部纹理,实际游戏中需要真正的纹理图片"
-}

+ 29 - 0
src/main/resources/data/husj/advancements/recipes/husj/disassembler.json

@@ -0,0 +1,29 @@
+{
+  "parent": "minecraft:recipes/root",
+  "criteria": {
+    "has_iron": {
+      "trigger": "minecraft:inventory_changed",
+      "conditions": {"items": [{"items": ["minecraft:iron_ingot"]}]}
+    },
+    "has_diamond": {
+      "trigger": "minecraft:inventory_changed",
+      "conditions": {"items": [{"items": ["minecraft:diamond"]}]}
+    },
+    "has_cobblestone": {
+      "trigger": "minecraft:inventory_changed",
+      "conditions": {"items": [{"items": ["minecraft:cobblestone"]}]}
+    },
+    "has_recipe": {
+      "trigger": "minecraft:recipe_unlocked",
+      "conditions": {"recipe": "husj:disassembler"}
+    }
+  },
+  "requirements": [
+    ["has_iron", "has_recipe"],
+    ["has_diamond", "has_recipe"],
+    ["has_cobblestone", "has_recipe"]
+  ],
+  "rewards": {
+    "recipes": ["husj:disassembler"]
+  }
+}

+ 0 - 0
src/main/resources/data/husj/loot_tables/blocks/disassembler.json → src/main/resources/data/husj/loot_table/blocks/disassembler.json


+ 18 - 0
src/main/resources/data/husj/recipe/disassembler.json

@@ -0,0 +1,18 @@
+{
+    "type": "minecraft:crafting_shaped",
+    "category": "misc",
+    "pattern": [
+        "III",
+        "DDD",
+        "SSS"
+    ],
+    "key": {
+        "I": "minecraft:iron_ingot",
+        "D": "minecraft:diamond",
+        "S": "minecraft:cobblestone"
+    },
+    "result": {
+        "id": "husj:disassembler",
+        "count": 1
+    }
+}

+ 0 - 22
src/main/resources/data/husj/recipes/disassembler.json

@@ -1,22 +0,0 @@
-{
-  "type": "minecraft:crafting_shaped",
-  "pattern": [
-    "III",
-    "DDD",
-    "SSS"
-  ],
-  "key": {
-    "I": {
-      "item": "minecraft:iron_ingot"
-    },
-    "D": {
-      "item": "minecraft:diamond"
-    },
-    "S": {
-      "item": "minecraft:cobblestone"
-    }
-  },
-  "result": {
-    "item": "husj:disassembler"
-  }
-}

+ 6 - 0
src/main/resources/pack.mcmeta

@@ -0,0 +1,6 @@
+{
+  "pack": {
+    "pack_format": 42,
+    "description": "husj built-in resources and data (recipes)"
+  }
+}