本篇教程的视频

本篇教程的源代码

忘记分支了,和下一期并一起了

本篇教程目标

  • 为模组添加Blockbench制作的物品或者方块模型

Blockbench

那么从本期教程开始,我们之后的教程可能会用到使用Blockbench制作的模型

在暑假期到来之前,我们将主要讲解方块状态

而后再将没有做的教程补上

那么这里就先简单介绍一下Blockbench这个软件,这是一个轻量级的开源三维建模软件,主要用于Minecraft相关的建模或者动画

它的上手是非常简单的,只要对体块进行缩放移动旋转就可以完成一个模型的制作

当然,要精通那还得学很多东西,比如会绘制或者调节UV,但足够用了

Blockbench下载地址:下载

注意事项

在所有的Minecraft Java版模组开发中,如果你不使用obj模型,那么在新建模型选择模板时,
就必须选择Java版方块/物品,不要选择基岩版的,否则导出模型时没有json格式可选

注册物品和方块

导出模型

那么建模的过程我就不说了,实在不会就看看哔哩哔哩上的教程

建好模型之后,可以在右上栏的显示模式中调整包括GUI第一人称第三人称等不同角度下模型的显示

当然它也有预设,有武器木棍方块的,你也可以根据你的实际情况来保存你自己的预设

这个显示模式得调整,不然在游戏中会很怪

调整好之后,导出贴图,再点文件->导出->导出为Java版方块/物品,我们就得到了一个json文件

注册

物品和方块的注册就不用多说了,我们已经注册了很多很多方块和物品了

物品的

1
public static final Item BASEBALL_BAT = registerItems("baseball_bat", new Item(new Item.Settings()));

这个就简单做了个棒球棍

方块的

1
2
public static final Block ORANGE_NIGHTSTAND = register("orange_nightstand",
new Block(AbstractBlock.Settings.create().strength(2.0f, 6.0f).nonOpaque()));

这里我们还是实例化Block,从后面的教程开始我们就要自定义方块类了

不过在方块设置中,我们还加上了nonOpaque这个方法,这个指定方块是非实心的

这个方块并不是一个完整的方块,但我们直接实例化Block类,没有调整它的碰撞箱

数据生成

语言文件

1
2
translationBuilder.add(ModItems.BASEBALL_BAT, "Baseball Bat");
translationBuilder.add(ModBlocks.ORANGE_NIGHTSTAND, "Orange Nightstand");

模型文件

这里我们只要一个简单的方块状态文件即可,模型文件的话就用的是Blockbench导出的

1
blockStateModelGenerator.registerSimpleState(ModBlocks.ORANGE_NIGHTSTAND);

方块模型文件,这里我附上我自己做的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "tutorial-mod:block/orange_nightstand",
"particle": "tutorial-mod:block/orange_nightstand"
},
"elements": [
{
"from": [0, 15, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 8, 4, 8.25], "texture": "#0"},
"east": {"uv": [0, 8.25, 4, 8.5], "texture": "#0"},
"south": {"uv": [0, 8.5, 4, 8.75], "texture": "#0"},
"west": {"uv": [0, 8.75, 4, 9], "texture": "#0"},
"up": {"uv": [4, 4, 0, 0], "texture": "#0"},
"down": {"uv": [4, 4, 0, 8], "texture": "#0"}
}
},
{
"from": [1, 0, 1],
"to": [15, 15, 16],
"faces": {
"north": {"uv": [4, 7.5, 7.5, 11.25], "texture": "#0"},
"east": {"uv": [4, 0, 7.75, 3.75], "texture": "#0"},
"south": {"uv": [7.5, 7.5, 11, 11.25], "texture": "#0"},
"west": {"uv": [4, 3.75, 7.75, 7.5], "texture": "#0"},
"up": {"uv": [11.25, 3.75, 7.75, 0], "texture": "#0"},
"down": {"uv": [11.25, 3.75, 7.75, 7.5], "texture": "#0"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 225, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.25, 0.25, 0.25]
},
"gui": {
"rotation": [30, 225, 0],
"scale": [0.625, 0.625, 0.625]
},
"fixed": {
"scale": [0.5, 0.5, 0.5]
}
},
"groups": [
{
"name": "group",
"origin": [0, 0, 0],
"color": 0,
"children": [0, 1]
}
]
}

物品模型同样如此,也用Blockbench导出的即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
"credit": "Made with Blockbench",
"textures": {
"0": "tutorial-mod:item/baseball_bat",
"particle": "tutorial-mod:item/baseball_bat"
},
"elements": [
{
"from": [7, 0, 7],
"to": [9, 1, 9],
"rotation": {"angle": 0, "axis": "y", "origin": [7, 0, 7]},
"faces": {
"north": {"uv": [10, 8, 12, 9], "texture": "#0"},
"east": {"uv": [10, 9, 12, 10], "texture": "#0"},
"south": {"uv": [10, 10, 12, 11], "texture": "#0"},
"west": {"uv": [0, 11, 2, 12], "texture": "#0"},
"up": {"uv": [12, 2, 10, 0], "texture": "#0"},
"down": {"uv": [12, 2, 10, 4], "texture": "#0"}
}
},
{
"from": [7, 8, 7],
"to": [9, 19, 9],
"rotation": {"angle": 0, "axis": "y", "origin": [7, 7, 7]},
"faces": {
"north": {"uv": [0, 0, 2, 11], "texture": "#0"},
"east": {"uv": [2, 0, 4, 11], "texture": "#0"},
"south": {"uv": [4, 0, 6, 11], "texture": "#0"},
"west": {"uv": [6, 0, 8, 11], "texture": "#0"},
"up": {"uv": [12, 6, 10, 4], "texture": "#0"},
"down": {"uv": [12, 6, 10, 8], "texture": "#0"}
}
},
{
"from": [7.5, 1, 7.5],
"to": [8.5, 8, 8.5],
"rotation": {"angle": 0, "axis": "y", "origin": [6.5, 1, 7.5]},
"faces": {
"north": {"uv": [8, 0, 9, 7], "texture": "#0"},
"east": {"uv": [8, 7, 9, 14], "texture": "#0"},
"south": {"uv": [9, 0, 10, 7], "texture": "#0"},
"west": {"uv": [9, 7, 10, 14], "texture": "#0"},
"up": {"uv": [3, 12, 2, 11], "texture": "#0"},
"down": {"uv": [4, 11, 3, 12], "texture": "#0"}
}
}
],
"display": {
"thirdperson_righthand": {
"translation": [0, 2, 0.25]
},
"thirdperson_lefthand": {
"translation": [0, 3, 1],
"scale": [0.55, 0.55, 0.55]
},
"firstperson_righthand": {
"rotation": [0, -90, 25],
"translation": [1.13, 3.2, 1.13],
"scale": [0.68, 0.68, 0.68]
},
"firstperson_lefthand": {
"rotation": [0, -90, 25],
"translation": [1.13, 3.2, 1.13],
"scale": [0.68, 0.68, 0.68]
},
"ground": {
"translation": [0, 2, 0],
"scale": [0.5, 0.5, 0.5]
},
"gui": {
"rotation": [30, 225, 0],
"scale": [0.625, 0.625, 0.625]
},
"head": {
"rotation": [0, 180, 0],
"translation": [0, 13, 7]
},
"fixed": {
"rotation": [0, 180, 0],
"translation": [0, -1.5, 0]
}
}
}

贴图文件

贴图文件放到对应的位置即可

测试

跑好数据生成之后,我们就可以启动游戏进行测试了