版本信息
你使用的系统:window 10
你是用的JDK: 不清楚怎么看
你使用的IDE:IntelliJ IDEA
你使用的IDE版本:2020.2 x64
Forge版本: 1.15.2-31.2
Minecraft版本: 1.15.2
错误情况简述
我仿照原版的恶魂写了一个实体和ai,原版恶魂的类里面有一个MovementHelperController我完全没搞懂是干什么的,但是不加他的话就动不了或者一直往前走。
相关代码
我的实体类中的ai
static class RandomFlyGoal extends Goal {
private final EyeOfCthulhu eyeOfCthulhu;
public RandomFlyGoal(EyeOfCthulhu eoc) {
this.eyeOfCthulhu = eoc;
this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
}
public boolean shouldExecute() {
MovementController movementcontroller = this.eyeOfCthulhu.getMoveHelper();
if (!movementcontroller.isUpdating()) {
return true;
} else {
double d0 = movementcontroller.getX() - this.eyeOfCthulhu.getPosX();
double d1 = movementcontroller.getY() - this.eyeOfCthulhu.getPosY();
double d2 = movementcontroller.getZ() - this.eyeOfCthulhu.getPosZ();
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
return d3 < 1.0D || d3 > 3600.0D;
}
}
public boolean shouldContinueExecuting() {
return false;
}
public void startExecuting() {
Random random = this.eyeOfCthulhu.getRNG();
double d0 = this.eyeOfCthulhu.getPosX() + (double)((random.nextFloat() * 2.0F - 1.0F) * 6.0F);
double d1 = this.eyeOfCthulhu.getPosY() + (double)((random.nextFloat() * 2.0F - 1.0F) * 6.0F);
double d2 = this.eyeOfCthulhu.getPosZ() + (double)((random.nextFloat() * 2.0F - 1.0F) * 6.0F);
this.eyeOfCthulhu.getMoveHelper().setMoveTo(d0, d1, d2, 1.0D);
}
}
那个MovementHelperController
static class MoveHelperController extends MovementController {
private final EyeOfCthulhu eyeOfCthulhu;
private int coolDown;
public MoveHelperController(EyeOfCthulhu eoc) {
super(eoc);
this.eyeOfCthulhu = eoc;
}
public void tick() {
if (this.action == MovementController.Action.MOVE_TO) {
if (this.coolDown-- <= 0) {
this.coolDown += this.eyeOfCthulhu.getRNG().nextInt(5) + 2;
Vec3d vec3d = new Vec3d(this.posX - this.eyeOfCthulhu.getPosX(),
this.posY - this.eyeOfCthulhu.getPosY(),
this.posZ - this.eyeOfCthulhu.getPosZ());
double d0 = vec3d.length();
vec3d = vec3d.normalize();
if (this.func_220673_a(vec3d, MathHelper.ceil(d0))) {
this.eyeOfCthulhu.setMotion(this.eyeOfCthulhu.getMotion().add(vec3d.scale(0.1D)));
System.out.println(this.eyeOfCthulhu.getMotion());
} else {
this.action = MovementController.Action.WAIT;
}
}
}
}
private boolean func_220673_a(Vec3d p_220673_1_, int p_220673_2_) {
AxisAlignedBB axisalignedbb = this.eyeOfCthulhu.getBoundingBox();
for(int i = 1; i < p_220673_2_; ++i) {
axisalignedbb = axisalignedbb.offset(p_220673_1_);
if (!this.eyeOfCthulhu.world.hasNoCollisions(this.eyeOfCthulhu, axisalignedbb)) {
return false;
}
}
return true;
}
}
上面这俩完全是从原版复制过来的