====== 添加粒子效果 ====== 粒子效果是用于特殊事件和附加的视觉特效。它们被用在爆炸效果,火焰效果,滴水效果以及更多上! ===== 添加简单的粒子效果 ===== 简单的粒子效果可以只用 Minecraft 原本的粒子工厂来实现。这意味着粒子所有的行为都必须和一个原版中已经存在的粒子相同。作为例子,我们将实现一个被用在火把上的粒子效果 - ''火焰粒子效果'' 的绿色变种。 ==== 初始化注册 ==== 首先,在你的 ''ModInitializer'' 中注册你的粒子: public class ExampleMod implements ModInitializer { // instance of our particle public static final DefaultParticleType GREEN_FLAME = FabricParticleTypes.simple(); @Override public void onInitialize() { Registry.register(Registry.PARTICLE_TYPE, new Identifier("modid", "green_flame"), GREEN_FLAME); } } ==== 客户端注册 ==== 现在我们需要在客户端侧注册它。创建一个实现 ''ClientModInitializer'' 的类(如果没有的话): public class ExampleModClient implements ClientModInitializer { @Override public void onInitializeClient() { /* Adds our particle textures to vanilla's Texture Atlas so it can be shown properly. * Modify the namespace and particle id accordingly. * * This is only used if you plan to add your own textures for the particle. Otherwise, remove this.*/ ClientSpriteRegistryCallback.event(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).register(((atlasTexture, registry) -> { registry.register(new Identifier("modid", "particle/green_flame")); })); /* Registers our particle client-side. * First argument is our particle's instance, created previously on ExampleMod. * Second argument is the particle's factory. The factory controls how the particle behaves. * In this example, we'll use FlameParticle's Factory.*/ ParticleFactoryRegistry.getInstance().register(ExampleMod.GREEN_FLAME, FlameParticle.Factory::new); } } ==== 模型和纹理 ==== 我们的粒子现在被正确的实现了... //code-wise//. 在开始游戏之前,你将需要创建两个文件:粒子的 **model** 以及 **texture**. { "textures": [ "modid:green_flame" ] } 这将告诉Minecraft哪些纹理用于我们的粒子。由于我们使用的是 FlameParticle 的工厂,所以我们将只使用一个粒子,就像前者一样。 **提示:** 你可以使用Minecraft自己的纹理! 现在,将你的粒子纹理添加到下面的路径中: src/main/resources/assets/modid/textures/particle/ 推荐的纹理大小是 **16x16** 像素。 如果所有操作都正确,你的粒子效果现在应该可以完美地工作!您可以使用命令 ''/particle modid:green_flame ~ ~ ~'' 对其进行测试。 ===== 添加复杂粒子效果 ===== 未完待续 这个教程的源代码可以在这里找到: [[https://github.com/Luligabi1/ParticleExampleMod|ParticleExampleMod]]