diff --git a/nms-patches/Entity.patch b/nms-patches/Entity.patch index 7b35b28776..4abdc4eccf 100644 --- a/nms-patches/Entity.patch +++ b/nms-patches/Entity.patch @@ -264,7 +264,20 @@ } public void c(Vec3D vec3d) { -@@ -1235,7 +1404,7 @@ +@@ -1225,6 +1394,12 @@ + return false; + } + ++ // CraftBukkit start - collidable API ++ public boolean canCollideWith(Entity entity) { ++ return isCollidable(); ++ } ++ // CraftBukkit end ++ + public void a(Entity entity, int i, DamageSource damagesource) { + if (entity instanceof EntityPlayer) { + CriterionTriggers.c.a((EntityPlayer) entity, this, damagesource); +@@ -1235,7 +1410,7 @@ public boolean a_(NBTTagCompound nbttagcompound) { String s = this.getSaveID(); @@ -273,7 +286,7 @@ nbttagcompound.setString("id", s); this.save(nbttagcompound); return true; -@@ -1259,6 +1428,18 @@ +@@ -1259,6 +1434,18 @@ Vec3D vec3d = this.getMot(); nbttagcompound.set("Motion", this.a(vec3d.x, vec3d.y, vec3d.z)); @@ -292,7 +305,7 @@ nbttagcompound.set("Rotation", this.a(this.yaw, this.pitch)); nbttagcompound.setFloat("FallDistance", this.fallDistance); nbttagcompound.setShort("Fire", (short) this.fireTicks); -@@ -1267,6 +1448,12 @@ +@@ -1267,6 +1454,12 @@ nbttagcompound.setBoolean("Invulnerable", this.invulnerable); nbttagcompound.setInt("PortalCooldown", this.portalCooldown); nbttagcompound.a("UUID", this.getUniqueID()); @@ -305,7 +318,7 @@ IChatBaseComponent ichatbasecomponent = this.getCustomName(); if (ichatbasecomponent != null) { -@@ -1324,6 +1511,11 @@ +@@ -1324,6 +1517,11 @@ } } @@ -317,7 +330,7 @@ return nbttagcompound; } catch (Throwable throwable) { CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT"); -@@ -1401,6 +1593,43 @@ +@@ -1401,6 +1599,43 @@ } else { throw new IllegalStateException("Entity has invalid position"); } @@ -361,7 +374,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded"); -@@ -1476,9 +1705,22 @@ +@@ -1476,9 +1711,22 @@ } else if (this.world.isClientSide) { return null; } else { @@ -384,13 +397,7 @@ this.world.addEntity(entityitem); return entityitem; } -@@ -1554,12 +1796,13 @@ - return false; - } else { - if (this.isPassenger()) { -+ if (this.vehicle == entity) return true; // CraftBukkit - SPIGOT-5562: already riding - this.stopRiding(); - } +@@ -1559,7 +1807,7 @@ this.setPose(EntityPose.STANDING); this.vehicle = entity; @@ -399,7 +406,7 @@ return true; } } -@@ -1584,7 +1827,7 @@ +@@ -1584,7 +1832,7 @@ Entity entity = this.vehicle; this.vehicle = null; @@ -408,7 +415,7 @@ } } -@@ -1593,10 +1836,31 @@ +@@ -1593,10 +1841,31 @@ this.bb(); } @@ -441,7 +448,7 @@ if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) { this.passengers.add(0, entity); } else { -@@ -1604,15 +1868,33 @@ +@@ -1604,15 +1873,33 @@ } } @@ -476,7 +483,7 @@ } protected boolean q(Entity entity) { -@@ -1665,7 +1947,13 @@ +@@ -1665,7 +1952,13 @@ this.world.getMethodProfiler().enter("portal"); this.portalTicks = i; this.portalCooldown = this.getDefaultPortalCooldown(); @@ -491,7 +498,7 @@ this.world.getMethodProfiler().exit(); } -@@ -1765,6 +2053,13 @@ +@@ -1765,6 +2058,13 @@ } public void setSwimming(boolean flag) { @@ -505,7 +512,7 @@ this.setFlag(4, flag); } -@@ -1825,16 +2120,56 @@ +@@ -1825,16 +2125,56 @@ } public void setAirTicks(int i) { @@ -565,7 +572,7 @@ } public void k(boolean flag) { -@@ -1986,18 +2321,45 @@ +@@ -1986,18 +2326,45 @@ @Nullable public Entity a(WorldServer worldserver) { @@ -615,7 +622,7 @@ } else { double d0 = this.locX(); double d1 = this.locZ(); -@@ -2023,7 +2385,16 @@ +@@ -2023,7 +2390,16 @@ Vec3D vec3d1 = this.getPortalOffset(); blockposition = new BlockPosition(d0, this.locY(), d1); @@ -633,7 +640,7 @@ if (shapedetector_shape == null) { return null; -@@ -2033,6 +2404,11 @@ +@@ -2033,6 +2409,11 @@ vec3d = shapedetector_shape.velocity; f = (float) shapedetector_shape.yaw; } @@ -645,7 +652,7 @@ this.world.getMethodProfiler().exitEnter("reloading"); Entity entity = this.getEntityType().a((World) worldserver); -@@ -2043,8 +2419,16 @@ +@@ -2043,8 +2424,16 @@ entity.setMot(vec3d); worldserver.addEntityTeleport(entity); if (worldserver.getDimensionKey() == World.THE_END) { @@ -663,7 +670,7 @@ } this.bJ(); -@@ -2253,7 +2637,26 @@ +@@ -2253,7 +2642,26 @@ } public void a(AxisAlignedBB axisalignedbb) { diff --git a/nms-patches/EntityLiving.patch b/nms-patches/EntityLiving.patch index fe50480d4b..96e7788911 100644 --- a/nms-patches/EntityLiving.patch +++ b/nms-patches/EntityLiving.patch @@ -1,11 +1,13 @@ --- a/net/minecraft/server/EntityLiving.java +++ b/net/minecraft/server/EntityLiving.java -@@ -21,6 +21,24 @@ +@@ -21,6 +21,26 @@ import javax.annotation.Nullable; import org.apache.logging.log4j.Logger; +// CraftBukkit start +import java.util.ArrayList; ++import java.util.HashSet; ++import java.util.Set; +import com.google.common.base.Function; +import org.bukkit.Location; +import org.bukkit.craftbukkit.attribute.CraftAttributeMap; @@ -25,7 +27,7 @@ public abstract class EntityLiving extends Entity { private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D"); -@@ -106,6 +124,20 @@ +@@ -106,6 +126,21 @@ private float bI; private float bJ; protected BehaviorController bn; @@ -36,6 +38,7 @@ + ArrayList drops = new ArrayList(); + public final org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes; + public boolean collides = true; ++ public Set collidableExemptions = new HashSet<>(); + public boolean canPickUpLoot; + + @Override @@ -46,7 +49,7 @@ protected EntityLiving(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -117,7 +149,9 @@ +@@ -117,7 +152,9 @@ this.activeItem = ItemStack.b; this.bF = Optional.empty(); this.attributeMap = new AttributeMapBase(AttributeDefaults.a(entitytypes)); @@ -57,7 +60,7 @@ this.i = true; this.aG = (float) ((Math.random() + 1.0D) * 0.009999999776482582D); this.ac(); -@@ -184,7 +218,13 @@ +@@ -184,7 +221,13 @@ double d1 = Math.min((double) (0.2F + f / 15.0F), 2.5D); int i = (int) (150.0D * d1); @@ -72,7 +75,7 @@ } } -@@ -406,7 +446,7 @@ +@@ -406,7 +449,7 @@ protected void cT() { ++this.deathTicks; @@ -81,7 +84,7 @@ this.die(); for (int i = 0; i < 20; ++i) { -@@ -567,6 +607,17 @@ +@@ -567,6 +610,17 @@ } } @@ -99,7 +102,7 @@ if (nbttagcompound.hasKeyOfType("Health", 99)) { this.setHealth(nbttagcompound.getFloat("Health")); } -@@ -604,9 +655,32 @@ +@@ -604,9 +658,32 @@ } @@ -132,7 +135,7 @@ try { while (iterator.hasNext()) { MobEffectList mobeffectlist = (MobEffectList) iterator.next(); -@@ -616,6 +690,12 @@ +@@ -616,6 +693,12 @@ this.a(mobeffect, true); })) { if (!this.world.isClientSide) { @@ -145,7 +148,7 @@ iterator.remove(); this.b(mobeffect); } -@@ -626,6 +706,17 @@ +@@ -626,6 +709,17 @@ } catch (ConcurrentModificationException concurrentmodificationexception) { ; } @@ -163,7 +166,7 @@ if (this.updateEffects) { if (!this.world.isClientSide) { -@@ -735,7 +826,13 @@ +@@ -735,7 +829,13 @@ this.datawatcher.set(EntityLiving.f, 0); } @@ -177,7 +180,7 @@ if (this.world.isClientSide) { return false; } else { -@@ -744,7 +841,14 @@ +@@ -744,7 +844,14 @@ boolean flag; for (flag = false; iterator.hasNext(); flag = true) { @@ -193,7 +196,7 @@ iterator.remove(); } -@@ -769,18 +873,44 @@ +@@ -769,18 +876,44 @@ return (MobEffect) this.effects.get(mobeffectlist); } @@ -239,7 +242,7 @@ return true; } else { return false; -@@ -804,13 +934,39 @@ +@@ -804,13 +937,39 @@ return this.getMonsterType() == EnumMonsterType.UNDEAD; } @@ -280,7 +283,7 @@ if (mobeffect != null) { this.b(mobeffect); -@@ -847,20 +1003,55 @@ +@@ -847,20 +1006,55 @@ } @@ -337,7 +340,7 @@ this.datawatcher.set(EntityLiving.HEALTH, MathHelper.a(f, 0.0F, this.getMaxHealth())); } -@@ -874,7 +1065,7 @@ +@@ -874,7 +1068,7 @@ return false; } else if (this.world.isClientSide) { return false; @@ -346,7 +349,7 @@ return false; } else if (damagesource.isFire() && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; -@@ -886,17 +1077,19 @@ +@@ -886,17 +1080,19 @@ this.ticksFarFromPlayer = 0; float f1 = f; @@ -369,7 +372,7 @@ this.damageShield(f); f2 = f; f = 0.0F; -@@ -916,20 +1109,39 @@ +@@ -916,20 +1112,39 @@ if ((float) this.noDamageTicks > 10.0F) { if (f <= this.lastDamage) { @@ -411,7 +414,7 @@ this.aw = 0.0F; Entity entity1 = damagesource.getEntity(); -@@ -1050,19 +1262,29 @@ +@@ -1050,19 +1265,29 @@ EnumHand[] aenumhand = EnumHand.values(); int i = aenumhand.length; @@ -445,7 +448,7 @@ EntityPlayer entityplayer = (EntityPlayer) this; entityplayer.b(StatisticList.ITEM_USED.b(Items.TOTEM_OF_UNDYING)); -@@ -1070,13 +1292,15 @@ +@@ -1070,13 +1295,15 @@ } this.setHealth(1.0F); @@ -465,7 +468,7 @@ } } -@@ -1193,28 +1417,48 @@ +@@ -1193,28 +1420,48 @@ boolean flag = this.lastDamageByPlayerTime > 0; @@ -516,7 +519,7 @@ } -@@ -1335,9 +1579,14 @@ +@@ -1335,9 +1582,14 @@ int i = this.e(f, f1); if (i > 0) { @@ -532,7 +535,7 @@ return true; } else { return flag; -@@ -1377,7 +1626,7 @@ +@@ -1377,7 +1629,7 @@ protected float applyArmorModifier(DamageSource damagesource, float f) { if (!damagesource.ignoresArmor()) { @@ -541,7 +544,7 @@ f = CombatMath.a(f, (float) this.getArmorStrength(), (float) this.b(GenericAttributes.ARMOR_TOUGHNESS)); } -@@ -1390,7 +1639,8 @@ +@@ -1390,7 +1642,8 @@ } else { int i; @@ -551,7 +554,7 @@ i = (this.getEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = f * (float) j; -@@ -1421,28 +1671,173 @@ +@@ -1421,28 +1674,173 @@ } } @@ -635,9 +638,12 @@ + if (event.isCancelled()) { + return false; + } -+ + +- f = Math.max(f - this.getAbsorptionHearts(), 0.0F); +- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f)); +- float f2 = f1 - f; + f = (float) event.getFinalDamage(); -+ + + // Resistance + if (event.getDamage(DamageModifier.RESISTANCE) < 0) { + float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE); @@ -662,10 +668,7 @@ + float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT)); + 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 @@ -676,7 +679,7 @@ + this.shieldBlock((EntityLiving) entity); + } + } - ++ + absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION); + this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F)); + float f2 = absorptionModifier; @@ -735,7 +738,7 @@ } public CombatTracker getCombatTracker() { -@@ -1814,6 +2209,7 @@ +@@ -1814,6 +2212,7 @@ } if (this.onGround && !this.world.isClientSide) { @@ -743,7 +746,7 @@ this.setFlag(7, false); } } else { -@@ -2319,6 +2715,7 @@ +@@ -2319,6 +2718,7 @@ } if (!this.world.isClientSide) { @@ -751,7 +754,7 @@ this.setFlag(7, flag); } -@@ -2439,6 +2836,7 @@ +@@ -2439,6 +2839,7 @@ } public boolean hasLineOfSight(Entity entity) { @@ -759,7 +762,7 @@ Vec3D vec3d = new Vec3D(this.locX(), this.getHeadY(), this.locZ()); Vec3D vec3d1 = new Vec3D(entity.locX(), entity.getHeadY(), entity.locZ()); -@@ -2456,12 +2854,12 @@ +@@ -2456,13 +2857,20 @@ @Override public boolean isInteractable() { @@ -771,10 +774,18 @@ public boolean isCollidable() { - return this.isAlive() && !this.isClimbing(); + return this.isAlive() && !this.isClimbing() && this.collides; // CraftBukkit ++ } ++ ++ // CraftBukkit start - collidable API ++ @Override ++ public boolean canCollideWith(Entity entity) { ++ return isCollidable() && this.collides != this.collidableExemptions.contains(entity.getUniqueID()); } ++ // CraftBukkit end @Override -@@ -2645,7 +3043,27 @@ + protected void velocityChanged() { +@@ -2645,7 +3053,27 @@ } else { if (!this.activeItem.isEmpty() && this.isHandRaised()) { this.b(this.activeItem, 16); @@ -803,7 +814,7 @@ this.clearActiveItem(); } -@@ -2732,10 +3150,18 @@ +@@ -2732,10 +3160,18 @@ } if (flag2) { @@ -825,7 +836,7 @@ } } -@@ -2832,7 +3258,7 @@ +@@ -2832,7 +3268,7 @@ } public void entityWakeup() { @@ -834,7 +845,7 @@ World world = this.world; this.world.getClass(); -@@ -2899,7 +3325,7 @@ +@@ -2899,7 +3335,7 @@ Pair pair = (Pair) iterator.next(); if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) { diff --git a/nms-patches/EntityParrot.patch b/nms-patches/EntityParrot.patch index 38c254a669..2ad80ef3f9 100644 --- a/nms-patches/EntityParrot.patch +++ b/nms-patches/EntityParrot.patch @@ -27,6 +27,15 @@ if (entityhuman.isCreative() || !this.isInvulnerable()) { this.damageEntity(DamageSource.playerAttack(entityhuman), Float.MAX_VALUE); } +@@ -315,7 +315,7 @@ + + @Override + public boolean isCollidable() { +- return true; ++ return super.isCollidable(); // CraftBukkit - collidable API + } + + @Override @@ -330,7 +330,7 @@ if (this.isInvulnerable(damagesource)) { return false; diff --git a/nms-patches/IEntitySelector.patch b/nms-patches/IEntitySelector.patch new file mode 100644 index 0000000000..971d828b80 --- /dev/null +++ b/nms-patches/IEntitySelector.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/server/IEntitySelector.java ++++ b/net/minecraft/server/IEntitySelector.java +@@ -37,7 +37,7 @@ + ScoreboardTeamBase.EnumTeamPush scoreboardteambase_enumteampush = scoreboardteambase == null ? ScoreboardTeamBase.EnumTeamPush.ALWAYS : scoreboardteambase.getCollisionRule(); + + return (Predicate) (scoreboardteambase_enumteampush == ScoreboardTeamBase.EnumTeamPush.NEVER ? Predicates.alwaysFalse() : IEntitySelector.g.and((entity1) -> { +- if (!entity1.isCollidable()) { ++ if (!entity1.canCollideWith(entity) || !entity.canCollideWith(entity1)) { // CraftBukkit - collidable API + return false; + } else if (entity.world.isClientSide && (!(entity1 instanceof EntityHuman) || !((EntityHuman) entity1).ey())) { + return false; diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index ac29dd3394..28151d1537 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.UUID; import net.minecraft.server.DamageSource; import net.minecraft.server.EntityArmorStand; import net.minecraft.server.EntityArrow; @@ -611,6 +612,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return getHandle().collides; } + @Override + public Set getCollidableExemptions() { + return getHandle().collidableExemptions; + } + @Override public T getMemory(MemoryKey memoryKey) { return (T) getHandle().getBehaviorController().getMemory(CraftMemoryKey.fromMemoryKey(memoryKey)).map(CraftMemoryMapper::fromNms).orElse(null);