生成一个Minecraft1201 fabric的模组要求:打一下僵尸生成一只名为’鸡你太美‘的鸡
要生成一个Minecraft 1.20.1 fabric的mod,让击败僵尸后生成一只名为'鸡你太美'的鸡,你可以按照以下步骤进行操作:
-
首先,确保你已经安装了Minecraft Launcher和Fabric Loader。
-
在你的mod开发环境中创建一个新的mod项目,可以使用你喜欢的IDE,如IntelliJ IDEA。
-
在你的mod项目中创建一个新的Java类,命名为"CustomZombieEntity"(或任何你喜欢的名称)。
-
在该类中,继承Minecraft的ZombieEntity(僵尸实体)类,它位于
net.minecraft.entity.mob包中。 -
覆盖
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);
}
- 在mod的主类(一般是mod项目中的入口类)中注册自定义僵尸实体。
public class ExampleMod implements ModInitializer {
@Override
public void onInitialize() {
// 注册自定义僵尸实体
FabricDefaultAttributeRegistry.register(CustomZombieEntity.TYPE, CustomZombieEntity.createZombieAttributes());
}
}
- 构建并运行你的mod。
现在,当你在游戏中击败一个僵尸,它将生成一只名为'鸡你太美'的鸡。请确保你的mod环境配置正确,并且你已经设置了正确的Minecraft版本和Fabric版本
原文地址: https://www.cveoy.top/t/topic/iHX9 著作权归作者所有。请勿转载和采集!