From 59490dfe12f5b4bcc7db1f51a7cbf796bd3d4ade Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 23 Dec 2020 07:53:45 +1100 Subject: [PATCH] SPIGOT-6289: Fix setting entity equipment By: md_5 --- paper-server/nms-patches/Entity.patch | 31 ++++++---------- paper-server/nms-patches/EntityLiving.patch | 39 ++++++++++++++------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/paper-server/nms-patches/Entity.patch b/paper-server/nms-patches/Entity.patch index a590e9b9a3..c399fc83a2 100644 --- a/paper-server/nms-patches/Entity.patch +++ b/paper-server/nms-patches/Entity.patch @@ -520,16 +520,7 @@ this.world.getMethodProfiler().exit(); } -@@ -1690,6 +2000,8 @@ - - public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {} - -+ public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) {} // CraftBukkit -+ - public boolean isBurning() { - boolean flag = this.world != null && this.world.isClientSide; - -@@ -1753,6 +2065,13 @@ +@@ -1753,6 +2063,13 @@ } public void setSwimming(boolean flag) { @@ -543,7 +534,7 @@ this.setFlag(4, flag); } -@@ -1785,8 +2104,12 @@ +@@ -1785,8 +2102,12 @@ return this.getScoreboardTeam() != null ? this.getScoreboardTeam().isAlly(scoreboardteambase) : false; } @@ -557,7 +548,7 @@ } public boolean getFlag(int i) { -@@ -1813,16 +2136,56 @@ +@@ -1813,16 +2134,56 @@ } public void setAirTicks(int i) { @@ -617,7 +608,7 @@ } public void k(boolean flag) { -@@ -1972,15 +2335,32 @@ +@@ -1972,15 +2333,32 @@ @Nullable public Entity b(WorldServer worldserver) { @@ -652,7 +643,7 @@ this.world.getMethodProfiler().exitEnter("reloading"); Entity entity = this.getEntityType().a((World) worldserver); -@@ -1989,9 +2369,17 @@ +@@ -1989,9 +2367,17 @@ entity.setPositionRotation(shapedetectorshape.position.x, shapedetectorshape.position.y, shapedetectorshape.position.z, shapedetectorshape.yaw, entity.pitch); entity.setMot(shapedetectorshape.velocity); worldserver.addEntityTeleport(entity); @@ -672,7 +663,7 @@ } this.bN(); -@@ -2012,13 +2400,18 @@ +@@ -2012,13 +2398,18 @@ @Nullable protected ShapeDetectorShape a(WorldServer worldserver) { @@ -695,7 +686,7 @@ return null; } else { WorldBorder worldborder = worldserver.getWorldBorder(); -@@ -2028,8 +2421,16 @@ +@@ -2028,8 +2419,16 @@ double d3 = Math.min(2.9999872E7D, worldborder.h() - 16.0D); double d4 = DimensionManager.a(this.world.getDimensionManager(), worldserver.getDimensionManager()); BlockPosition blockposition = new BlockPosition(MathHelper.a(this.locX() * d4, d0, d2), this.locY(), MathHelper.a(this.locZ() * d4, d1, d3)); @@ -713,7 +704,7 @@ IBlockData iblockdata = this.world.getType(this.ac); EnumDirection.EnumAxis enumdirection_enumaxis; Vec3D vec3d; -@@ -2046,8 +2447,8 @@ +@@ -2046,8 +2445,8 @@ vec3d = new Vec3D(0.5D, 0.0D, 0.0D); } @@ -724,7 +715,7 @@ } } else { BlockPosition blockposition1; -@@ -2057,8 +2458,15 @@ +@@ -2057,8 +2456,15 @@ } else { blockposition1 = worldserver.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSpawn()); } @@ -741,7 +732,7 @@ } } -@@ -2066,8 +2474,23 @@ +@@ -2066,8 +2472,23 @@ return BlockPortalShape.a(blockutil_rectangle, enumdirection_enumaxis, this.getPositionVector(), this.a(this.getPose())); } @@ -767,7 +758,7 @@ } public boolean canPortal() { -@@ -2253,7 +2676,26 @@ +@@ -2253,7 +2674,26 @@ } public void a(AxisAlignedBB axisalignedbb) { diff --git a/paper-server/nms-patches/EntityLiving.patch b/paper-server/nms-patches/EntityLiving.patch index 2845118d73..84a7dd5278 100644 --- a/paper-server/nms-patches/EntityLiving.patch +++ b/paper-server/nms-patches/EntityLiving.patch @@ -589,10 +589,7 @@ + public Double apply(Double f) { + if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !EntityLiving.this.getEquipment(EnumItemSlot.HEAD).isEmpty()) { + return -(f - (f * 0.75F)); - -- f = Math.max(f - this.getAbsorptionHearts(), 0.0F); -- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f)); -- float f2 = f1 - f; ++ + } + return -0.0; + } @@ -685,12 +682,15 @@ + this.damageArmor(damagesource, armorDamage); + } +- f = Math.max(f - this.getAbsorptionHearts(), 0.0F); +- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f)); +- float f2 = f1 - f; + // Apply blocking code // PAIL: steal from above + if (event.getDamage(DamageModifier.BLOCKING) < 0) { + this.world.broadcastEntityEffect(this, (byte) 29); // SPIGOT-4635 - shield damage sound + this.damageShield((float) -event.getDamage(DamageModifier.BLOCKING)); + Entity entity = damagesource.j(); -+ + + if (entity instanceof EntityLiving) { + this.shieldBlock((EntityLiving) entity); + } @@ -775,7 +775,20 @@ public final int dz() { return (Integer) this.datawatcher.get(EntityLiving.bi); } -@@ -1816,6 +2229,7 @@ +@@ -1594,6 +2007,12 @@ + + public abstract ItemStack getEquipment(EnumItemSlot enumitemslot); + ++ // CraftBukkit start ++ public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) { ++ this.setSlot(enumitemslot, itemstack); ++ } ++ // CraftBukkit end ++ + @Override + public abstract void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack); + +@@ -1816,6 +2235,7 @@ } if (this.onGround && !this.world.isClientSide) { @@ -783,7 +796,7 @@ this.setFlag(7, false); } } else { -@@ -2321,6 +2735,7 @@ +@@ -2321,6 +2741,7 @@ } if (!this.world.isClientSide) { @@ -791,7 +804,7 @@ this.setFlag(7, flag); } -@@ -2441,6 +2856,7 @@ +@@ -2441,6 +2862,7 @@ } public boolean hasLineOfSight(Entity entity) { @@ -799,7 +812,7 @@ Vec3D vec3d = new Vec3D(this.locX(), this.getHeadY(), this.locZ()); Vec3D vec3d1 = new Vec3D(entity.locX(), entity.getHeadY(), entity.locZ()); -@@ -2458,14 +2874,21 @@ +@@ -2458,14 +2880,21 @@ @Override public boolean isInteractable() { @@ -823,7 +836,7 @@ @Override protected void velocityChanged() { this.velocityChanged = this.random.nextDouble() >= this.b(GenericAttributes.KNOCKBACK_RESISTANCE); -@@ -2658,7 +3081,25 @@ +@@ -2658,7 +3087,25 @@ } else { if (!this.activeItem.isEmpty() && this.isHandRaised()) { this.b(this.activeItem, 16); @@ -850,7 +863,7 @@ if (itemstack != this.activeItem) { this.a(enumhand, itemstack); -@@ -2750,10 +3191,18 @@ +@@ -2750,10 +3197,18 @@ } if (flag2) { @@ -872,7 +885,7 @@ } } -@@ -2850,7 +3299,7 @@ +@@ -2850,7 +3305,7 @@ } public void entityWakeup() { @@ -881,7 +894,7 @@ World world = this.world; this.world.getClass(); -@@ -2921,7 +3370,7 @@ +@@ -2921,7 +3376,7 @@ Pair pair = (Pair) iterator.next(); if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) {