
net.minecraft.server.EntitySkeleton Maven / Gradle / Ivy
package net.minecraft.server;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.entity.EntityCombustEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Calendar;
public class EntitySkeleton extends EntityMonster implements IRangedEntity {
private final PathfinderGoalArrowAttack a = new PathfinderGoalArrowAttack(this, 1.0D, 20, 60, 15.0F);
private final PathfinderGoalMeleeAttack b = new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.2D, false);
public EntitySkeleton(World world) {
super(world);
this.goalSelector.addTask(1, new PathfinderGoalFloat(this));
this.goalSelector.addTask(2, new PathfinderGoalRestrictSun(this));
this.goalSelector.addTask(3, new PathfinderGoalFleeSun(this, 1.0D));
this.goalSelector.addTask(3, new PathfinderGoalAvoidTarget(this, EntityWolf.class, 6.0F, 1.0D, 1.2D));
this.goalSelector.addTask(4, new PathfinderGoalRandomStroll(this, 1.0D));
this.goalSelector.addTask(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
this.goalSelector.addTask(6, new PathfinderGoalRandomLookaround(this));
this.targetSelector.addTask(1, new PathfinderGoalHurtByTarget(this, false));
this.targetSelector.addTask(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true));
this.targetSelector.addTask(3, new PathfinderGoalNearestAttackableTarget(this, EntityIronGolem.class, true));
if (world != null && !world.isClientSide) {
this.n();
}
}
@NotNull
@Override
public Skeleton getEntityBukkit() {
return (Skeleton) super.getEntityBukkit();
}
protected void initAttributes() {
super.initAttributes();
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.25D);
}
protected void entityInit() {
super.entityInit();
this.datawatcher.a(13, new Byte((byte) 0));
}
protected String getLivingSound() {
return "mob.skeleton.say";
}
protected String getHurtSound() {
return "mob.skeleton.hurt";
}
protected String getDeathSound() {
return "mob.skeleton.death";
}
protected void playStepSound(BlockPosition pos, Block block) {
this.playSound("mob.skeleton.step", 0.15F, 1.0F);
}
public boolean attackEntityAsMob(Entity entity) {
if (super.attackEntityAsMob(entity)) {
if (this.getSkeletonType() == 1 && entity instanceof EntityLiving) {
((EntityLiving) entity).addEffect(new MobEffect(MobEffectList.WITHER.id, 200));
}
return true;
} else {
return false;
}
}
public EnumMonsterType getMonsterType() {
return EnumMonsterType.UNDEAD;
}
public void onLivingUpdate() {
if (this.world.w() && !this.world.isClientSide) {
float f = this.getBrightness(1.0F);
BlockPosition blockposition = new BlockPosition(this.locX, (double) Math.round(this.locY), this.locZ);
if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.i(blockposition)) {
boolean flag = true;
ItemStack itemstack = this.getEquipment(4);
if (itemstack != null) {
if (itemstack.isItemStackDamageable()) {
itemstack.setItemDamage(itemstack.getItemDamage() + this.random.nextInt(2));
if (itemstack.getItemDamage() >= itemstack.getMaxDamage()) {
this.renderBrokenItemStack(itemstack);
this.setEquipment(4, null);
}
}
flag = false;
}
if (flag) {
// CraftBukkit start
EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), 8);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.setOnFire(event.getDuration());
}
// CraftBukkit end
}
}
}
if (this.world.isClientSide && this.getSkeletonType() == 1) {
this.setSize(0.72F, 2.535F);
}
super.onLivingUpdate();
}
public void updateRidden() {
super.updateRidden();
if (this.vehicle instanceof EntityCreature) {
EntityCreature entitycreature = (EntityCreature) this.vehicle;
this.renderYawOffset = entitycreature.renderYawOffset;
}
}
public void onDeath(DamageSource cause) {
// super.die(damagesource); // CraftBukkit
if (cause.i() instanceof EntityArrow && cause.getEntity() instanceof EntityHuman) {
EntityHuman entityhuman = (EntityHuman) cause.getEntity();
double d0 = entityhuman.locX - this.locX;
double d1 = entityhuman.locZ - this.locZ;
if (d0 * d0 + d1 * d1 >= 2500.0D) {
entityhuman.b(AchievementList.v);
}
} else if (cause.getEntity() instanceof EntityCreeper && ((EntityCreeper) cause.getEntity()).isPowered() && ((EntityCreeper) cause.getEntity()).cp()) {
((EntityCreeper) cause.getEntity()).cq();
// CraftBukkit start
// this.a(new ItemStack(Items.SKULL, 1, this.getSkeletonType() == 1 ? 1 : 0), 0.0F);
headDrop = new ItemStack(Items.SKULL, 1, this.getSkeletonType() == 1 ? 1 : 0);
// CraftBukkit end
}
super.onDeath(cause); // CraftBukkit - moved from above
}
/* CraftBukkit start
protected Item getLoot() {
return Items.ARROW;
}
// CraftBukkit end */
protected void dropDeathLoot(boolean wasRecentlyHit, int lootingModifier) {
super.dropDeathLoot(wasRecentlyHit, lootingModifier); // CraftBukkit
int j;
int k;
if (this.getSkeletonType() == 1) {
j = this.random.nextInt(3 + lootingModifier) - 1;
for (k = 0; k < j; ++k) {
this.dropItem(Items.COAL, 1);
}
} else {
j = this.random.nextInt(3 + lootingModifier);
for (k = 0; k < j; ++k) {
this.dropItem(Items.ARROW, 1);
}
}
j = this.random.nextInt(3 + lootingModifier);
for (k = 0; k < j; ++k) {
this.dropItem(Items.BONE, 1);
}
}
protected void getRareDrop() {
if (this.getSkeletonType() == 1) {
this.dropItem(new ItemStack(Items.SKULL, 1, 1), 0.0F);
}
}
protected void setEquipmentBasedOnDifficulty(DifficultyDamageScaler scaler) {
super.setEquipmentBasedOnDifficulty(scaler);
this.setEquipment(0, new ItemStack(Items.BOW));
}
public GroupDataEntity prepare(DifficultyDamageScaler scaler, GroupDataEntity data) {
data = super.prepare(scaler, data);
if (this.world.worldProvider instanceof WorldProviderHell && this.getRandom().nextInt(5) > 0) {
this.goalSelector.addTask(4, this.b);
this.setSkeletonType(1);
this.setEquipment(0, new ItemStack(Items.STONE_SWORD));
this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(4.0D);
} else {
this.goalSelector.addTask(4, this.a);
this.setEquipmentBasedOnDifficulty(scaler);
this.setEnchantmentBasedOnDifficulty(scaler);
}
this.setCanPickUpLoot(this.random.nextFloat() < 0.55F * scaler.c());
if (this.getEquipment(4) == null) {
Calendar calendar = this.world.Y();
if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.random.nextFloat() < 0.25F) {
this.setEquipment(4, new ItemStack(this.random.nextFloat() < 0.1F ? Blocks.LIT_PUMPKIN : Blocks.PUMPKIN));
this.dropChances[4] = 0.0F;
}
}
return data;
}
public void n() {
this.goalSelector.removeTask(this.b);
this.goalSelector.removeTask(this.a);
ItemStack itemstack = this.getHeldItem();
if (itemstack != null && itemstack.getItem() == Items.BOW) {
this.goalSelector.addTask(4, this.a);
} else {
this.goalSelector.addTask(4, this.b);
}
}
public void a(EntityLiving entityliving, float f) {
EntityArrow entityarrow = new EntityArrow(this.world, this, entityliving, 1.6F, (float) (14 - this.world.getDifficulty().a() * 4));
int i = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, this.getHeldItem());
int j = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, this.getHeldItem());
entityarrow.setDamage((double) (f * 2.0F) + this.random.nextGaussian() * 0.25D + (double) ((float) this.world.getDifficulty().a() * 0.11F));
if (i > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
}
if (j > 0) {
entityarrow.setKnockbackStrength(j);
}
if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, this.getHeldItem()) > 0 || this.getSkeletonType() == 1) {
// CraftBukkit start - call EntityCombustEvent
EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
entityarrow.setOnFire(event.getDuration());
}
// CraftBukkit end
}
// CraftBukkit start
org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getHeldItem(), entityarrow, 0.8F);
if (event.isCancelled()) {
event.getProjectile().remove();
return;
}
if (event.getProjectile() == entityarrow.getBukkitEntity()) {
world.addEntity(entityarrow);
}
// CraftBukkit end
this.playSound("random.bow", 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
// this.world.addEntity(entityarrow); // CraftBukkit - moved up
}
public int getSkeletonType() {
return this.datawatcher.getByte(13);
}
public void setSkeletonType(int i) {
this.datawatcher.watch(13, Byte.valueOf((byte) i));
this.fireProof = i == 1;
if (i == 1) {
this.setSize(0.72F, 2.535F);
} else {
this.setSize(0.6F, 1.95F);
}
}
public void loadEntityData(NBTTagCompound tag) {
super.loadEntityData(tag);
if (tag.hasKeyOfType("SkeletonType", 99)) {
byte b0 = tag.getByte("SkeletonType");
this.setSkeletonType(b0);
}
this.n();
}
public void saveEntityData(NBTTagCompound tag) {
super.saveEntityData(tag);
tag.setByte("SkeletonType", (byte) this.getSkeletonType());
}
public void setEquipment(int slot, ItemStack item) {
super.setEquipment(slot, item);
if (!this.world.isClientSide && slot == 0) {
this.n();
}
}
public float getHeadHeight() {
return this.getSkeletonType() == 1 ? super.getHeadHeight() : 1.74F;
}
public double getYOffset() {
return this.isBaby() ? 0.0D : -0.35D;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy