
net.minecraft.server.EntityPig Maven / Gradle / Ivy
package net.minecraft.server;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.entity.Pig;
import org.jetbrains.annotations.NotNull;
public class EntityPig extends EntityAnimal {
private final PathfinderGoalPassengerCarrotStick bm;
@NotNull
@Override
public Pig getEntityBukkit() {
return (Pig) super.getEntityBukkit();
}
public EntityPig(World world) {
super(world);
this.setSize(0.9F, 0.9F);
((Navigation) this.getNavigation()).a(true);
this.goalSelector.addTask(0, new PathfinderGoalFloat(this));
this.goalSelector.addTask(1, new PathfinderGoalPanic(this, 1.25D));
this.goalSelector.addTask(2, this.bm = new PathfinderGoalPassengerCarrotStick(this, 0.3F));
this.goalSelector.addTask(3, new PathfinderGoalBreed(this, 1.0D));
this.goalSelector.addTask(4, new PathfinderGoalTempt(this, 1.2D, Items.CARROT_ON_A_STICK, false));
this.goalSelector.addTask(4, new PathfinderGoalTempt(this, 1.2D, Items.CARROT, false));
this.goalSelector.addTask(5, new PathfinderGoalFollowParent(this, 1.1D));
this.goalSelector.addTask(6, new PathfinderGoalRandomStroll(this, 1.0D));
this.goalSelector.addTask(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
this.goalSelector.addTask(8, new PathfinderGoalRandomLookaround(this));
}
protected void initAttributes() {
super.initAttributes();
this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(10.0D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.25D);
}
public boolean canBeSteered() {
ItemStack itemstack = ((EntityHuman) this.passenger).getHeldItem();
return itemstack != null && itemstack.getItem() == Items.CARROT_ON_A_STICK;
}
protected void entityInit() {
super.entityInit();
this.datawatcher.a(16, Byte.valueOf((byte) 0));
}
public void saveEntityData(NBTTagCompound tag) {
super.saveEntityData(tag);
tag.setBoolean("Saddle", this.hasSaddle());
}
public void loadEntityData(NBTTagCompound tag) {
super.loadEntityData(tag);
this.setSaddle(tag.getBoolean("Saddle"));
}
protected String getLivingSound() {
return "mob.pig.say";
}
protected String getHurtSound() {
return "mob.pig.say";
}
protected String getDeathSound() {
return "mob.pig.death";
}
protected void playStepSound(BlockPosition pos, Block block) {
this.playSound("mob.pig.step", 0.15F, 1.0F);
}
public boolean interact(EntityHuman player) {
if (super.interact(player)) {
return true;
} else if (this.hasSaddle() && !this.world.isClientSide && (this.passenger == null || this.passenger == player)) {
player.mount(this);
return true;
} else {
return false;
}
}
protected Item getLoot() {
return this.isBurning() ? Items.COOKED_PORKCHOP : Items.PORKCHOP;
}
protected void dropDeathLoot(boolean wasRecentlyHit, int lootingModifier) {
int j = this.random.nextInt(3) + 1 + this.random.nextInt(1 + lootingModifier);
for (int k = 0; k < j; ++k) {
if (this.isBurning()) {
this.dropItem(Items.COOKED_PORKCHOP, 1);
} else {
this.dropItem(Items.PORKCHOP, 1);
}
}
if (this.hasSaddle()) {
this.dropItem(Items.SADDLE, 1);
}
}
public boolean hasSaddle() {
return (this.datawatcher.getByte(16) & 1) != 0;
}
public void setSaddle(boolean flag) {
if (flag) {
this.datawatcher.watch(16, Byte.valueOf((byte) 1));
} else {
this.datawatcher.watch(16, Byte.valueOf((byte) 0));
}
}
public void onStruckByLightning(EntityLightning lightning) {
if (!this.world.isClientSide && !this.dead) {
EntityPigZombie entitypigzombie = new EntityPigZombie(this.world);
// CraftBukkit start
if (CraftEventFactory.callPigZapEvent(this, lightning, entitypigzombie).isCancelled()) {
return;
}
// CraftBukkit end
entitypigzombie.setEquipment(0, new ItemStack(Items.GOLDEN_SWORD));
entitypigzombie.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
entitypigzombie.setAI(this.hasAI());
if (this.hasCustomName()) {
entitypigzombie.setCustomName(this.getCustomName());
entitypigzombie.setCustomNameVisible(this.getCustomNameVisible());
}
// CraftBukkit - added a reason for spawning this creature
this.world.addEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
this.die();
}
}
public void fall(float f, float f1) {
super.fall(f, f1);
if (f > 5.0F && this.passenger instanceof EntityHuman) {
((EntityHuman) this.passenger).b(AchievementList.u);
}
}
public EntityPig b(EntityAgeable entityageable) {
return new EntityPig(this.world);
}
public boolean d(ItemStack itemstack) {
return itemstack != null && itemstack.getItem() == Items.CARROT;
}
public PathfinderGoalPassengerCarrotStick cm() {
return this.bm;
}
public EntityAgeable createChild(EntityAgeable entityageable) {
return this.b(entityageable);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy