mirror of
https://github.com/barkeser2002/Tenet.git
synced 2026-09-25 08:00:07 +03:00
608 lines
28 KiB
Diff
608 lines
28 KiB
Diff
@@ -1094,10 +1301,11 @@
|
|
|
|
this.noActionTime = 0;
|
|
float f1 = f;
|
|
- boolean flag = false;
|
|
+ boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below
|
|
float f2 = 0.0F;
|
|
|
|
- if (f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
|
|
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
|
|
+ if (false && f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
|
|
this.hurtCurrentlyUsedShield(f);
|
|
f2 = f;
|
|
f = 0.0F;
|
|
@@ -1115,27 +1323,46 @@
|
|
this.animationSpeed = 1.5F;
|
|
boolean flag1 = true;
|
|
|
|
- if ((float) this.invulnerableTime > 10.0F) {
|
|
+ if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F) { // CraftBukkit - restore use of maxNoDamageTicks
|
|
if (f <= this.lastHurt) {
|
|
return false;
|
|
}
|
|
|
|
- this.actuallyHurt(damagesource, f - this.lastHurt);
|
|
+ // CraftBukkit start
|
|
+ if (!this.damageEntity0(damagesource, f - this.lastHurt)) {
|
|
+ return false;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.lastHurt = f;
|
|
flag1 = false;
|
|
} else {
|
|
+ // CraftBukkit start
|
|
+ if (!this.damageEntity0(damagesource, f)) {
|
|
+ return false;
|
|
+ }
|
|
this.lastHurt = f;
|
|
- this.invulnerableTime = 20;
|
|
- this.actuallyHurt(damagesource, f);
|
|
+ this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks
|
|
+ // this.damageEntity0(damagesource, f);
|
|
+ // CraftBukkit end
|
|
this.hurtDuration = 10;
|
|
this.hurtTime = this.hurtDuration;
|
|
}
|
|
|
|
- if (damagesource.isDamageHelmet() && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
|
|
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
|
|
+ if (false && damagesource.isDamageHelmet() && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
|
|
this.hurtHelmet(damagesource, f);
|
|
f *= 0.75F;
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ if (this instanceof EntityAnimal) {
|
|
+ ((EntityAnimal) this).resetLove();
|
|
+ if (this instanceof EntityTameableAnimal) {
|
|
+ ((EntityTameableAnimal) this).setOrderedToSit(false);
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
this.hurtDir = 0.0F;
|
|
Entity entity1 = damagesource.getEntity();
|
|
|
|
@@ -1258,19 +1485,32 @@
|
|
EnumHand[] aenumhand = EnumHand.values();
|
|
int i = aenumhand.length;
|
|
|
|
+ // CraftBukkit start
|
|
+ EnumHand hand = null;
|
|
+ ItemStack itemstack1 = ItemStack.EMPTY;
|
|
for (int j = 0; j < i; ++j) {
|
|
EnumHand enumhand = aenumhand[j];
|
|
- ItemStack itemstack1 = this.getItemInHand(enumhand);
|
|
+ itemstack1 = this.getItemInHand(enumhand);
|
|
|
|
if (itemstack1.is(Items.TOTEM_OF_UNDYING)) {
|
|
+ hand = enumhand; // CraftBukkit
|
|
itemstack = itemstack1.copy();
|
|
- itemstack1.shrink(1);
|
|
+ // itemstack1.subtract(1); // CraftBukkit
|
|
break;
|
|
}
|
|
}
|
|
|
|
- if (itemstack != null) {
|
|
- if (this instanceof EntityPlayer) {
|
|
+ org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
|
|
+ EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity(), handSlot);
|
|
+ event.setCancelled(itemstack == null);
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ if (!itemstack1.isEmpty()) {
|
|
+ itemstack1.shrink(1);
|
|
+ }
|
|
+ if (itemstack != null && this instanceof EntityPlayer) {
|
|
+ // CraftBukkit end
|
|
EntityPlayer entityplayer = (EntityPlayer) this;
|
|
|
|
entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
|
|
@@ -1278,14 +1518,16 @@
|
|
}
|
|
|
|
this.setHealth(1.0F);
|
|
- this.removeAllEffects();
|
|
- this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1));
|
|
- this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1));
|
|
- this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0));
|
|
+ // CraftBukkit start
|
|
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
|
|
+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
|
|
+ this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
|
|
+ this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
|
|
+ // CraftBukkit end
|
|
this.level.broadcastEntityEvent(this, (byte) 35);
|
|
}
|
|
|
|
- return itemstack != null;
|
|
+ return !event.isCancelled();
|
|
}
|
|
}
|
|
|
|
@@ -1390,14 +1632,22 @@
|
|
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
|
|
|
|
if (this.level.getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level, blockposition)) {
|
|
- this.level.setBlock(blockposition, iblockdata, 3);
|
|
- flag = true;
|
|
+ // CraftBukkit start - call EntityBlockFormEvent for Wither Rose
|
|
+ flag = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this.level, blockposition, iblockdata, 3, this);
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
if (!flag) {
|
|
EntityItem entityitem = new EntityItem(this.level, this.getX(), this.getY(), this.getZ(), new ItemStack(Items.WITHER_ROSE));
|
|
|
|
+ // CraftBukkit start
|
|
+ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
|
|
+ CraftEventFactory.callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.level.addFreshEntity(entityitem);
|
|
}
|
|
}
|
|
@@ -1417,21 +1667,40 @@
|
|
|
|
boolean flag = this.lastHurtByPlayerTime > 0;
|
|
|
|
+ this.dropEquipment(); // CraftBukkit - from below
|
|
if (this.shouldDropLoot() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
|
|
this.dropFromLootTable(damagesource, flag);
|
|
this.dropCustomDeathLoot(damagesource, i, flag);
|
|
}
|
|
+ // CraftBukkit start - Call death event
|
|
+ CraftEventFactory.callEntityDeathEvent(this, this.drops);
|
|
+ this.drops = new ArrayList<>();
|
|
+ // CraftBukkit end
|
|
|
|
- this.dropEquipment();
|
|
+ // this.dropInventory();// CraftBukkit - moved up
|
|
this.dropExperience();
|
|
}
|
|
|
|
protected void dropEquipment() {}
|
|
|
|
- protected void dropExperience() {
|
|
+ // CraftBukkit start
|
|
+ public int getExpReward() {
|
|
if (this.level instanceof WorldServer && !this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
|
|
- EntityExperienceOrb.award((WorldServer) this.level, this.position(), this.getExperienceReward());
|
|
+ int i = this.getExperienceReward();
|
|
+ return i;
|
|
+ } else {
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
+ protected void dropExperience() {
|
|
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
|
|
+ if (true && !(this instanceof net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon)) { // CraftBukkit - SPIGOT-2420: Special case ender dragon will drop the xp over time
|
|
+ EntityExperienceOrb.award((WorldServer) this.level, this.position(), this.expToDrop);
|
|
+ this.expToDrop = 0;
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
@@ -1559,9 +1850,14 @@
|
|
int i = this.calculateFallDamage(f, f1);
|
|
|
|
if (i > 0) {
|
|
+ // CraftBukkit start
|
|
+ if (!this.hurt(damagesource, (float) i)) {
|
|
+ return true;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.playSound(this.getFallDamageSound(i), 1.0F, 1.0F);
|
|
this.playBlockFallSound();
|
|
- this.hurt(damagesource, (float) i);
|
|
+ // this.damageEntity(damagesource, (float) i); // CraftBukkit - moved up
|
|
return true;
|
|
} else {
|
|
return flag;
|
|
@@ -1610,7 +1906,7 @@
|
|
|
|
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
|
|
if (!damagesource.isBypassArmor()) {
|
|
- this.hurtArmor(damagesource, f);
|
|
+ // this.damageArmor(damagesource, f); // CraftBukkit - Moved into damageEntity0(DamageSource, float)
|
|
f = CombatMath.getDamageAfterAbsorb(f, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
|
|
}
|
|
|
|
@@ -1623,7 +1919,8 @@
|
|
} else {
|
|
int i;
|
|
|
|
- if (this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
|
|
+ // CraftBukkit - Moved to damageEntity0(DamageSource, float)
|
|
+ if (false && this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
|
|
i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
|
|
int j = 25 - i;
|
|
float f1 = f * (float) j;
|
|
@@ -1656,29 +1953,172 @@
|
|
}
|
|
}
|
|
|
|
- protected void actuallyHurt(DamageSource damagesource, float f) {
|
|
- if (!this.isInvulnerableTo(damagesource)) {
|
|
- f = this.getDamageAfterArmorAbsorb(damagesource, f);
|
|
- f = this.getDamageAfterMagicAbsorb(damagesource, f);
|
|
- float f1 = f;
|
|
+ // CraftBukkit start
|
|
+ protected boolean damageEntity0(final DamageSource damagesource, float f) { // void -> boolean, add final
|
|
+ if (!this.isInvulnerableTo(damagesource)) {
|
|
+ final boolean human = this instanceof EntityHuman;
|
|
+ float originalDamage = f;
|
|
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ if (damagesource.isDamageHelmet() && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
|
|
+ return -(f - (f * 0.75F));
|
|
+
|
|
+ }
|
|
+ return -0.0;
|
|
+ }
|
|
+ };
|
|
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
|
|
+ f += hardHatModifier;
|
|
+
|
|
+ Function<Double, Double> blocking = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ return -((EntityLiving.this.isDamageSourceBlocked(damagesource)) ? f : 0.0);
|
|
+ }
|
|
+ };
|
|
+ float blockingModifier = blocking.apply((double) f).floatValue();
|
|
+ f += blockingModifier;
|
|
+
|
|
+ Function<Double, Double> armor = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ return -(f - EntityLiving.this.getDamageAfterArmorAbsorb(damagesource, f.floatValue()));
|
|
+ }
|
|
+ };
|
|
+ float armorModifier = armor.apply((double) f).floatValue();
|
|
+ f += armorModifier;
|
|
+
|
|
+ Function<Double, Double> resistance = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ if (!damagesource.isBypassMagic() && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
|
|
+ int i = (EntityLiving.this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
|
|
+ int j = 25 - i;
|
|
+ float f1 = f.floatValue() * (float) j;
|
|
+ return -(f - (f1 / 25.0F));
|
|
+ }
|
|
+ return -0.0;
|
|
+ }
|
|
+ };
|
|
+ float resistanceModifier = resistance.apply((double) f).floatValue();
|
|
+ f += resistanceModifier;
|
|
+
|
|
+ Function<Double, Double> magic = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue()));
|
|
+ }
|
|
+ };
|
|
+ float magicModifier = magic.apply((double) f).floatValue();
|
|
+ f += magicModifier;
|
|
+
|
|
+ Function<Double, Double> absorption = new Function<Double, Double>() {
|
|
+ @Override
|
|
+ public Double apply(Double f) {
|
|
+ return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionAmount(), 0.0F), 0.0F));
|
|
+ }
|
|
+ };
|
|
+ float absorptionModifier = absorption.apply((double) f).floatValue();
|
|
+
|
|
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
|
|
+ if (damagesource.getEntity() instanceof EntityHuman) {
|
|
+ ((EntityHuman) damagesource.getEntity()).resetAttackStrengthTicker(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
|
|
+ }
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ f = (float) event.getFinalDamage();
|
|
+
|
|
+ // Resistance
|
|
+ if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
|
|
+ float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
|
|
+ if (f3 > 0.0F && f3 < 3.4028235E37F) {
|
|
+ if (this instanceof EntityPlayer) {
|
|
+ ((EntityPlayer) this).awardStat(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
|
+ } else if (damagesource.getEntity() instanceof EntityPlayer) {
|
|
+ ((EntityPlayer) damagesource.getEntity()).awardStat(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Apply damage to helmet
|
|
+ if (damagesource.isDamageHelmet() && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
|
|
+ this.hurtHelmet(damagesource, f);
|
|
+ }
|
|
+
|
|
+ // Apply damage to armor
|
|
+ if (!damagesource.isBypassArmor()) {
|
|
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
|
|
+ this.hurtArmor(damagesource, armorDamage);
|
|
+ }
|
|
+
|
|
+ // Apply blocking code // PAIL: steal from above
|
|
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
|
|
+ this.level.broadcastEntityEvent(this, (byte) 29); // SPIGOT-4635 - shield damage sound
|
|
+ this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
|
|
+ Entity entity = damagesource.getDirectEntity();
|
|
+
|
|
+ if (entity instanceof EntityLiving) {
|
|
+ this.blockUsingShield((EntityLiving) entity);
|
|
+ }
|
|
+ }
|
|
|
|
- f = Math.max(f - this.getAbsorptionAmount(), 0.0F);
|
|
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - f));
|
|
- float f2 = f1 - f;
|
|
+ absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
|
|
+ this.setAbsorptionAmount(Math.max(this.getAbsorptionAmount() - absorptionModifier, 0.0F));
|
|
+ float f2 = absorptionModifier;
|
|
|
|
+ if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof EntityHuman) {
|
|
+ ((EntityHuman) this).awardStat(StatisticList.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
|
+ }
|
|
if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof EntityPlayer) {
|
|
((EntityPlayer) damagesource.getEntity()).awardStat(StatisticList.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
|
|
}
|
|
|
|
- if (f != 0.0F) {
|
|
+ if (f > 0 || !human) {
|
|
+ if (human) {
|
|
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
|
|
+ ((EntityHuman) this).causeFoodExhaustion(damagesource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
|
|
+ if (f < 3.4028235E37F) {
|
|
+ ((EntityHuman) this).awardStat(StatisticList.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
float f3 = this.getHealth();
|
|
|
|
this.setHealth(f3 - f);
|
|
this.getCombatTracker().recordDamage(damagesource, f3, f);
|
|
- this.setAbsorptionAmount(this.getAbsorptionAmount() - f);
|
|
+ // CraftBukkit start
|
|
+ if (!human) {
|
|
+ this.setAbsorptionAmount(this.getAbsorptionAmount() - f);
|
|
+ }
|
|
this.gameEvent(GameEvent.ENTITY_DAMAGE);
|
|
+
|
|
+ return true;
|
|
+ } else {
|
|
+ // Duplicate triggers if blocking
|
|
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
|
|
+ if (this instanceof EntityPlayer) {
|
|
+ CriterionTriggers.ENTITY_HURT_PLAYER.trigger((EntityPlayer) this, damagesource, f, originalDamage, true);
|
|
+ f2 = (float) -event.getDamage(DamageModifier.BLOCKING);
|
|
+ if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
|
+ ((EntityPlayer) this).awardStat(StatisticList.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (damagesource.getEntity() instanceof EntityPlayer) {
|
|
+ CriterionTriggers.PLAYER_HURT_ENTITY.trigger((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ } else {
|
|
+ return originalDamage > 0;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
+ return false; // CraftBukkit
|
|
}
|
|
|
|
public CombatTracker getCombatTracker() {
|
|
@@ -1699,9 +2139,19 @@
|
|
}
|
|
|
|
public final void setArrowCount(int i) {
|
|
- this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, i);
|
|
+ // CraftBukkit start
|
|
+ setArrowCount(i, false);
|
|
}
|
|
|
|
+ public final void setArrowCount(int i, boolean flag) {
|
|
+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, getArrowCount(), i, flag);
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, event.getNewAmount());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public final int getStingerCount() {
|
|
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
|
|
}
|
|
@@ -1996,6 +2446,12 @@
|
|
|
|
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
|
|
|
|
+ // CraftBukkit start
|
|
+ public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) {
|
|
+ this.setItemSlot(enumitemslot, itemstack);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
|
|
|
|
@@ -2239,6 +2695,7 @@
|
|
}
|
|
|
|
if (this.onGround && !this.level.isClientSide) {
|
|
+ if (getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
|
|
this.setSharedFlag(7, false);
|
|
}
|
|
} else {
|
|
@@ -2772,6 +3229,7 @@
|
|
}
|
|
|
|
if (!this.level.isClientSide) {
|
|
+ if (flag != this.getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
|
|
this.setSharedFlag(7, flag);
|
|
}
|
|
|
|
@@ -2931,14 +3389,21 @@
|
|
|
|
@Override
|
|
public boolean isPickable() {
|
|
- return !this.isRemoved();
|
|
+ return !this.isRemoved() && this.collides; // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
public boolean isPushable() {
|
|
- return this.isAlive() && !this.isSpectator() && !this.onClimbable();
|
|
+ return this.isAlive() && !this.isSpectator() && !this.onClimbable() && this.collides; // CraftBukkit
|
|
}
|
|
|
|
+ // CraftBukkit start - collidable API
|
|
+ @Override
|
|
+ public boolean canCollideWithBukkit(Entity entity) {
|
|
+ return isPushable() && this.collides != this.collidableExemptions.contains(entity.getUUID());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public float getYHeadRot() {
|
|
return this.yHeadRot;
|
|
@@ -3133,7 +3598,26 @@
|
|
} else {
|
|
if (!this.useItem.isEmpty() && this.isUsingItem()) {
|
|
this.triggerItemUseEffects(this.useItem, 16);
|
|
- ItemStack itemstack = this.useItem.finishUsingItem(this.level, this);
|
|
+ // CraftBukkit start - fire PlayerItemConsumeEvent
|
|
+ ItemStack itemstack;
|
|
+ if (this instanceof EntityPlayer) {
|
|
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
|
|
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand);
|
|
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand);
|
|
+ level.getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ // Update client
|
|
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
|
|
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ itemstack = (craftItem.equals(event.getItem())) ? this.useItem.finishUsingItem(this.level, this) : CraftItemStack.asNMSCopy(event.getItem()).finishUsingItem(level, this);
|
|
+ } else {
|
|
+ itemstack = this.useItem.finishUsingItem(this.level, this);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
if (itemstack != this.useItem) {
|
|
this.setItemInHand(enumhand, itemstack);
|
|
@@ -3211,6 +3695,12 @@
|
|
}
|
|
|
|
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
|
|
+ // CraftBukkit start
|
|
+ return randomTeleport(d0, d1, d2, flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN).orElse(false);
|
|
+ }
|
|
+
|
|
+ public Optional<Boolean> randomTeleport(double d0, double d1, double d2, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
|
|
+ // CraftBukkit end
|
|
double d3 = this.getX();
|
|
double d4 = this.getY();
|
|
double d5 = this.getZ();
|
|
@@ -3235,16 +3725,41 @@
|
|
}
|
|
|
|
if (flag2) {
|
|
- this.teleportTo(d0, d6, d2);
|
|
+ // CraftBukkit start - Teleport event
|
|
+ // this.teleportTo(d0, d6, d2);
|
|
+
|
|
+ // first set position, to check if the place to teleport is valid
|
|
+ this.setPos(d0, d6, d2);
|
|
if (world.noCollision((Entity) this) && !world.containsAnyLiquid(this.getBoundingBox())) {
|
|
flag1 = true;
|
|
}
|
|
+ // now revert and call event if the teleport place is valid
|
|
+ this.setPos(d3, d4, d5);
|
|
+
|
|
+ if (flag1) {
|
|
+ if (!(this instanceof EntityPlayer)) {
|
|
+ EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), new Location(this.level.getWorld(), d3, d4, d5), new Location(this.level.getWorld(), d0, d6, d2));
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(teleport);
|
|
+ if (!teleport.isCancelled()) {
|
|
+ Location to = teleport.getTo();
|
|
+ this.teleportTo(to.getX(), to.getY(), to.getZ());
|
|
+ } else {
|
|
+ return Optional.empty();
|
|
+ }
|
|
+ } else {
|
|
+ // player teleport event is called in the underlining code
|
|
+ if (((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), java.util.Collections.emptySet(), false, cause)) {
|
|
+ return Optional.empty();
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
if (!flag1) {
|
|
- this.teleportTo(d3, d4, d5);
|
|
- return false;
|
|
+ // this.enderTeleportTo(d3, d4, d5); // CraftBukkit - already set the location back
|
|
+ return Optional.of(false); // CraftBukkit
|
|
} else {
|
|
if (flag) {
|
|
world.broadcastEntityEvent(this, (byte) 46);
|
|
@@ -3254,7 +3769,7 @@
|
|
((EntityCreature) this).getNavigation().stop();
|
|
}
|
|
|
|
- return true;
|
|
+ return Optional.of(true); // CraftBukkit
|
|
}
|
|
}
|
|
|
|
@@ -3337,7 +3852,7 @@
|
|
}
|
|
|
|
public void stopSleeping() {
|
|
- Optional optional = this.getSleepingPos();
|
|
+ Optional<BlockPosition> optional = this.getSleepingPos(); // CraftBukkit - decompile error
|
|
World world = this.level;
|
|
|
|
java.util.Objects.requireNonNull(this.level);
|
|
@@ -3369,7 +3884,7 @@
|
|
|
|
@Nullable
|
|
public EnumDirection getBedOrientation() {
|
|
- BlockPosition blockposition = (BlockPosition) this.getSleepingPos().orElse((Object) null);
|
|
+ BlockPosition blockposition = (BlockPosition) this.getSleepingPos().orElse(null); // CraftBukkit - decompile error
|
|
|
|
return blockposition != null ? BlockBed.getBedOrientation(this.level, blockposition) : null;
|
|
}
|
|
@@ -3417,7 +3932,7 @@
|
|
Pair<MobEffect, Float> pair = (Pair) iterator.next();
|
|
|
|
if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) {
|
|
- entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst()));
|
|
+ entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst()), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit
|
|
}
|
|
}
|
|
}
|