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