以下是一个简单的实体代码示例:

package com.example.mymod.entities;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.ai.goal.WanderAroundGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.world.World;

public class MyEntity extends HostileEntity {
    
    public MyEntity(EntityType<? extends HostileEntity> entityType, World world) {
        super(entityType, world);
    }
    
    public static DefaultAttributeContainer.Builder createMyEntityAttributes() {
        return LivingEntity.createLivingAttributes()
                .add(EntityAttributes.GENERIC_MAX_HEALTH, 10.0)
                .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 4.0)
                .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25)
                .add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0);
    }
    
    @Override
    protected void initGoals() {
        this.goalSelector.add(0, new SwimGoal(this));
        this.goalSelector.add(1, new MeleeAttackGoal(this, 1.0, true));
        this.goalSelector.add(2, new WanderAroundGoal(this, 1.0));
        this.goalSelector.add(3, new LookAtEntityGoal(this, LivingEntity.class, 8.0f));
    }
    
    @Override
    public SpawnType getSpawnType() {
        return SpawnType.NATURAL;
    }
}

在这个示例中,MyEntity 是一个继承自 HostileEntity 的实体类。它有一些基本的属性(如最大生命值、攻击力、移动速度和跟随范围),并且具有一些行为目标(如游泳、近战攻击、漫游和盯着玩家)。

请注意,这只是一个简单的示例,你可以根据自己的需求自定义实体的属性和行为。你还可以在 initGoals() 方法中添加其他行为目标,或者在实体类中添加其他方法和属性

我的世界 Java 版 mod 实体 代码

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

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