aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player')
-rw-r--r--patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Inventory.java.patch100
-rw-r--r--patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Player.java.patch519
2 files changed, 619 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Inventory.java.patch b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Inventory.java.patch
new file mode 100644
index 0000000000..c8952ba42c
--- /dev/null
+++ b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Inventory.java.patch
@@ -0,0 +1,100 @@
+--- a/net/minecraft/world/entity/player/Inventory.java
++++ b/net/minecraft/world/entity/player/Inventory.java
+@@ -26,7 +26,12 @@
+ import net.minecraft.world.item.ItemStack;
+ import net.minecraft.world.level.block.state.BlockState;
+
+-public class Inventory implements Container, Nameable {
++// CraftBukkit start
++import java.util.ArrayList;
++import org.bukkit.Location;
++import org.bukkit.craftbukkit.entity.CraftHumanEntity;
++import org.bukkit.entity.HumanEntity;
++// CraftBukkit end
+
+ public static final int POP_TIME_DURATION = 5;
+ public static final int INVENTORY_SIZE = 36;
+@@ -43,6 +50,54 @@
+ public final Player player;
+ private int timesChanged;
+
++ // CraftBukkit start - add fields and methods
++ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
++ private int maxStack = MAX_STACK;
++
++ public List<ItemStack> getContents() {
++ List<ItemStack> combined = new ArrayList<ItemStack>(items.size() + armor.size() + offhand.size());
++ for (List<net.minecraft.world.item.ItemStack> sub : this.compartments) {
++ combined.addAll(sub);
++ }
++
++ return combined;
++ }
++
++ public List<ItemStack> getArmorContents() {
++ return this.armor;
++ }
++
++ public void onOpen(CraftHumanEntity who) {
++ transaction.add(who);
++ }
++
++ public void onClose(CraftHumanEntity who) {
++ transaction.remove(who);
++ }
++
++ public List<HumanEntity> getViewers() {
++ return transaction;
++ }
++
++ public org.bukkit.inventory.InventoryHolder getOwner() {
++ return this.player.getBukkitEntity();
++ }
++
++ @Override
++ public int getMaxStackSize() {
++ return maxStack;
++ }
++
++ public void setMaxStackSize(int size) {
++ maxStack = size;
++ }
++
++ @Override
++ public Location getLocation() {
++ return player.getBukkitEntity().getLocation();
++ }
++ // CraftBukkit end
++
+ public Inventory(Player player) {
+ this.items = NonNullList.withSize(36, ItemStack.EMPTY);
+ this.armor = NonNullList.withSize(4, ItemStack.EMPTY);
+@@ -63,6 +118,28 @@
+ return !itemstack.isEmpty() && ItemStack.isSameItemSameTags(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
+ }
+
++ // CraftBukkit start - Watch method above! :D
++ public int canHold(ItemStack itemstack) {
++ int remains = itemstack.getCount();
++ for (int i = 0; i < this.items.size(); ++i) {
++ ItemStack itemstack1 = this.getItem(i);
++ if (itemstack1.isEmpty()) return itemstack.getCount();
++
++ if (this.hasRemainingSpaceForItem(itemstack1, itemstack)) {
++ remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
++ }
++ if (remains <= 0) return itemstack.getCount();
++ }
++ ItemStack offhandItemStack = this.getItem(this.items.size() + this.armor.size());
++ if (this.hasRemainingSpaceForItem(offhandItemStack, itemstack)) {
++ remains -= (offhandItemStack.getMaxStackSize() < this.getMaxStackSize() ? offhandItemStack.getMaxStackSize() : this.getMaxStackSize()) - offhandItemStack.getCount();
++ }
++ if (remains <= 0) return itemstack.getCount();
++
++ return itemstack.getCount() - remains;
++ }
++ // CraftBukkit end
++
+ public int getFreeSlot() {
+ for (int i = 0; i < this.items.size(); ++i) {
+ if (((ItemStack) this.items.get(i)).isEmpty()) {
diff --git a/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Player.java.patch b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Player.java.patch
new file mode 100644
index 0000000000..8eb24b7af0
--- /dev/null
+++ b/patch-remap/mache-spigotflower-stripped/net/minecraft/world/entity/player/Player.java.patch
@@ -0,0 +1,519 @@
+--- a/net/minecraft/world/entity/player/Player.java
++++ b/net/minecraft/world/entity/player/Player.java
+@@ -111,6 +112,16 @@
+ import net.minecraft.world.scores.PlayerTeam;
+ import net.minecraft.world.scores.Scoreboard;
+ import org.slf4j.Logger;
++import org.bukkit.craftbukkit.entity.CraftHumanEntity;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.craftbukkit.util.CraftVector;
++import org.bukkit.entity.Item;
++import org.bukkit.event.entity.CreatureSpawnEvent;
++import org.bukkit.event.entity.EntityCombustByEntityEvent;
++import org.bukkit.event.entity.EntityExhaustionEvent;
++import org.bukkit.event.player.PlayerDropItemEvent;
++import org.bukkit.event.player.PlayerVelocityEvent;
++// CraftBukkit end
+
+ public abstract class Player extends LivingEntity {
+
+@@ -136,10 +148,10 @@
+ protected static final EntityDataAccessor<CompoundTag> DATA_SHOULDER_RIGHT = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
+ private long timeEntitySatOnShoulder;
+ private final Inventory inventory = new Inventory(this);
+- protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer();
++ protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer(this); // CraftBukkit - add "this" to constructor
+ public final InventoryMenu inventoryMenu;
+ public AbstractContainerMenu containerMenu;
+- protected FoodData foodData = new FoodData();
++ protected FoodData foodData = new FoodData(this); // CraftBukkit - add "this" to constructor
+ protected int jumpTriggerTime;
+ public float oBob;
+ public float bob;
+@@ -168,7 +180,17 @@
+ public FishingHook fishing;
+ protected float hurtDir;
+
+- public Player(Level level, BlockPos blockpos, float f, GameProfile gameprofile) {
++ // CraftBukkit start
++ public boolean fauxSleeping;
++ public int oldLevel = -1;
++
++ @Override
++ public CraftHumanEntity getBukkitEntity() {
++ return (CraftHumanEntity) super.getBukkitEntity();
++ }
++ // CraftBukkit end
++
++ public Player(Level level, BlockPos pos, float yRot, GameProfile gameProfile) {
+ super(EntityType.PLAYER, level);
+ this.lastItemInMainHand = ItemStack.EMPTY;
+ this.cooldowns = this.createItemCooldowns();
+@@ -315,7 +334,7 @@
+ ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
+
+ if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(FluidTags.WATER)) {
+- this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
++ this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
+ }
+
+ }
+@@ -495,8 +504,14 @@
+ public void rideTick() {
+ if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
+ this.stopRiding();
+- this.setShiftKeyDown(false);
+- } else {
++ // CraftBukkit start - SPIGOT-7316: no longer passenger, dismount and return
++ if (!this.isPassenger()) {
++ this.setShiftKeyDown(false);
++ return;
++ }
++ }
++ {
++ // CraftBukkit end
+ super.rideTick();
+ this.oBob = this.bob;
+ this.bob = 0.0F;
+@@ -520,7 +533,8 @@
+
+ if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
+ if (this.getHealth() < this.getMaxHealth() && this.tickCount % 20 == 0) {
+- this.heal(1.0F);
++ // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
++ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
+ }
+
+ if (this.foodData.needsFood() && this.tickCount % 10 == 0) {
+@@ -683,7 +693,14 @@
+ }
+
+ @Nullable
+- public ItemEntity drop(ItemStack itemstack, boolean flag, boolean flag1) {
++ public ItemEntity drop(ItemStack droppedItem, boolean dropAround, boolean includeThrowerName) {
++ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
++ return drop(droppedItem, dropAround, includeThrowerName, true);
++ }
++
++ @Nullable
++ public ItemEntity drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
++ // CraftBukkit end
+ if (itemstack.isEmpty()) {
+ return null;
+ } else {
+@@ -718,7 +735,34 @@
+ itementity.setDeltaMovement((double) (-f3 * f2 * 0.3F) + Math.cos((double) f5) * (double) f6, (double) (-f1 * 0.3F + 0.1F + (this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (f4 * f2 * 0.3F) + Math.sin((double) f5) * (double) f6);
+ }
+
+- return itementity;
++ // CraftBukkit start - fire PlayerDropItemEvent
++ if (!callEvent) { // SPIGOT-2942: Add boolean to call event
++ return entityitem;
++ }
++ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.getBukkitEntity();
++ Item drop = (Item) entityitem.getBukkitEntity();
++
++ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
++ this.level().getCraftServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
++ if (flag1 && (cur == null || cur.getAmount() == 0)) {
++ // The complete stack was dropped
++ player.getInventory().setItemInHand(drop.getItemStack());
++ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) {
++ // Only one item is dropped
++ cur.setAmount(cur.getAmount() + 1);
++ player.getInventory().setItemInHand(cur);
++ } else {
++ // Fallback
++ player.getInventory().addItem(drop.getItemStack());
++ }
++ return null;
++ }
++ // CraftBukkit end
++
++ return entityitem;
+ }
+ }
+
+@@ -872,12 +912,12 @@
+ return false;
+ } else {
+ if (!this.level().isClientSide) {
+- this.removeEntitiesOnShoulder();
++ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
+ }
+
+ if (damagesource.scalesWithDifficulty()) {
+ if (this.level().getDifficulty() == Difficulty.PEACEFUL) {
+- f = 0.0F;
++ return false; // CraftBukkit - f = 0.0f -> return false
+ }
+
+ if (this.level().getDifficulty() == Difficulty.EASY) {
+@@ -889,7 +929,13 @@
+ }
+ }
+
+- return f == 0.0F ? false : super.hurt(damagesource, f);
++ // CraftBukkit start - Don't filter out 0 damage
++ boolean damaged = super.hurt(source, amount);
++ if (damaged) {
++ this.removeEntitiesOnShoulder();
++ }
++ return damaged;
++ // CraftBukkit end
+ }
+ }
+ }
+@@ -910,11 +954,30 @@
+ return !this.getAbilities().invulnerable && super.canBeSeenAsEnemy();
+ }
+
+- public boolean canHarmPlayer(Player player) {
+- PlayerTeam playerteam = this.getTeam();
+- PlayerTeam playerteam1 = player.getTeam();
++ public boolean canHarmPlayer(Player other) {
++ // CraftBukkit start - Change to check OTHER player's scoreboard team according to API
++ // To summarize this method's logic, it's "Can parameter hurt this"
++ org.bukkit.scoreboard.Team team;
++ if (other instanceof ServerPlayer) {
++ ServerPlayer thatPlayer = (ServerPlayer) other;
++ team = thatPlayer.getBukkitEntity().getScoreboard().getPlayerTeam(thatPlayer.getBukkitEntity());
++ if (team == null || team.allowFriendlyFire()) {
++ return true;
++ }
++ } else {
++ // This should never be called, but is implemented anyway
++ org.bukkit.OfflinePlayer thisPlayer = other.level().getCraftServer().getOfflinePlayer(other.getScoreboardName());
++ team = other.level().getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
++ if (team == null || team.allowFriendlyFire()) {
++ return true;
++ }
++ }
+
+- return playerteam == null ? true : (!playerteam.isAlliedTo(playerteam1) ? true : playerteam.isAllowFriendlyFire());
++ if (this instanceof ServerPlayer) {
++ return !team.hasPlayer(((ServerPlayer) this).getBukkitEntity());
++ }
++ return !team.hasPlayer(this.level().getCraftServer().getOfflinePlayer(this.getScoreboardName()));
++ // CraftBukkit end
+ }
+
+ @Override
+@@ -959,9 +1019,13 @@
+ }
+ }
+
++ // CraftBukkit start
+ @Override
+- @Override
+- protected void actuallyHurt(DamageSource damagesource, float f) {
++ protected boolean damageEntity0(DamageSource damagesource, float f) { // void -> boolean
++ if (true) {
++ return super.damageEntity0(damagesource, f);
++ }
++ // CraftBukkit end
+ if (!this.isInvulnerableTo(damagesource)) {
+ f = this.getDamageAfterArmorAbsorb(damagesource, f);
+ f = this.getDamageAfterMagicAbsorb(damagesource, f);
+@@ -976,7 +1040,7 @@
+ }
+
+ if (f != 0.0F) {
+- this.causeFoodExhaustion(damagesource.getFoodExhaustion());
++ this.causeFoodExhaustion(damagesource.getFoodExhaustion(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
+ this.getCombatTracker().recordDamage(damagesource, f);
+ this.setHealth(this.getHealth() - f);
+ if (f < 3.4028235E37F) {
+@@ -986,6 +1050,7 @@
+ this.gameEvent(GameEvent.ENTITY_DAMAGE);
+ }
+ }
++ return false; // CraftBukkit
+ }
+
+ @Override
+@@ -1156,7 +1215,7 @@
+
+ f *= 0.2F + f2 * f2 * 0.8F;
+ f1 *= f2;
+- this.resetAttackStrengthTicker();
++ // this.resetAttackCooldown(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt
+ if (f > 0.0F || f1 > 0.0F) {
+ boolean flag = f2 > 0.9F;
+ boolean flag1 = false;
+@@ -1192,11 +1251,18 @@
+ boolean flag4 = false;
+ int j = EnchantmentHelper.getFireAspect(this);
+
+- if (entity instanceof LivingEntity) {
+- f3 = ((LivingEntity) entity).getHealth();
+- if (j > 0 && !entity.isOnFire()) {
+- flag4 = true;
+- entity.setSecondsOnFire(1);
++ if (target instanceof LivingEntity) {
++ f3 = ((LivingEntity) target).getHealth();
++ if (j > 0 && !target.isOnFire()) {
++ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
++ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), target.getBukkitEntity(), 1);
++ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
++
++ if (!combustEvent.isCancelled()) {
++ flag4 = true;
++ target.setSecondsOnFire(combustEvent.getDuration(), false);
++ }
++ // CraftBukkit end
+ }
+ }
+
+@@ -1223,9 +1289,12 @@
+ while (iterator.hasNext()) {
+ LivingEntity livingentity = (LivingEntity) iterator.next();
+
+- if (livingentity != this && livingentity != entity && !this.isAlliedTo((Entity) livingentity) && (!(livingentity instanceof ArmorStand) || !((ArmorStand) livingentity).isMarker()) && this.distanceToSqr((Entity) livingentity) < 9.0D) {
+- livingentity.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+- livingentity.hurt(this.damageSources().playerAttack(this), f4);
++ if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) {
++ // CraftBukkit start - Only apply knockback if the damage hits
++ if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) {
++ entityliving.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
++ }
++ // CraftBukkit end
+ }
+ }
+
+@@ -1233,10 +1302,27 @@
+ this.sweepAttack();
+ }
+
+- if (entity instanceof ServerPlayer && entity.hurtMarked) {
+- ((ServerPlayer) entity).connection.send(new ClientboundSetEntityMotionPacket(entity));
+- entity.hurtMarked = false;
+- entity.setDeltaMovement(vec3);
++ if (target instanceof ServerPlayer && target.hurtMarked) {
++ // CraftBukkit start - Add Velocity Event
++ boolean cancelled = false;
++ org.bukkit.entity.Player player = (org.bukkit.entity.Player) target.getBukkitEntity();
++ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
++
++ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
++ this.level().getCraftServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ cancelled = true;
++ } else if (!velocity.equals(event.getVelocity())) {
++ player.setVelocity(event.getVelocity());
++ }
++
++ if (!cancelled) {
++ ((ServerPlayer) target).connection.send(new ClientboundSetEntityMotionPacket(target));
++ target.hurtMarked = false;
++ target.setDeltaMovement(vec3d);
++ }
++ // CraftBukkit end
+ }
+
+ if (flag2) {
+@@ -1281,7 +1367,14 @@
+
+ this.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
+ if (j > 0) {
+- entity.setSecondsOnFire(j * 4);
++ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
++ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), target.getBukkitEntity(), j * 4);
++ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
++
++ if (!combustEvent.isCancelled()) {
++ target.setSecondsOnFire(combustEvent.getDuration(), false);
++ }
++ // CraftBukkit end
+ }
+
+ if (this.level() instanceof ServerLevel && f5 > 2.0F) {
+@@ -1291,12 +1384,17 @@
+ }
+ }
+
+- this.causeFoodExhaustion(0.1F);
++ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent
+ } else {
+ this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
+ if (flag4) {
+ entity.clearFire();
+ }
++ // CraftBukkit start - resync on cancelled event
++ if (this instanceof ServerPlayer) {
++ ((ServerPlayer) this).getBukkitEntity().updateInventory();
++ }
++ // CraftBukkit end
+ }
+ }
+
+@@ -1374,8 +1470,14 @@
+ return this.containerMenu != this.inventoryMenu;
+ }
+
+- public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos blockpos) {
+- this.startSleeping(blockpos);
++ public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos bedPos) {
++ // CraftBukkit start
++ return this.startSleepInBed(bedPos, false);
++ }
++
++ public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos blockposition, boolean force) {
++ // CraftBukkit end
++ this.startSleeping(blockposition);
+ this.sleepCounter = 0;
+ return Either.right(Unit.INSTANCE);
+ }
+@@ -1464,9 +1564,9 @@
+ super.jumpFromGround();
+ this.awardStat(Stats.JUMP);
+ if (this.isSprinting()) {
+- this.causeFoodExhaustion(0.2F);
++ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent
+ } else {
+- this.causeFoodExhaustion(0.05F);
++ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent
+ }
+
+ }
+@@ -1494,7 +1593,11 @@
+
+ this.setDeltaMovement(vec32.x, d0 * 0.6D, vec32.z);
+ this.resetFallDistance();
+- this.setSharedFlag(7, false);
++ // CraftBukkit start
++ if (getSharedFlag(7) && !org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
++ this.setSharedFlag(7, false);
++ }
++ // CraftBukkit end
+ } else {
+ super.travel(vec3);
+ }
+@@ -1550,12 +1650,24 @@
+ }
+
+ public void startFallFlying() {
+- this.setSharedFlag(7, true);
++ // CraftBukkit start
++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) {
++ this.setSharedFlag(7, true);
++ } else {
++ // SPIGOT-5542: must toggle like below
++ this.setSharedFlag(7, true);
++ this.setSharedFlag(7, false);
++ }
++ // CraftBukkit end
+ }
+
+ public void stopFallFlying() {
++ // CraftBukkit start
++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
+ this.setSharedFlag(7, true);
+ this.setSharedFlag(7, false);
++ }
++ // CraftBukkit end
+ }
+
+ @Override
+@@ -1674,10 +1781,21 @@
+ return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
+ }
+
+- public void causeFoodExhaustion(float f) {
++ // CraftBukkit start
++ public void causeFoodExhaustion(float exhaustion) {
++ this.causeFoodExhaustion(exhaustion, EntityExhaustionEvent.ExhaustionReason.UNKNOWN);
++ }
++
++ public void causeFoodExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) {
++ // CraftBukkit end
+ if (!this.abilities.invulnerable) {
+ if (!this.level().isClientSide) {
+- this.foodData.addExhaustion(f);
++ // CraftBukkit start
++ EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent(this, reason, f);
++ if (!event.isCancelled()) {
++ this.foodData.addExhaustion(event.getExhaustion());
++ }
++ // CraftBukkit end
+ }
+
+ }
+@@ -1763,21 +1880,21 @@
+ }
+
+ @Override
+- @Override
+- protected boolean doesEmitEquipEvent(EquipmentSlot equipmentslot) {
+- return equipmentslot.getType() == EquipmentSlot.Type.ARMOR;
++ public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
++ // CraftBukkit start
++ setItemSlot(slot, stack, false);
+ }
+
+ @Override
+- @Override
+- public void setItemSlot(EquipmentSlot equipmentslot, ItemStack itemstack) {
++ public void setItemSlot(EquipmentSlot enumitemslot, ItemStack itemstack, boolean silent) {
++ // CraftBukkit end
+ this.verifyEquippedItem(itemstack);
+- if (equipmentslot == EquipmentSlot.MAINHAND) {
+- this.onEquipItem(equipmentslot, (ItemStack) this.inventory.items.set(this.inventory.selected, itemstack), itemstack);
+- } else if (equipmentslot == EquipmentSlot.OFFHAND) {
+- this.onEquipItem(equipmentslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack);
+- } else if (equipmentslot.getType() == EquipmentSlot.Type.ARMOR) {
+- this.onEquipItem(equipmentslot, (ItemStack) this.inventory.armor.set(equipmentslot.getIndex(), itemstack), itemstack);
++ if (enumitemslot == EquipmentSlot.MAINHAND) {
++ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.items.set(this.inventory.selected, itemstack), itemstack, silent); // CraftBukkit
++ } else if (enumitemslot == EquipmentSlot.OFFHAND) {
++ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack, silent); // CraftBukkit
++ } else if (enumitemslot.getType() == EquipmentSlot.Function.ARMOR) {
++ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack, silent); // CraftBukkit
+ }
+
+ }
+@@ -1818,26 +1933,31 @@
+
+ protected void removeEntitiesOnShoulder() {
+ if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
+- this.respawnEntityOnShoulder(this.getShoulderEntityLeft());
+- this.setShoulderEntityLeft(new CompoundTag());
+- this.respawnEntityOnShoulder(this.getShoulderEntityRight());
+- this.setShoulderEntityRight(new CompoundTag());
++ // CraftBukkit start
++ if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
++ this.setShoulderEntityLeft(new CompoundTag());
++ }
++ if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
++ this.setShoulderEntityRight(new CompoundTag());
++ }
++ // CraftBukkit end
+ }
+
+ }
+
+- private void respawnEntityOnShoulder(CompoundTag compoundtag) {
+- if (!this.level().isClientSide && !compoundtag.isEmpty()) {
+- EntityType.create(compoundtag, this.level()).ifPresent((entity) -> {
++ private boolean respawnEntityOnShoulder(CompoundTag nbttagcompound) { // CraftBukkit void->boolean
++ if (!this.level().isClientSide && !nbttagcompound.isEmpty()) {
++ return EntityType.create(nbttagcompound, this.level()).map((entity) -> { // CraftBukkit
+ if (entity instanceof TamableAnimal) {
+ ((TamableAnimal) entity).setOwnerUUID(this.uuid);
+ }
+
+ entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ());
+- ((ServerLevel) this.level()).addWithUUID(entity);
+- });
++ return ((ServerLevel) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit
++ }).orElse(true); // CraftBukkit
+ }
+
++ return true; // CraftBukkit
+ }
+
+ @Override