在 Minecraft 1.21.4 中用制导导弹炸你的朋友。
这是一个仅适用于服务器的 Fabric Minecraft 模组。
它允许所有玩家编程制导导弹,并从 弩 或 发射器 发射它们。
请参阅 Minecraft 中的制导导弹 了解你可以用这个模组做什么。
应用结构
这是一个特殊的 Minecraft 模组,通过 gRPC 连接到外部进程。

每个玩家都编程一个制导服务器应用程序。
这些制导服务器可以托管在与 Minecraft 服务器相同的宿主机上的 Docker 容器中。
每当发射一枚导弹时,Minecraft 都会连接到玩家的制导服务器,并在每个刻(tick)发送导弹状态(例如位置、速度)。
制导服务器可以在接收到每个导弹状态后向导弹发送控制输入。
开发导弹制导
你可以用你喜欢的任何语言实现你的制导服务器。
它必须做两件事:
- 读取
PORT 环境变量。
- 在该端口上暴露一个 gRPC 服务器,遵循 src/main/proto/guidance.proto 中定义的协议。
这个
guidance.proto 文件包含有关该协议细节的更多文档。
Christopher Besch 撰写的 Minecraft 中的制导导弹 文章详细介绍了制导系统可以做什么以及如何实现。
制导服务器模板
目前有以下模板可以让你立即开始:
其他人的制导代码
有一些开源制导服务器可供你参考:
飞行动力学
与玩家一样,导弹也是 Minecraft 中的一个 实体。
导弹具有
-
位置 $p = \begin{pmatrix} p_1 \ p_2 \ p_3 \end{pmatrix} \in \mathbb{R}^3$(其中 $p_2$ 为海拔高度),
-
速度 $v \in \mathbb{R}^3$,
-
俯仰角 $\theta \in [-90, 90]$ 以及
-
偏航角 $\psi \in [-180, 180]$。
这些角度以度为单位,且没有翻滚角。
此外,它们是 Mincraft F3 菜单 中显示的 角度 的相反数。
这是因为出于某种原因,投射物的朝向是翻转的:
$\theta=90$ 是向上,$\theta=-90$ 向下,$\psi \in {-180, 180}$ 是北方,$\psi = 90$ 是东方,$\psi = 0$ 是南方,$\psi = -90$ 是西方。
Minecraft 每刻(每秒 20 次)更新导弹的状态。
第 $t \in \mathbb{N}_0$ 刻的更新分为三个阶段:
-
接收控制输入:
导弹的唯一输入方法是一个不切实际地强大的 力矩陀螺仪。
因此,玩家的制导代码会产生请求的俯仰角变化 $\theta_{in}$ 和偏航角变化 $\psi_{in}$。
它无法直接控制导弹的位置、速度或推力——只能控制旋转。
-
更新导弹状态:
陀螺仪很强大,但并非无限强大。
当控制输入过大(大于由空气动力学外形定义的 $M_r$)时,它会线性缩放:
\begin{aligned}
l &= \sqrt{\theta_{in}^2 + \psi_{in}^2} \\
\begin{pmatrix} \theta_{in} \\ \psi_{in} \end{pmatrix}
&\rightarrow \max{\left\{\frac{M_r}{l}, 1\right\}}
\begin{pmatrix} \theta_{in} \\ \psi_{in} \end{pmatrix}.
\end{aligned}
通过这种方式,Minecraft 会应用调整后的控制输入加上一些随机噪声。
\begin{aligned}
\theta &\rightarrow \theta + \theta_{in} + N_r \\
\psi &\rightarrow \psi + \psi_{in} + N_r \\
\end{aligned}
每个 $N_r$ 都是正态分布的噪声,取决于导弹使用的空气动力学外形。
因此,你对导弹旋转的控制并不完美,总会存在一些方差。
现在,可以从旋转矢量 $r \in \mathbb{R}^3$、当前推力 $T(t) \in [0, \infty)$ 和重力 $g = \begin{pmatrix} 0 \ -|g| \ 0 \end{pmatrix} \in \mathbb{R}^3$ 计算加速度 $a \in \mathbb{R}^3$。
\begin{aligned}
r & =
\begin{pmatrix}
\sin(\psi) \cos(\theta) \\
\sin(\theta) \\
\cos(\psi) \cos(\theta)
\end{pmatrix} \\
a & = \begin{pmatrix} a_1 \\ a_2 \\ a_3 \end{pmatrix} \\
& = \left(T(t) + N_T \right) \cdot r + g
\end{aligned}
$N_T$ 是正态分布的噪声,并且像推力函数 $T$ 一样由火箭发动机定义。
最后,使用空气动力学外形定义的阻力 $d \in [0, 1)$ 更新速度和位置。
\begin{aligned}
v &\rightarrow (1 - d) \cdot (v + a) \\
p &\rightarrow p + v
\end{aligned}
-
现在导弹状态已更新,Minecraft 将该状态发送给玩家的制导代码。
所有这些值也都包含一些方差——这取决于导弹的 惯性测量单元。
制导服务器有不到 50 毫秒的时间来发送下一刻的旋转变化。
在第一刻($t=0$),导弹还没有制导输入,因此它以射手的速度和旋转直线飞行。
此处不应用任何方差。
免责声明:
正如你所见,Minecraft 中导弹的飞行动力学与真实导弹毫无关系。
例如,完全没有模拟任何空气动力学特性。
我们所做的只是在真空中神奇地旋转一块岩石。
因此,本文所解释的制导代码仅适用于 Minecraft 这个玩具世界,而不适用于其他任何东西。
尽管如此,这仍然会很有趣!
制作你的第一枚导弹
这是一个仅限服务器的模组,因此你无需在 Minecraft 客户端安装任何模组。
因此,该模组不会带来任何新物品。
所有导弹在发射前都是正常的 烟花火箭物品。
有两种特殊因素将导弹与普通 Minecraft 烟花区分开来:
导弹命名
在 Minecraft 中,你可以使用 铁砧 更改物品的名称。
要将普通的烟花火箭转换为导弹,你需要给你的烟花火箭起一个特殊的名字。
<- 要使用的制导服务器 ID
<- 传递给制导服务器的字符串
m/69/test_name
这允许 Minecraft 模组识别应使用哪个制导服务器。
此外,每个制导服务器可以实现多种不同的导弹。
你仍需在下方部分满足材料要求,才能制作出可用的导弹。
导弹预算
你的导弹必须至少包含一枚 烟花之星 来制作。
制作导弹的方法有很多种。
mc_missile 模组会计算你用来制作烟花物品的材料。
它给每种材料赋予一个价值,并将这些价值相加。
这就是导弹的预算,可用于改善导弹的特性,请参阅 导弹组件 部分。
注意:
当你制作烟花火箭时,你会从一个配方中获得三个烟花火箭。
如果你在这种配方中投入一颗钻石,你将拥有三颗烟花火箭,每颗的价值相当于钻石的 1/3。
示例:
一个简单的烟花之星可以用火药和染料制作。
利用这一点,你可以制作最便宜的导弹:
那枚烟花之星、一份火药和一张纸,你就能得到三枚预算为 99€ 的导弹。
以下是所有可能材料的数值。
==== 材料数值 ====
PAPER = 90€
GUNPOWDER = 90€
DYE = 27€
BLAZE_POWDER = 900€
COAL = 180€
GOLD_NUGGET = 90€
HEAD = 90000€
FEATHER = 180€
DIAMOND = 9000€
GLOWSTONE_DUST = 90€
最低可能的导弹预算 = 99€
最高可能的导弹预算 = 231543€
==== 材料数值 ====
导弹组件
导弹由多个组件构成,每个组件都有价格标签以及对导弹的影响。
有关它们的具体影响,请参阅 guidance.proto。
以下是各组件的价格:
==== 硬件组件成本 ====
== 弹头成本 ====
BLANK = 0€
TNT_M = 450€
TNT_L = 9000€
TNT_XL = 90000€
INCENDIARY_M = 900€
INCENDIARY_L = 18000€
INCENDIARY_XL = 180000€
NEUTRON_BOMB_S = 450€
NEUTRON_BOMB_L = 900€
TUNGSTEN_PENETRATOR_S = 180€
TUNGSTEN_PENETRATOR_M = 450€
TUNGSTEN_PENETRATOR_L = 900€
BUNKER_BUSTER_M = 18000€
BUNKER_BUSTER_L = 27000€
BUNKER_BUSTER_XL = 180000€
== 弹头成本 ====
== 机身成本 ====
SPACE_SHUTTLE = 450000€
BRICK = 0€
DEFAULT_AIRFRAME = 180€
PERFECT_AIRFRAME = 1800€
== 机身成本 ====
== 发动机成本 ====
NO_MOTOR = 0€
SIMPLE_S = 900€
SIMPLE_M = 1800€
SIMPLE_L = 2700€
SIMPLE_XL = 90000€
BOOST_S = 450€
BOOST_M = 900€
TWO_STAGE_M = 450€
TWO_STAGE_L = 900€
RANDOM_S = 450€
RANDOM_L = 900€
CHANGING_S = 450€
CHANGING_M = 900€
CHANGING_L = 1350€
== 发动机成本 ====
== 电池成本 ====
NO_BATTERY = 0€
LI_ION_XS = 450€
LI_ION_S = 900€
LI_ION_M = 1350€
LI_ION_L = 2700€
LI_ION_XL = 5400€
LI_ION_XXL = 9000€
NUCLEAR = 90000€
== 电池成本 ====
== 导引头成本 ====
NO_SEEKER = 0€
IR_SEEKER_WIDE_S = 9000€
IR_SEEKER_WIDE_L = 18000€
IR_SEEKER_WIDE_INACCURATE_S = 6000€
IR_SEEKER_WIDE_INACCURATE_L = 12000€
IR_SEEKER_SNIPER_S = 6000€
IR_SEEKER_SNIPER_L = 12000€
IR_SEEKER_SNIPER_INACCURATE_S = 2000€
IR_SEEKER_SNIPER_INACCURATE_L = 4000€
IR_SEEKER_360_S = 12000€
IR_SEEKER_360_L = 24000€
IR_SEEKER_360_INACCURATE_S = 6000€
IR_SEEKER_360_INACCURATE_L = 12000€
LASER_DISTANCE_SEEKER = 3000€
== 导引头成本 ====
== 惯性系统成本 ====
BLIND = 0€
BAD_IMU = 180€
DEFAULT_IMU = 1260€
ACCURATE_IMU = 2700€
PERFECT_IMU = 9000€
== 惯性系统成本 ====
最低可能导弹成本 = 0€
最高可能导弹成本 = 843000€
==== 硬件组件成本 ====
所有组件的总价格必须小于或等于导弹的预算。
模组安装
本模组设计用于 Docker 部署。
请查看 example_deployment 及其 docker-compose.yml。
模组开发
开发环境
- 安装 Docker。
- 在此目录中创建开发容器,命令如下:
sudo docker run --net host -ti --name mc_missile_java -v ./:/home/gradle/mc_missile -p 25565:25565 --entrypoint /bin/bash gradle
- 当你退出该 shell 后,使用以下命令重新启动容器:
sudo docker start mc_missile_java
- 现在你可以进入它:
sudo docker exec -ti mc_missile_java /bin/bash
反编译 Minecraft
- 在 Docker 容器中的 mc_missile 目录下运行这些命令。
./gradlew genSources
jar xf ../.gradle/loom-cache/minecraftMaven/net/minecraft/minecraft-merged-abba00472f/1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2/minecraft-merged-abba00472f-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2-sources.jar com /net
jar xf ../.gradle/loom-cache/minecraftMaven/net/minecraft/minecraft-merged-abba00472f/1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2/minecraft-merged-abba00472f-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2.jar assets/ data /
Gradle
- 在 Docker 容器中的 mc_missile 目录下运行这些命令。
./gradlew validateAccessWidener
cp ./env.sh.example ./env.sh 并输入你所需的配置
./gradlew runServer
部署
cp ./env.sh.example ./env.sh 并输入你的 modrinth token(只需执行一次)
source ./env.sh
./gradlew modrinth
- 你也可以在
./build/libs/mc_missile-1.0.0.jar 中找到最终的 jar 包
格式化
- 下载 google-java-format
- 运行
find ./src -name '*.java' -type f -print0 | xargs -0 java -jar ~/dwn/google-java-format-1.26.0-all-deps.jar --aosp -r
Blow up your friends in Minecraft 1.21.4 with guided missiles.
This is a server-only Fabric Minecraft mod.
It allows all players to program guided missiles and fire them from a crossbow or dispenser.
See Guided Missiles in Minecraft for what you can do with this mod.
Application Structure
This is a special Minecraft mod that connects to external processes through gRPC.

Every player programs a guidance server application.
These guidance servers could be hosted in Docker containers on the same host as the Minecraft server.
Whenever a missile is fired Minecraft connects to the player's guidance server and sends the missile state (e.g., position, velocity) every tick.
The guidance server can send control inputs to the missile after each received missile state.
Developing Missile Guidance
You can implement your guidance server in any language you like.
It has to do two things:
- Read the
PORT environment variable.
- Expose a gRPC server at that port adhering to the protocol defined in src/main/proto/guidance.proto.
This
guidance.proto file contains more documentation about the specifics of that protocol.
The Guided Missiles in Minecraft article by Christopher Besch gives a detailed description of what a guidance system can do and how to achieve that.
Guidance Server Templates
Right now there are these templates to get you started right away:
Other People's Guidance Code
There are a few open-source guidance servers you can use for inspiration:
Flight Dynamics
Like the player the missile is an entity in Minecraft.
The missile has
-
a position $p = \begin{pmatrix} p_1 \ p_2 \ p_3 \end{pmatrix} \in \mathbb{R}^3$ (with the elevation $p_2$),
-
velocity $v \in \mathbb{R}^3$,
-
pitch $\theta \in [-90, 90]$ and
-
yaw $\psi \in [-180, 180]$.
These angles are in degrees and there's no roll.
Additionally, they are the negated angles displayed in the Mincraft F3 Menu.
That's because projectiles have flipped headings for some reason:
$\theta=90$ is up, $\theta=-90$ down and $\psi \in {-180, 180}$ is north, $\psi = 90$ east, $\psi = 0$ south and $\psi = -90$ west.
Minecraft updates the missile's state every tick (20 times a second).
The update in tick $t \in \mathbb{N}_0$ is separated into three stages:
-
Receive the control input:
The missile's only input method is an unrealisticly beefy control moment gyroscope.
So the player's guidance code produces a requested change in pitch $\theta_{in}$ and yaw $\psi_{in}$.
It has no direct control over the missiles position, velocity, or thrust — only the rotation.
-
Update the missile's state:
The gyroscope is powerful but not overly powerful.
When the control input is too large (larger than $M_r$ defined by the airframe), it is scaled down linearly:
\begin{aligned}
l &= \sqrt{\theta_{in}^2 + \psi_{in}^2} \\
\begin{pmatrix} \theta_{in} \\ \psi_{in} \end{pmatrix}
&\rightarrow \max{\left\{\frac{M_r}{l}, 1\right\}}
\begin{pmatrix} \theta_{in} \\ \psi_{in} \end{pmatrix}.
\end{aligned}
With this, Minecraft applies the adjusted control input plus some random noise.
\begin{aligned}
\theta &\rightarrow \theta + \theta_{in} + N_r \\
\psi &\rightarrow \psi + \psi_{in} + N_r \\
\end{aligned}
each $N_r$ is normally distributed noise dependent on the air frame used by the missile.
So you don't have perfect control over the missiles rotation, there is always some variance.
Now the acceleration $a \in \mathbb{R}^3$ can be calculated from the rotation vector $r \in \mathbb{R}^3$, the current thrust $T(t) \in [0, \infty)$ and gravity $g = \begin{pmatrix} 0 \ -|g| \ 0 \end{pmatrix} \in \mathbb{R}^3$.
\begin{aligned}
r & =
\begin{pmatrix}
\sin(\psi) \cos(\theta) \\
\sin(\theta) \\
\cos(\psi) \cos(\theta)
\end{pmatrix} \\
a & = \begin{pmatrix} a_1 \\ a_2 \\ a_3 \end{pmatrix} \\
& = \left(T(t) + N_T \right) \cdot r + g
\end{aligned}
$N_T$ is normally distributed noise and like the thrust function $T$ defined by the rocket motor.
Lastly, the velocity and position are updated with the airframe defined drag $d \in [0, 1)$.
\begin{aligned}
v &\rightarrow (1 - d) \cdot (v + a) \\
p &\rightarrow p + v
\end{aligned}
-
Now that the missile's state has been updated Minecraft sends that state to the player's guidance code.
All these values contain some variance, too — depending on the missile's inertial measurement unit.
The guidance server has a little less than 50ms to send the rotation change for the next tick.
In the first tick ($t=0$), the missile doesn't have guidance input yet and thus flies straight ahead with the velocity and rotation of the shooter.
No variance is applied here.
Disclaimer:
As you can see the flight dynamics of Minecraft missiles don't have anything to do with real missiles.
There are no aerodynamic aspects simulated at all, for example.
All we do is magically rotate a rock in vacuum.
Thus the guidance code explained in this article can only be applied to the toy world that is Minecraft and nothing else.
Still, it'll be fun!
Crafting Your First Missile
This is a server-only mod so you don't have to install any mods on your Minecraft client.
As such there are no new items coming with this mod.
All missiles are normal firework rocket items before launch.
There are two special things differentiating missiles from normal Minecraft fireworks:
- the item's name and
- the ingredients used to craft the missile.
Missile Naming
In Minecraft you can change an item's name with an anvil.
To convert a normal firework rockt into a missile you have need to give your firework rocket a special name.
<- the id of the guidance server to use
<- some string that is passed to the guidance server
m/69/test_name
This allows the Minecraft mod to identify what guidance server should be used.
Additionally, each guidance server can implement multiple different missiles.
You still need to fulfill the ingredient requirements in the below section to craft a working missile.
Missile Budget
Your missile needs to be crafted with at least one firework star.
There are many ways of crafting a missile.
The mc_missile mod calculated what ingredients you used to craft the firework item.
It gives every ingredient a value and adds these values up.
This is the budget of the missile, which can be used to improve the missile's characteristics, see the Missile Components section.
Note:
When you craft a firework rocket you get three firework rockets from one crafting recipe.
If you invest one diamond into such a recipe, you'll have three firework rockets with 1/3 the value of a diamond each.
Example:
A simple firework star can be crafted from one gunpowder and one dye.
With this you can craft the cheapest missile:
That firework star, one gunpowder and a paper and you get three missile with a budget of 99€.
These are all values for every possible ingredient.
==== Material Values ====
PAPER = 90€
GUNPOWDER = 90€
DYE = 27€
BLAZE_POWDER = 900€
COAL = 180€
GOLD_NUGGET = 90€
HEAD = 90000€
FEATHER = 180€
DIAMOND = 9000€
GLOWSTONE_DUST = 90€
Lowest Possible Missile Budget = 99€
Highest Possible Missile Budget = 231543€
==== Material Values ====
Missile Components
A missile is built from components, each with a price tag and effects on the missile.
See guidance.proto for what effects they have.
These are the components' prices:
==== Hardware Component Costs ====
== Warhead Costs ==
BLANK = 0€
TNT_M = 450€
TNT_L = 9000€
TNT_XL = 90000€
INCENDIARY_M = 900€
INCENDIARY_L = 18000€
INCENDIARY_XL = 180000€
NEUTRON_BOMB_S = 450€
NEUTRON_BOMB_L = 900€
TUNGSTEN_PENETRATOR_S = 180€
TUNGSTEN_PENETRATOR_M = 450€
TUNGSTEN_PENETRATOR_L = 900€
BUNKER_BUSTER_M = 18000€
BUNKER_BUSTER_L = 27000€
BUNKER_BUSTER_XL = 180000€
== Warhead Costs ==
== Airframe Costs ==
SPACE_SHUTTLE = 450000€
BRICK = 0€
DEFAULT_AIRFRAME = 180€
PERFECT_AIRFRAME = 1800€
== Airframe Costs ==
== Motor Costs ==
NO_MOTOR = 0€
SIMPLE_S = 900€
SIMPLE_M = 1800€
SIMPLE_L = 2700€
SIMPLE_XL = 90000€
BOOST_S = 450€
BOOST_M = 900€
TWO_STAGE_M = 450€
TWO_STAGE_L = 900€
RANDOM_S = 450€
RANDOM_L = 900€
CHANGING_S = 450€
CHANGING_M = 900€
CHANGING_L = 1350€
== Motor Costs ==
== Battery Costs ==
NO_BATTERY = 0€
LI_ION_XS = 450€
LI_ION_S = 900€
LI_ION_M = 1350€
LI_ION_L = 2700€
LI_ION_XL = 5400€
LI_ION_XXL = 9000€
NUCLEAR = 90000€
== Battery Costs ==
== Seeker Costs ==
NO_SEEKER = 0€
IR_SEEKER_WIDE_S = 9000€
IR_SEEKER_WIDE_L = 18000€
IR_SEEKER_WIDE_INACCURATE_S = 6000€
IR_SEEKER_WIDE_INACCURATE_L = 12000€
IR_SEEKER_SNIPER_S = 6000€
IR_SEEKER_SNIPER_L = 12000€
IR_SEEKER_SNIPER_INACCURATE_S = 2000€
IR_SEEKER_SNIPER_INACCURATE_L = 4000€
IR_SEEKER_360_S = 12000€
IR_SEEKER_360_L = 24000€
IR_SEEKER_360_INACCURATE_S = 6000€
IR_SEEKER_360_INACCURATE_L = 12000€
LASER_DISTANCE_SEEKER = 3000€
== Seeker Costs ==
== InertialSystem Costs ==
BLIND = 0€
BAD_IMU = 180€
DEFAULT_IMU = 1260€
ACCURATE_IMU = 2700€
PERFECT_IMU = 9000€
== InertialSystem Costs ==
Cheapest Possible Missile = 0€
Most Expensive Possible Missile = 843000€
==== Hardware Component Costs ====
The summed prices of all components must be smaller or equal to the missile's budget.
Mod Installation
This mod is designed to be used by a Docker deployment.
Take a look at the example_deployment and it's docker-compose.yml.
Mod Development
Development environment
- Install Docker.
- Create the dev container in this directory with:
sudo docker run --net host -ti --name mc_missile_java -v ./:/home/gradle/mc_missile -p 25565:25565 --entrypoint /bin/bash gradle
- When you leave that shell start the container again with:
sudo docker start mc_missile_java
- Now you can enter it with:
sudo docker exec -ti mc_missile_java /bin/bash
Decompile Minecraft
- run these commands in the mc_missile directory in the Docker container.
./gradlew genSources
jar xf ../.gradle/loom-cache/minecraftMaven/net/minecraft/minecraft-merged-abba00472f/1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2/minecraft-merged-abba00472f-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2-sources.jar com /net
jar xf ../.gradle/loom-cache/minecraftMaven/net/minecraft/minecraft-merged-abba00472f/1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2/minecraft-merged-abba00472f-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2.jar assets/ data /
Gradle
- run these commands in the mc_missile directory in the Docker container.
./gradlew validateAccessWidener
cp ./env.sh.example ./env.sh and enter your desired config
./gradlew runServer
Deploy
cp ./env.sh.example ./env.sh and enter your modrinth token (only do this once)
source ./env.sh
./gradlew modrinth
- you can also find the final jar in
./build/libs/mc_missile-1.0.0.jar
Formatting
- Download google-java-format
- run
find ./src -name '*.java' -type f -print0 | xargs -0 java -jar ~/dwn/google-java-format-1.26.0-all-deps.jar --aosp -r
评论 0
登录后参与评分
还没有评论,来抢沙发吧