Minecraft 1.20.1 Fabric 模组:击败僵尸生成'鸡你太美'鸡

本教程将指导您创建 Minecraft 1.20.1 Fabric 模组,实现击败僵尸后生成一只名为'鸡你太美'的鸡。

步骤:

  1. 准备环境:

    • 确保已安装 Minecraft Launcher 和 Fabric Loader。
    • 创建新的 mod 项目,使用您喜欢的 IDE (例如 IntelliJ IDEA)。
  2. 创建自定义僵尸实体类:

    • 创建一个名为 CustomZombieEntity 的新 Java 类。
    • 继承 net.minecraft.entity.mob.ZombieEntity 类。
    • 覆盖 onKilledOther 方法,该方法在实体击败其他实体时被调用。
@Override
public boolean onKilledOther(ServerWorld world, LivingEntity entity) {
    if (entity instanceof ZombieEntity) {
        // 当僵尸击败另一个僵尸时,调用父类的onKilledOther方法处理
        return super.onKilledOther(world, entity);
    } else if (entity instanceof PlayerEntity) {
        // 当僵尸击败玩家时,在击败位置生成一只名为'鸡你太美'的鸡
        ChickenEntity chicken = EntityType.CHICKEN.create(world);
        chicken.setCustomName(new LiteralText('鸡你太美'));
        chicken.setCustomNameVisible(true);
        chicken.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.getYaw(), this.getPitch());
        world.spawnEntity(chicken);
    }
    return super.onKilledOther(world, entity);
}
  1. 注册自定义僵尸实体:
    • 在 mod 的主类 (通常是项目的入口类) 中注册 CustomZombieEntity
public class ExampleMod implements ModInitializer {
    @Override
    public void onInitialize() {
        // 注册自定义僵尸实体
        FabricDefaultAttributeRegistry.register(CustomZombieEntity.TYPE, CustomZombieEntity.createZombieAttributes());
    }
}
  1. 构建并运行模组:
    • 构建您的模组并运行 Minecraft。

现在,当您在游戏中击败一个僵尸时,它将在击败的位置生成一只名为'鸡你太美'的鸡。

注意:

  • 确保您的模组环境配置正确,并且您已设置了正确的 Minecraft 版本和 Fabric 版本。
  • 如果您遇到任何问题,请参考 Fabric 文档或寻求帮助。
Minecraft 1.20.1 Fabric 模组:击败僵尸生成'鸡你太美'鸡

原文地址: https://www.cveoy.top/t/topic/qoqV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录