PaperMC/paper-server/nms-patches/net/minecraft/world/entity/player/EntityHuman.patch
2023-03-25 11:26:10 +11:00

553 lines
27 KiB
Diff

--- a/net/minecraft/world/entity/player/EntityHuman.java
+++ b/net/minecraft/world/entity/player/EntityHuman.java
@@ -117,6 +117,20 @@
import net.minecraft.world.scores.ScoreboardTeamBase;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.nbt.NBTBase;
+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.entity.Player;
+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 EntityHuman extends EntityLiving {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -130,7 +144,8 @@
public static final float SWIMMING_BB_HEIGHT = 0.6F;
public static final float DEFAULT_EYE_HEIGHT = 1.62F;
public static final EntitySize STANDING_DIMENSIONS = EntitySize.scalable(0.6F, 1.8F);
- private static final Map<EntityPose, EntitySize> POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F)).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F)).build();
+ // CraftBukkit - decompile error
+ private static final Map<EntityPose, EntitySize> POSES = ImmutableMap.<EntityPose, EntitySize>builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F)).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F)).build();
private static final int FLY_ACHIEVEMENT_SPEED = 25;
private static final DataWatcherObject<Float> DATA_PLAYER_ABSORPTION_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.FLOAT);
private static final DataWatcherObject<Integer> DATA_SCORE_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.INT);
@@ -140,10 +155,10 @@
protected static final DataWatcherObject<NBTTagCompound> DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG);
private long timeEntitySatOnShoulder;
private final PlayerInventory inventory = new PlayerInventory(this);
- protected InventoryEnderChest enderChestInventory = new InventoryEnderChest();
+ protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(this); // CraftBukkit - add "this" to constructor
public final ContainerPlayer inventoryMenu;
public Container containerMenu;
- protected FoodMetaData foodData = new FoodMetaData();
+ protected FoodMetaData foodData = new FoodMetaData(this); // CraftBukkit - add "this" to constructor
protected int jumpTriggerTime;
public float oBob;
public float bob;
@@ -172,6 +187,16 @@
public EntityFishingHook fishing;
protected float hurtDir;
+ // CraftBukkit start
+ public boolean fauxSleeping;
+ public int oldLevel = -1;
+
+ @Override
+ public CraftHumanEntity getBukkitEntity() {
+ return (CraftHumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
+
public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) {
super(EntityTypes.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -311,7 +336,7 @@
ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD);
if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) {
- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
+ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
}
}
@@ -477,8 +502,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
double d0 = this.getX();
double d1 = this.getY();
double d2 = this.getZ();
@@ -505,7 +536,8 @@
if (this.level.getDifficulty() == EnumDifficulty.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) {
@@ -664,6 +696,13 @@
@Nullable
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
+ return drop(itemstack, flag, flag1, true);
+ }
+
+ @Nullable
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
+ // CraftBukkit end
if (itemstack.isEmpty()) {
return null;
} else {
@@ -698,6 +737,33 @@
entityitem.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);
}
+ // CraftBukkit start - fire PlayerDropItemEvent
+ if (!callEvent) { // SPIGOT-2942: Add boolean to call event
+ return entityitem;
+ }
+ Player player = (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;
}
}
@@ -788,7 +854,7 @@
}
if (nbttagcompound.contains("LastDeathLocation", 10)) {
- DataResult dataresult = GlobalPos.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("LastDeathLocation"));
+ DataResult<GlobalPos> dataresult = GlobalPos.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("LastDeathLocation")); // CraftBukkit - decompile error
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -821,7 +887,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
- DataResult dataresult = GlobalPos.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, globalpos);
+ DataResult<NBTBase> dataresult = GlobalPos.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, globalpos); // CraftBukkit - decompile error
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -848,12 +914,12 @@
return false;
} else {
if (!this.level.isClientSide) {
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
}
if (damagesource.scalesWithDifficulty()) {
if (this.level.getDifficulty() == EnumDifficulty.PEACEFUL) {
- f = 0.0F;
+ return false; // CraftBukkit - f = 0.0f -> return false
}
if (this.level.getDifficulty() == EnumDifficulty.EASY) {
@@ -865,7 +931,13 @@
}
}
- return f == 0.0F ? false : super.hurt(damagesource, f);
+ // CraftBukkit start - Don't filter out 0 damage
+ boolean damaged = super.hurt(damagesource, f);
+ if (damaged) {
+ this.removeEntitiesOnShoulder();
+ }
+ return damaged;
+ // CraftBukkit end
}
}
}
@@ -885,10 +957,29 @@
}
public boolean canHarmPlayer(EntityHuman entityhuman) {
- ScoreboardTeamBase scoreboardteambase = this.getTeam();
- ScoreboardTeamBase scoreboardteambase1 = entityhuman.getTeam();
+ // 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 (entityhuman instanceof EntityPlayer) {
+ EntityPlayer thatPlayer = (EntityPlayer) entityhuman;
+ 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 = entityhuman.level.getCraftServer().getOfflinePlayer(entityhuman.getScoreboardName());
+ team = entityhuman.level.getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
+ }
- return scoreboardteambase == null ? true : (!scoreboardteambase.isAlliedTo(scoreboardteambase1) ? true : scoreboardteambase.isAllowFriendlyFire());
+ if (this instanceof EntityPlayer) {
+ return !team.hasPlayer(((EntityPlayer) this).getBukkitEntity());
+ }
+ return !team.hasPlayer(this.level.getCraftServer().getOfflinePlayer(this.getScoreboardName()));
+ // CraftBukkit end
}
@Override
@@ -930,8 +1021,13 @@
}
}
+ // CraftBukkit start
@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);
@@ -946,7 +1042,7 @@
}
if (f != 0.0F) {
- this.causeFoodExhaustion(damagesource.getFoodExhaustion());
+ this.causeFoodExhaustion(damagesource.getFoodExhaustion(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
float f3 = this.getHealth();
this.getCombatTracker().recordDamage(damagesource, f3, f);
@@ -957,6 +1053,7 @@
}
}
+ return false; // CraftBukkit
}
@Override
@@ -1121,7 +1218,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;
@@ -1160,8 +1257,15 @@
if (entity instanceof EntityLiving) {
f3 = ((EntityLiving) entity).getHealth();
if (j > 0 && !entity.isOnFire()) {
- flag4 = true;
- entity.setSecondsOnFire(1);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 1);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ flag4 = true;
+ entity.setSecondsOnFire(combustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
}
}
@@ -1189,8 +1293,11 @@
EntityLiving entityliving = (EntityLiving) iterator.next();
if (entityliving != this && entityliving != entity && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) 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) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
- entityliving.hurt(this.damageSources().playerAttack(this), f4);
+ }
+ // CraftBukkit end
}
}
@@ -1199,9 +1306,26 @@
}
if (entity instanceof EntityPlayer && entity.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ Player player = (Player) entity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity));
entity.hurtMarked = false;
entity.setDeltaMovement(vec3d);
+ }
+ // CraftBukkit end
}
if (flag2) {
@@ -1246,7 +1370,14 @@
this.awardStat(StatisticList.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(), entity.getBukkitEntity(), j * 4);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ entity.setSecondsOnFire(combustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
}
if (this.level instanceof WorldServer && f5 > 2.0F) {
@@ -1256,12 +1387,17 @@
}
}
- this.causeFoodExhaustion(0.1F);
+ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent
} else {
this.level.playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
if (flag4) {
entity.clearFire();
}
+ // CraftBukkit start - resync on cancelled event
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ }
+ // CraftBukkit end
}
}
@@ -1338,6 +1474,12 @@
}
public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
+ // CraftBukkit start
+ return this.startSleepInBed(blockposition, false);
+ }
+
+ public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition, boolean force) {
+ // CraftBukkit end
this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1422,9 +1564,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.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
}
}
@@ -1454,7 +1596,11 @@
this.setDeltaMovement(vec3d2.x, d3 * 0.6D, vec3d2.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(vec3d);
}
@@ -1489,19 +1635,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i);
- this.causeFoodExhaustion(0.01F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SWIM); // CraftBukkit - EntityExhaustionEvent
}
} else if (this.isEyeInFluid(TagsFluid.WATER)) {
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.WALK_UNDER_WATER_ONE_CM, i);
- this.causeFoodExhaustion(0.01F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // CraftBukkit - EntityExhaustionEvent
}
} else if (this.isInWater()) {
i = Math.round((float) Math.sqrt(d0 * d0 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.WALK_ON_WATER_ONE_CM, i);
- this.causeFoodExhaustion(0.01F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // CraftBukkit - EntityExhaustionEvent
}
} else if (this.onClimbable()) {
if (d1 > 0.0D) {
@@ -1512,13 +1658,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i);
- this.causeFoodExhaustion(0.1F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.1F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SPRINT); // CraftBukkit - EntityExhaustionEvent
} else if (this.isCrouching()) {
this.awardStat(StatisticList.CROUCH_ONE_CM, i);
- this.causeFoodExhaustion(0.0F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.0F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.CROUCH); // CraftBukkit - EntityExhaustionEvent
} else {
this.awardStat(StatisticList.WALK_ONE_CM, i);
- this.causeFoodExhaustion(0.0F * (float) i * 0.01F);
+ this.causeFoodExhaustion(0.0F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK); // CraftBukkit - EntityExhaustionEvent
}
}
} else if (this.isFallFlying()) {
@@ -1584,12 +1730,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
@@ -1680,10 +1838,21 @@
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
+ // CraftBukkit start
public void causeFoodExhaustion(float f) {
+ this.causeFoodExhaustion(f, 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
}
}
@@ -1769,13 +1938,20 @@
@Override
public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
+ // CraftBukkit start
+ setItemSlot(enumitemslot, itemstack, false);
+ }
+
+ @Override
+ public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) {
+ // CraftBukkit end
this.verifyEquippedItem(itemstack);
if (enumitemslot == EnumItemSlot.MAINHAND) {
- this.onEquipItem(enumitemslot, (ItemStack) this.inventory.items.set(this.inventory.selected, itemstack), itemstack);
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.items.set(this.inventory.selected, itemstack), itemstack, silent); // CraftBukkit
} else if (enumitemslot == EnumItemSlot.OFFHAND) {
- this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack);
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack, silent); // CraftBukkit
} else if (enumitemslot.getType() == EnumItemSlot.Function.ARMOR) {
- this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack);
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack, silent); // CraftBukkit
}
}
@@ -1814,26 +1990,31 @@
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level.getGameTime()) {
- this.respawnEntityOnShoulder(this.getShoulderEntityLeft());
- this.setShoulderEntityLeft(new NBTTagCompound());
- this.respawnEntityOnShoulder(this.getShoulderEntityRight());
- this.setShoulderEntityRight(new NBTTagCompound());
+ // CraftBukkit start
+ if (this.spawnEntityFromShoulder(this.getShoulderEntityLeft())) {
+ this.setShoulderEntityLeft(new NBTTagCompound());
+ }
+ if (this.spawnEntityFromShoulder(this.getShoulderEntityRight())) {
+ this.setShoulderEntityRight(new NBTTagCompound());
+ }
+ // CraftBukkit end
}
}
- private void respawnEntityOnShoulder(NBTTagCompound nbttagcompound) {
+ private boolean spawnEntityFromShoulder(NBTTagCompound nbttagcompound) { // CraftBukkit void->boolean
if (!this.level.isClientSide && !nbttagcompound.isEmpty()) {
- EntityTypes.create(nbttagcompound, this.level).ifPresent((entity) -> {
+ return EntityTypes.create(nbttagcompound, this.level).map((entity) -> { // CraftBukkit
if (entity instanceof EntityTameableAnimal) {
((EntityTameableAnimal) entity).setOwnerUUID(this.uuid);
}
entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ());
- ((WorldServer) this.level).addWithUUID(entity);
- });
+ return ((WorldServer) this.level).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit
+ }).orElse(true); // CraftBukkit
}
+ return true; // CraftBukkit
}
@Override