cn.nukkit.entity.passive.EntityCow Maven / Gradle / Ivy
package cn.nukkit.entity.passive;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.ai.behavior.Behavior;
import cn.nukkit.entity.ai.behaviorgroup.BehaviorGroup;
import cn.nukkit.entity.ai.behaviorgroup.IBehaviorGroup;
import cn.nukkit.entity.ai.controller.LookController;
import cn.nukkit.entity.ai.controller.WalkController;
import cn.nukkit.entity.ai.evaluator.AllMatchEvaluator;
import cn.nukkit.entity.ai.evaluator.MemoryCheckNotEmptyEvaluator;
import cn.nukkit.entity.ai.evaluator.PassByTimeEvaluator;
import cn.nukkit.entity.ai.evaluator.ProbabilityEvaluator;
import cn.nukkit.entity.ai.executor.*;
import cn.nukkit.entity.ai.memory.CoreMemoryTypes;
import cn.nukkit.entity.ai.route.finder.impl.SimpleFlatAStarRouteFinder;
import cn.nukkit.entity.ai.route.posevaluator.WalkingPosEvaluator;
import cn.nukkit.entity.ai.sensor.NearestFeedingPlayerSensor;
import cn.nukkit.entity.ai.sensor.NearestPlayerSensor;
import cn.nukkit.item.Item;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import java.util.Set;
/**
* @author BeYkeRYkt (Nukkit Project)
*/
public class EntityCow extends EntityWalkingAnimal {
public static final int NETWORK_ID = 11;
private IBehaviorGroup behaviorGroup;
public EntityCow(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}
@Override
public IBehaviorGroup getBehaviorGroup() {
if (behaviorGroup == null) {
behaviorGroup = new BehaviorGroup(
this.tickSpread,
Set.of(
//用于刷新InLove状态的核心行为
new Behavior(
new InLoveExecutor(400),
new AllMatchEvaluator(
new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_FED_TIME, 0, 400),
new PassByTimeEvaluator(CoreMemoryTypes.LAST_IN_LOVE_TIME, 6000, Integer.MAX_VALUE)
),
1, 1
)
),
Set.of(
new Behavior(new RandomRoamExecutor(0.25f, 12, 40, true, 100, true, 10), new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_ATTACKED_TIME, 0, 100), 4, 1),
new Behavior(new EntityBreedingExecutor<>(EntityCow.class, 16, 100, 0.5f), entity -> entity.getMemoryStorage().get(CoreMemoryTypes.IS_IN_LOVE), 3, 1),
new Behavior(new MoveToTargetExecutor(CoreMemoryTypes.NEAREST_FEEDING_PLAYER, 0.25f, true), new MemoryCheckNotEmptyEvaluator(CoreMemoryTypes.NEAREST_FEEDING_PLAYER), 2, 1),
new Behavior(new LookAtTargetExecutor(CoreMemoryTypes.NEAREST_PLAYER, 100), new ProbabilityEvaluator(4, 10), 1, 1, 100),
new Behavior(new RandomRoamExecutor(0.1f, 12, 100, false, -1, true, 10), (entity -> true), 1, 1)
),
Set.of(new NearestFeedingPlayerSensor(8, 0), new NearestPlayerSensor(8, 0, 20)),
Set.of(new WalkController(), new LookController(true, true)),
new SimpleFlatAStarRouteFinder(new WalkingPosEvaluator(), this)
);
}
return behaviorGroup;
}
@Override
public float getWidth() {
if (this.isBaby()) {
return 0.45f;
}
return 0.9f;
}
@Override
public float getHeight() {
if (this.isBaby()) {
return 0.65f;
}
return 1.3f;
}
@PowerNukkitOnly
@Since("1.5.1.0-PN")
@Override
public String getOriginalName() {
return "Cow";
}
@Override
public Item[] getDrops() {
return new Item[]{Item.get(Item.LEATHER), Item.get(((this.isOnFire()) ? Item.COOKED_BEEF : Item.RAW_BEEF))};
}
@Override
public int getNetworkId() {
return NETWORK_ID;
}
@Override
protected void initEntity() {
this.setMaxHealth(10);
super.initEntity();
}
@Override
public boolean onInteract(Player player, Item item, Vector3 clickedPos) {
if (super.onInteract(player, item, clickedPos)) {
return true;
}
if (item.getId() == Item.BUCKET && item.getDamage() == 0) {
item.count--;
player.getInventory().addItem(Item.get(Item.BUCKET, 1));
return true;
}
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy