#743: LivingEntity - add methods for getting/setting invisibility

This commit is contained in:
Shane Bee 2020-09-19 17:44:48 +10:00 committed by md_5
parent da9bb3ea92
commit f8d4da08e1
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 69 additions and 35 deletions

View File

@ -59,7 +59,7 @@
protected static final Logger LOGGER = LogManager.getLogger(); protected static final Logger LOGGER = LogManager.getLogger();
private static final AtomicInteger entityCount = new AtomicInteger(); private static final AtomicInteger entityCount = new AtomicInteger();
private static final List<ItemStack> c = Collections.emptyList(); private static final List<ItemStack> c = Collections.emptyList();
@@ -106,6 +156,20 @@ @@ -106,6 +156,21 @@
private long aB; private long aB;
private EntitySize size; private EntitySize size;
private float headHeight; private float headHeight;
@ -68,6 +68,7 @@
+ public boolean valid; + public boolean valid;
+ public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only + public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
+ public boolean forceExplosionKnockback; // SPIGOT-949 + public boolean forceExplosionKnockback; // SPIGOT-949
+ public boolean persistentInvisibility = false;
+ +
+ public float getBukkitYaw() { + public float getBukkitYaw() {
+ return this.yaw; + return this.yaw;
@ -80,7 +81,7 @@
public Entity(EntityTypes<?> entitytypes, World world) { public Entity(EntityTypes<?> entitytypes, World world) {
this.id = Entity.entityCount.incrementAndGet(); this.id = Entity.entityCount.incrementAndGet();
@@ -212,6 +276,12 @@ @@ -212,6 +277,12 @@
} }
public void setPose(EntityPose entitypose) { public void setPose(EntityPose entitypose) {
@ -93,7 +94,7 @@
this.datawatcher.set(Entity.POSE, entitypose); this.datawatcher.set(Entity.POSE, entitypose);
} }
@@ -228,6 +298,33 @@ @@ -228,6 +299,33 @@
} }
protected void setYawPitch(float f, float f1) { protected void setYawPitch(float f, float f1) {
@ -127,7 +128,7 @@
this.yaw = f % 360.0F; this.yaw = f % 360.0F;
this.pitch = f1 % 360.0F; this.pitch = f1 % 360.0F;
} }
@@ -235,6 +332,7 @@ @@ -235,6 +333,7 @@
public void setPosition(double d0, double d1, double d2) { public void setPosition(double d0, double d1, double d2) {
this.setPositionRaw(d0, d1, d2); this.setPositionRaw(d0, d1, d2);
this.a(this.size.a(d0, d1, d2)); this.a(this.size.a(d0, d1, d2));
@ -135,7 +136,7 @@
} }
protected void ae() { protected void ae() {
@@ -249,6 +347,15 @@ @@ -249,6 +348,15 @@
this.entityBaseTick(); this.entityBaseTick();
} }
@ -151,7 +152,7 @@
public void entityBaseTick() { public void entityBaseTick() {
this.world.getMethodProfiler().enter("entityBaseTick"); this.world.getMethodProfiler().enter("entityBaseTick");
if (this.isPassenger() && this.getVehicle().dead) { if (this.isPassenger() && this.getVehicle().dead) {
@@ -262,7 +369,7 @@ @@ -262,7 +370,7 @@
this.z = this.A; this.z = this.A;
this.lastPitch = this.pitch; this.lastPitch = this.pitch;
this.lastYaw = this.yaw; this.lastYaw = this.yaw;
@ -160,7 +161,7 @@
if (this.aN()) { if (this.aN()) {
this.aO(); this.aO();
} }
@@ -325,12 +432,44 @@ @@ -325,12 +433,44 @@
protected void burnFromLava() { protected void burnFromLava() {
if (!this.isFireProof()) { if (!this.isFireProof()) {
@ -206,7 +207,7 @@
int j = i * 20; int j = i * 20;
if (this instanceof EntityLiving) { if (this instanceof EntityLiving) {
@@ -427,6 +566,28 @@ @@ -427,6 +567,28 @@
block.a((IBlockAccess) this.world, this); block.a((IBlockAccess) this.world, this);
} }
@ -235,7 +236,7 @@
if (this.onGround && !this.bu()) { if (this.onGround && !this.bu()) {
block.stepOn(this.world, blockposition, this); block.stepOn(this.world, blockposition, this);
} }
@@ -700,6 +861,7 @@ @@ -700,6 +862,7 @@
AxisAlignedBB axisalignedbb = this.getBoundingBox(); AxisAlignedBB axisalignedbb = this.getBoundingBox();
this.setPositionRaw((axisalignedbb.minX + axisalignedbb.maxX) / 2.0D, axisalignedbb.minY, (axisalignedbb.minZ + axisalignedbb.maxZ) / 2.0D); this.setPositionRaw((axisalignedbb.minX + axisalignedbb.maxX) / 2.0D, axisalignedbb.minY, (axisalignedbb.minZ + axisalignedbb.maxZ) / 2.0D);
@ -243,7 +244,7 @@
} }
protected SoundEffect getSoundSwim() { protected SoundEffect getSoundSwim() {
@@ -1025,6 +1187,13 @@ @@ -1025,6 +1188,13 @@
} }
public void spawnIn(World world) { public void spawnIn(World world) {
@ -257,7 +258,7 @@
this.world = world; this.world = world;
} }
@@ -1044,6 +1213,7 @@ @@ -1044,6 +1214,7 @@
this.lastY = d1; this.lastY = d1;
this.lastZ = d4; this.lastZ = d4;
this.setPosition(d3, d1, d4); this.setPosition(d3, d1, d4);
@ -265,7 +266,7 @@
} }
public void d(Vec3D vec3d) { public void d(Vec3D vec3d) {
@@ -1218,6 +1388,12 @@ @@ -1218,6 +1389,12 @@
return false; return false;
} }
@ -278,7 +279,7 @@
public void a(Entity entity, int i, DamageSource damagesource) { public void a(Entity entity, int i, DamageSource damagesource) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
CriterionTriggers.c.a((EntityPlayer) entity, this, damagesource); CriterionTriggers.c.a((EntityPlayer) entity, this, damagesource);
@@ -1228,7 +1404,7 @@ @@ -1228,7 +1405,7 @@
public boolean a_(NBTTagCompound nbttagcompound) { public boolean a_(NBTTagCompound nbttagcompound) {
String s = this.getSaveID(); String s = this.getSaveID();
@ -287,7 +288,7 @@
nbttagcompound.setString("id", s); nbttagcompound.setString("id", s);
this.save(nbttagcompound); this.save(nbttagcompound);
return true; return true;
@@ -1252,6 +1428,18 @@ @@ -1252,6 +1429,18 @@
Vec3D vec3d = this.getMot(); Vec3D vec3d = this.getMot();
nbttagcompound.set("Motion", this.a(vec3d.x, vec3d.y, vec3d.z)); nbttagcompound.set("Motion", this.a(vec3d.x, vec3d.y, vec3d.z));
@ -306,7 +307,7 @@
nbttagcompound.set("Rotation", this.a(this.yaw, this.pitch)); nbttagcompound.set("Rotation", this.a(this.yaw, this.pitch));
nbttagcompound.setFloat("FallDistance", this.fallDistance); nbttagcompound.setFloat("FallDistance", this.fallDistance);
nbttagcompound.setShort("Fire", (short) this.fireTicks); nbttagcompound.setShort("Fire", (short) this.fireTicks);
@@ -1260,6 +1448,15 @@ @@ -1260,6 +1449,18 @@
nbttagcompound.setBoolean("Invulnerable", this.invulnerable); nbttagcompound.setBoolean("Invulnerable", this.invulnerable);
nbttagcompound.setInt("PortalCooldown", this.portalCooldown); nbttagcompound.setInt("PortalCooldown", this.portalCooldown);
nbttagcompound.a("UUID", this.getUniqueID()); nbttagcompound.a("UUID", this.getUniqueID());
@ -318,11 +319,14 @@
+ if (!this.persist) { + if (!this.persist) {
+ nbttagcompound.setBoolean("Bukkit.persist", this.persist); + nbttagcompound.setBoolean("Bukkit.persist", this.persist);
+ } + }
+ if (this.persistentInvisibility) {
+ nbttagcompound.setBoolean("Bukkit.invisible", this.persistentInvisibility);
+ }
+ // CraftBukkit end + // CraftBukkit end
IChatBaseComponent ichatbasecomponent = this.getCustomName(); IChatBaseComponent ichatbasecomponent = this.getCustomName();
if (ichatbasecomponent != null) { if (ichatbasecomponent != null) {
@@ -1317,6 +1514,11 @@ @@ -1317,6 +1518,11 @@
} }
} }
@ -334,7 +338,7 @@
return nbttagcompound; return nbttagcompound;
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT"); CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
@@ -1394,6 +1596,44 @@ @@ -1394,6 +1600,49 @@
} else { } else {
throw new IllegalStateException("Entity has invalid position"); throw new IllegalStateException("Entity has invalid position");
} }
@ -374,12 +378,17 @@
+ spawnIn(bworld == null ? null : ((CraftWorld) bworld).getHandle()); + spawnIn(bworld == null ? null : ((CraftWorld) bworld).getHandle());
+ } + }
+ this.getBukkitEntity().readBukkitValues(nbttagcompound); + this.getBukkitEntity().readBukkitValues(nbttagcompound);
+ if (nbttagcompound.hasKey("Bukkit.invisible")) {
+ boolean bukkitInvisible = nbttagcompound.getBoolean("Bukkit.invisible");
+ this.setInvisible(bukkitInvisible);
+ this.persistentInvisibility = bukkitInvisible;
+ }
+ // CraftBukkit end + // CraftBukkit end
+ +
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT"); CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
@@ -1469,9 +1709,22 @@ @@ -1469,9 +1718,22 @@
} else if (this.world.isClientSide) { } else if (this.world.isClientSide) {
return null; return null;
} else { } else {
@ -402,7 +411,7 @@
this.world.addEntity(entityitem); this.world.addEntity(entityitem);
return entityitem; return entityitem;
} }
@@ -1555,7 +1808,7 @@ @@ -1555,7 +1817,7 @@
this.setPose(EntityPose.STANDING); this.setPose(EntityPose.STANDING);
this.vehicle = entity; this.vehicle = entity;
@ -411,7 +420,7 @@
return true; return true;
} }
} }
@@ -1580,7 +1833,7 @@ @@ -1580,7 +1842,7 @@
Entity entity = this.vehicle; Entity entity = this.vehicle;
this.vehicle = null; this.vehicle = null;
@ -420,7 +429,7 @@
} }
} }
@@ -1589,10 +1842,31 @@ @@ -1589,10 +1851,31 @@
this.be(); this.be();
} }
@ -453,7 +462,7 @@
if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) { if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) {
this.passengers.add(0, entity); this.passengers.add(0, entity);
} else { } else {
@@ -1600,15 +1874,36 @@ @@ -1600,15 +1883,36 @@
} }
} }
@ -491,7 +500,7 @@
} }
protected boolean q(Entity entity) { protected boolean q(Entity entity) {
@@ -1649,11 +1944,17 @@ @@ -1649,11 +1953,17 @@
ResourceKey<World> resourcekey = this.world.getDimensionKey() == World.THE_NETHER ? World.OVERWORLD : World.THE_NETHER; ResourceKey<World> resourcekey = this.world.getDimensionKey() == World.THE_NETHER ? World.OVERWORLD : World.THE_NETHER;
WorldServer worldserver1 = minecraftserver.getWorldServer(resourcekey); WorldServer worldserver1 = minecraftserver.getWorldServer(resourcekey);
@ -511,7 +520,7 @@
this.world.getMethodProfiler().exit(); this.world.getMethodProfiler().exit();
} }
@@ -1753,6 +2054,13 @@ @@ -1753,6 +2063,13 @@
} }
public void setSwimming(boolean flag) { public void setSwimming(boolean flag) {
@ -525,7 +534,21 @@
this.setFlag(4, flag); this.setFlag(4, flag);
} }
@@ -1813,16 +2121,56 @@ @@ -1785,8 +2102,12 @@
return this.getScoreboardTeam() != null ? this.getScoreboardTeam().isAlly(scoreboardteambase) : false;
}
+ // CraftBukkit - start
public void setInvisible(boolean flag) {
- this.setFlag(5, flag);
+ if (!this.persistentInvisibility) { // Prevent Minecraft from removing our invisibility flag
+ this.setFlag(5, flag);
+ }
+ // CraftBukkit - end
}
public boolean getFlag(int i) {
@@ -1813,16 +2134,56 @@
} }
public void setAirTicks(int i) { public void setAirTicks(int i) {
@ -585,7 +608,7 @@
} }
public void k(boolean flag) { public void k(boolean flag) {
@@ -1972,15 +2320,32 @@ @@ -1972,15 +2333,32 @@
@Nullable @Nullable
public Entity b(WorldServer worldserver) { public Entity b(WorldServer worldserver) {
@ -620,7 +643,7 @@
this.world.getMethodProfiler().exitEnter("reloading"); this.world.getMethodProfiler().exitEnter("reloading");
Entity entity = this.getEntityType().a((World) worldserver); Entity entity = this.getEntityType().a((World) worldserver);
@@ -1989,9 +2354,17 @@ @@ -1989,9 +2367,17 @@
entity.setPositionRotation(shapedetectorshape.position.x, shapedetectorshape.position.y, shapedetectorshape.position.z, shapedetectorshape.yaw, entity.pitch); entity.setPositionRotation(shapedetectorshape.position.x, shapedetectorshape.position.y, shapedetectorshape.position.z, shapedetectorshape.yaw, entity.pitch);
entity.setMot(shapedetectorshape.velocity); entity.setMot(shapedetectorshape.velocity);
worldserver.addEntityTeleport(entity); worldserver.addEntityTeleport(entity);
@ -628,19 +651,19 @@
- WorldServer.a(worldserver); - WorldServer.a(worldserver);
+ if (worldserver.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit + if (worldserver.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit
+ WorldServer.a(worldserver, this); // CraftBukkit + WorldServer.a(worldserver, this); // CraftBukkit
+ } }
+ // CraftBukkit start - Forward the CraftEntity to the new entity + // CraftBukkit start - Forward the CraftEntity to the new entity
+ this.getBukkitEntity().setHandle(entity); + this.getBukkitEntity().setHandle(entity);
+ entity.bukkitEntity = this.getBukkitEntity(); + entity.bukkitEntity = this.getBukkitEntity();
+ +
+ if (this instanceof EntityInsentient) { + if (this instanceof EntityInsentient) {
+ ((EntityInsentient) this).unleash(true, false); // Unleash to prevent duping of leads. + ((EntityInsentient) this).unleash(true, false); // Unleash to prevent duping of leads.
} + }
+ // CraftBukkit end + // CraftBukkit end
} }
this.bM(); this.bM();
@@ -2012,13 +2385,18 @@ @@ -2012,13 +2398,18 @@
@Nullable @Nullable
protected ShapeDetectorShape a(WorldServer worldserver) { protected ShapeDetectorShape a(WorldServer worldserver) {
@ -663,7 +686,7 @@
return null; return null;
} else { } else {
WorldBorder worldborder = worldserver.getWorldBorder(); WorldBorder worldborder = worldserver.getWorldBorder();
@@ -2028,8 +2406,16 @@ @@ -2028,8 +2419,16 @@
double d3 = Math.min(2.9999872E7D, worldborder.h() - 16.0D); double d3 = Math.min(2.9999872E7D, worldborder.h() - 16.0D);
double d4 = DimensionManager.a(this.world.getDimensionManager(), worldserver.getDimensionManager()); 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)); BlockPosition blockposition = new BlockPosition(MathHelper.a(this.locX() * d4, d0, d2), this.locY(), MathHelper.a(this.locZ() * d4, d1, d3));
@ -681,7 +704,7 @@
IBlockData iblockdata = this.world.getType(this.ac); IBlockData iblockdata = this.world.getType(this.ac);
EnumDirection.EnumAxis enumdirection_enumaxis; EnumDirection.EnumAxis enumdirection_enumaxis;
Vec3D vec3d; Vec3D vec3d;
@@ -2046,8 +2432,8 @@ @@ -2046,8 +2445,8 @@
vec3d = new Vec3D(0.5D, 0.0D, 0.0D); vec3d = new Vec3D(0.5D, 0.0D, 0.0D);
} }
@ -692,7 +715,7 @@
} }
} else { } else {
BlockPosition blockposition1; BlockPosition blockposition1;
@@ -2057,8 +2443,15 @@ @@ -2057,8 +2456,15 @@
} else { } else {
blockposition1 = worldserver.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSpawn()); blockposition1 = worldserver.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSpawn());
} }
@ -709,7 +732,7 @@
} }
} }
@@ -2066,8 +2459,23 @@ @@ -2066,8 +2472,23 @@
return BlockPortalShape.a(blockutil_rectangle, enumdirection_enumaxis, this.getPositionVector(), this.a(this.getPose())); return BlockPortalShape.a(blockutil_rectangle, enumdirection_enumaxis, this.getPositionVector(), this.a(this.getPose()));
} }
@ -735,7 +758,7 @@
} }
public boolean canPortal() { public boolean canPortal() {
@@ -2253,7 +2661,26 @@ @@ -2253,7 +2674,26 @@
} }
public void a(AxisAlignedBB axisalignedbb) { public void a(AxisAlignedBB axisalignedbb) {

View File

@ -675,4 +675,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
throw new UnsupportedOperationException("Unsupported monster type: " + type + ". This is a bug, report this to Spigot."); throw new UnsupportedOperationException("Unsupported monster type: " + type + ". This is a bug, report this to Spigot.");
} }
@Override
public boolean isInvisible() {
return getHandle().isInvisible();
}
@Override
public void setInvisible(boolean invisible) {
getHandle().persistentInvisibility = invisible;
getHandle().setFlag(5, invisible);
}
} }