Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
cn.nukkit.entity.passive.EntityPig Maven / Gradle / Ivy
package cn.nukkit.entity.passive;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.EntityWalkable;
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.FluctuateController;
import cn.nukkit.entity.ai.controller.LookController;
import cn.nukkit.entity.ai.controller.WalkController;
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.nbt.tag.CompoundTag;
import java.util.Set;
/**
* @author BeYkeRYkt (Nukkit Project)
*/
public class EntityPig extends EntityAnimal implements EntityWalkable {
public static final int NETWORK_ID = 12;
public EntityPig(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}
@Override
public IBehaviorGroup requireBehaviorGroup() {
return new BehaviorGroup(
this.tickSpread,
Set.of(
//用于刷新InLove状态的核心行为
new Behavior(
new InLoveExecutor(400),
all(
new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_FEED_TIME, 0, 400),
new PassByTimeEvaluator(CoreMemoryTypes.LAST_IN_LOVE_TIME, 6000, Integer.MAX_VALUE)
),
1, 1
),
//生长
new Behavior(
new AnimalGrowExecutor(),
//todo:Growth rate
all(
new PassByTimeEvaluator(CoreMemoryTypes.ENTITY_SPAWN_TIME, 20 * 60 * 20, Integer.MAX_VALUE),
entity -> entity instanceof EntityAnimal animal && animal.isBaby()
)
, 1, 1, 1200
)
),
Set.of(
new Behavior(new FlatRandomRoamExecutor(0.4f, 12, 40, true, 100, true, 10), new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_ATTACKED_TIME, 0, 100), 4, 1),
new Behavior(new EntityBreedingExecutor<>(EntityPig.class, 16, 100, 0.5f), entity -> entity.getMemoryStorage().get(CoreMemoryTypes.IS_IN_LOVE), 3, 1),
new Behavior(new MoveToTargetExecutor(CoreMemoryTypes.NEAREST_FEEDING_PLAYER, 0.4f, 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 FlatRandomRoamExecutor(0.2f, 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 FluctuateController()),
new SimpleFlatAStarRouteFinder(new WalkingPosEvaluator(), this),
this
);
}
@Override
public float getWidth() {
if (this.isBaby()) {
return 0.45f;
}
return 0.9f;
}
@Override
public float getHeight() {
if (this.isBaby()) {
return 0.45f;
}
return 0.9f;
}
@Override
public void initEntity() {
this.setMaxHealth(10);
super.initEntity();
}
@PowerNukkitOnly
@Since("1.5.1.0-PN")
@Override
public String getOriginalName() {
return "Pig";
}
@Override
public Item[] getDrops() {
return new Item[]{Item.get(((this.isOnFire()) ? Item.COOKED_PORKCHOP : Item.RAW_PORKCHOP))};
}
@Override
public int getNetworkId() {
return NETWORK_ID;
}
@Override
public boolean isBreedingItem(Item item) {
int id = item.getId();
return id == Item.CARROT || id == Item.POTATO || id == Item.BEETROOT;
}
}