50 lines
1.2 KiB
Java
50 lines
1.2 KiB
Java
package net.minecraft.world.entity.ai.goal;
|
|
|
|
import java.util.EnumSet;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.TamableAnimal;
|
|
import net.minecraft.world.entity.ai.goal.Goal.Flag;
|
|
|
|
public class SitWhenOrderedToGoal extends Goal {
|
|
private final TamableAnimal mob;
|
|
|
|
public SitWhenOrderedToGoal(TamableAnimal mob) {
|
|
this.mob = mob;
|
|
this.setFlags(EnumSet.of(Flag.JUMP, Flag.MOVE));
|
|
}
|
|
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
return this.mob.isOrderedToSit();
|
|
}
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
boolean bl = this.mob.isOrderedToSit();
|
|
if (!bl && !this.mob.isTame()) {
|
|
return false;
|
|
} else if (this.mob.isInWater()) {
|
|
return false;
|
|
} else if (!this.mob.onGround()) {
|
|
return false;
|
|
} else {
|
|
LivingEntity livingEntity = this.mob.getOwner();
|
|
if (livingEntity == null) {
|
|
return true;
|
|
} else {
|
|
return this.mob.distanceToSqr(livingEntity) < 144.0 && livingEntity.getLastHurtByMob() != null ? false : bl;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void start() {
|
|
this.mob.getNavigation().stop();
|
|
this.mob.setInSittingPose(true);
|
|
}
|
|
|
|
@Override
|
|
public void stop() {
|
|
this.mob.setInSittingPose(false);
|
|
}
|
|
}
|