diff options
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/Entity.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/Entity.java.patch | 1065 |
1 files changed, 1065 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/Entity.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/Entity.java.patch new file mode 100644 index 0000000000..108c062a94 --- /dev/null +++ b/patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/Entity.java.patch @@ -0,0 +1,1065 @@ +--- a/net/minecraft/world/entity/Entity.java ++++ b/net/minecraft/world/entity/Entity.java +@@ -123,8 +126,63 @@ + import net.minecraft.world.scores.Team; + import org.joml.Vector3f; + import org.slf4j.Logger; ++import org.bukkit.Bukkit; ++import org.bukkit.Location; ++import org.bukkit.Server; ++import org.bukkit.block.BlockFace; ++import org.bukkit.command.CommandSender; ++import org.bukkit.craftbukkit.event.CraftPortalEvent; ++import org.bukkit.entity.Hanging; ++import org.bukkit.entity.LivingEntity; ++import org.bukkit.entity.Vehicle; ++import org.bukkit.event.entity.EntityCombustByEntityEvent; ++import org.bukkit.event.hanging.HangingBreakByEntityEvent; ++import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; ++import org.bukkit.event.vehicle.VehicleEnterEvent; ++import org.bukkit.event.vehicle.VehicleExitEvent; ++import org.bukkit.craftbukkit.CraftWorld; ++import org.bukkit.craftbukkit.entity.CraftEntity; ++import org.bukkit.craftbukkit.entity.CraftPlayer; ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.craftbukkit.util.CraftLocation; ++import org.bukkit.entity.Pose; ++import org.bukkit.event.entity.EntityAirChangeEvent; ++import org.bukkit.event.entity.EntityCombustEvent; ++import org.bukkit.event.entity.EntityDropItemEvent; ++import org.bukkit.event.entity.EntityPortalEvent; ++import org.bukkit.event.entity.EntityPoseChangeEvent; ++import org.bukkit.event.player.PlayerTeleportEvent; ++import org.bukkit.plugin.PluginManager; ++// CraftBukkit end + +-public abstract class Entity implements Nameable, EntityAccess, CommandSource, ScoreHolder { ++public abstract class Entity implements INamableTileEntity, EntityAccess, CommandSource, ScoreHolder { ++ ++ // CraftBukkit start ++ private static final int CURRENT_LEVEL = 2; ++ static boolean isLevelAtLeast(CompoundTag tag, int level) { ++ return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level; ++ } ++ ++ private CraftEntity bukkitEntity; ++ ++ public CraftEntity getBukkitEntity() { ++ if (bukkitEntity == null) { ++ bukkitEntity = CraftEntity.getEntity(level.getCraftServer(), this); ++ } ++ return bukkitEntity; ++ } ++ ++ @Override ++ public CommandSender getBukkitSender(CommandSourceStack wrapper) { ++ return getBukkitEntity(); ++ } ++ ++ // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() ++ public int getDefaultMaxAirSupply() { ++ return TOTAL_AIR_SUPPLY; ++ } ++ // CraftBukkit end ++ + private static final Logger LOGGER = LogUtils.getLogger(); + public static final String ID_TAG = "id"; + public static final String PASSENGERS_TAG = "Passengers"; +@@ -240,8 +296,31 @@ + private int lastCrystalSoundPlayTick; + private boolean hasVisualFire; + @Nullable +- private BlockState feetBlockState = null; ++ private IBlockData feetBlockState; ++ // CraftBukkit start ++ public boolean persist = true; ++ public boolean visibleByDefault = true; ++ public boolean valid; ++ public boolean inWorld = false; ++ public boolean generation; ++ public int maxAirTicks = getDefaultMaxAirSupply(); // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() ++ public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only ++ public boolean lastDamageCancelled; // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Keep track if the event was canceled ++ public boolean persistentInvisibility = false; ++ public BlockPos lastLavaContact; ++ // Marks an entity, that it was removed by a plugin via Entity#remove ++ // Main use case currently is for SPIGOT-7487, preventing dropping of leash when leash is removed ++ public boolean pluginRemoved = false; + ++ public float getBukkitYaw() { ++ return this.yRot; ++ } ++ ++ public boolean isChunkLoaded() { ++ return level.hasChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4); ++ } ++ // CraftBukkit end ++ + public Entity(EntityType<?> entityType, Level level) { + this.type = entityType; + this.level = level; +@@ -353,8 +452,14 @@ + public void onClientRemoval() { + } + +- public void setPose(Pose pose) { +- this.entityData.set(DATA_POSE, pose); ++ public void setPose(EntityPose pose) { ++ // CraftBukkit start ++ if (pose == this.getPose()) { ++ return; ++ } ++ this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), Pose.values()[pose.ordinal()])); ++ // CraftBukkit end ++ this.entityData.set(Entity.DATA_POSE, pose); + } + + public Pose getPose() { +@@ -377,6 +483,33 @@ + } + + protected void setRot(float yRot, float xRot) { ++ // CraftBukkit start - yaw was sometimes set to NaN, so we need to set it back to 0 ++ if (Float.isNaN(yRot)) { ++ yRot = 0; ++ } ++ ++ if (yRot == Float.POSITIVE_INFINITY || yRot == Float.NEGATIVE_INFINITY) { ++ if (this instanceof ServerPlayer) { ++ this.level.getCraftServer().getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid yaw"); ++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite yaw (Hacking?)"); ++ } ++ yRot = 0; ++ } ++ ++ // pitch was sometimes set to NaN, so we need to set it back to 0 ++ if (Float.isNaN(xRot)) { ++ xRot = 0; ++ } ++ ++ if (xRot == Float.POSITIVE_INFINITY || xRot == Float.NEGATIVE_INFINITY) { ++ if (this instanceof ServerPlayer) { ++ this.level.getCraftServer().getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid pitch"); ++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite pitch (Hacking?)"); ++ } ++ xRot = 0; ++ } ++ // CraftBukkit end ++ + this.setYRot(yRot % 360.0F); + this.setXRot(xRot % 360.0F); + } +@@ -416,6 +551,15 @@ + this.baseTick(); + } + ++ // CraftBukkit start ++ public void postTick() { ++ // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle ++ if (!(this instanceof ServerPlayer)) { ++ this.handleNetherPortal(); ++ } ++ } ++ // CraftBukkit end ++ + public void baseTick() { + this.level().getProfiler().push("entityBaseTick"); + this.feetBlockState = null; +@@ -430,7 +574,7 @@ + this.walkDistO = this.walkDist; + this.xRotO = this.getXRot(); + this.yRotO = this.getYRot(); +- this.handleNetherPortal(); ++ if (this instanceof ServerPlayer) this.handleNetherPortal(); // CraftBukkit - // Moved up to postTick + if (this.canSpawnSprintParticle()) { + this.spawnSprintParticle(); + } +@@ -465,6 +609,10 @@ + if (this.isInLava()) { + this.lavaHurt(); + this.fallDistance *= 0.5F; ++ // CraftBukkit start ++ } else { ++ this.lastLavaContact = null; ++ // CraftBukkit end + } + + this.checkBelowWorld(); +@@ -514,18 +664,49 @@ + + public void lavaHurt() { + if (!this.fireImmune()) { +- this.setSecondsOnFire(15); ++ // CraftBukkit start - Fallen in lava TODO: this event spams! ++ if (this instanceof net.minecraft.world.entity.LivingEntity && remainingFireTicks <= 0) { ++ // not on fire yet ++ org.bukkit.block.Block damager = (lastLavaContact == null) ? null : org.bukkit.craftbukkit.block.CraftBlock.at(level, lastLavaContact); ++ org.bukkit.entity.Entity damagee = this.getBukkitEntity(); ++ EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15); ++ this.level.getCraftServer().getPluginManager().callEvent(combustEvent); ++ ++ if (!combustEvent.isCancelled()) { ++ this.setSecondsOnFire(combustEvent.getDuration(), false); ++ } ++ } else { ++ // This will be called every single tick the entity is in lava, so don't throw an event ++ this.setSecondsOnFire(15, false); ++ } ++ CraftEventFactory.blockDamage = (lastLavaContact) == null ? null : org.bukkit.craftbukkit.block.CraftBlock.at(level, lastLavaContact); + if (this.hurt(this.damageSources().lava(), 4.0F)) { + this.playSound(SoundEvents.GENERIC_BURN, 0.4F, 2.0F + this.random.nextFloat() * 0.4F); + } ++ CraftEventFactory.blockDamage = null; ++ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls ++ + } + } + + public void setSecondsOnFire(int seconds) { +- int i = seconds * 20; +- if (this instanceof LivingEntity) { +- i = ProtectionEnchantment.getFireAfterDampener((LivingEntity)this, i); ++ // CraftBukkit start ++ this.setSecondsOnFire(seconds, true); ++ } ++ ++ public void setSecondsOnFire(int i, boolean callEvent) { ++ if (callEvent) { ++ EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), i); ++ this.level.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return; ++ } ++ ++ i = event.getDuration(); + } ++ // CraftBukkit end ++ int j = i * 20; + + if (this.remainingFireTicks < i) { + this.setRemainingFireTicks(i); +@@ -662,6 +856,28 @@ + block.updateEntityAfterFallOn(this.level(), this); + } + ++ // CraftBukkit start ++ if (horizontalCollision && getBukkitEntity() instanceof Vehicle) { ++ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); ++ org.bukkit.block.Block bl = this.level.getWorld().getBlockAt(Mth.floor(this.getX()), Mth.floor(this.getY()), Mth.floor(this.getZ())); ++ ++ if (pos.x > vec3d1.x) { ++ bl = bl.getRelative(BlockFace.EAST); ++ } else if (pos.x < vec3d1.x) { ++ bl = bl.getRelative(BlockFace.WEST); ++ } else if (pos.z > vec3d1.z) { ++ bl = bl.getRelative(BlockFace.SOUTH); ++ } else if (pos.z < vec3d1.z) { ++ bl = bl.getRelative(BlockFace.NORTH); ++ } ++ ++ if (!bl.getType().isAir()) { ++ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl); ++ level.getCraftServer().getPluginManager().callEvent(event); ++ } ++ } ++ // CraftBukkit end ++ + if (this.onGround()) { + block.stepOn(this.level(), onPosLegacy, blockState, this); + } +@@ -976,6 +1205,20 @@ + return SoundEvents.GENERIC_SPLASH; + } + ++ // CraftBukkit start - Add delegate methods ++ public SoundEvent getSwimSound0() { ++ return getSwimSound(); ++ } ++ ++ public SoundEvent getSwimSplashSound0() { ++ return getSwimSplashSound(); ++ } ++ ++ public SoundEvent getSwimHighSpeedSplashSound0() { ++ return getSwimHighSpeedSplashSound(); ++ } ++ // CraftBukkit end ++ + protected void checkInsideBlocks() { + AABB boundingBox = this.getBoundingBox(); + BlockPos blockPos = BlockPos.containing(boundingBox.minX + 1.0E-7, boundingBox.minY + 1.0E-7, boundingBox.minZ + 1.0E-7); +@@ -1357,13 +1625,15 @@ + this.xRotO = this.getXRot(); + } + +- public void absMoveTo(double x, double y, double z) { +- double d = Mth.clamp(x, -3.0E7, 3.0E7); +- double d1 = Mth.clamp(z, -3.0E7, 3.0E7); +- this.xo = d; +- this.yo = y; +- this.zo = d1; +- this.setPos(d, y, d1); ++ public void absMoveTo(double x, double d1, double y) { ++ double d3 = Mth.clamp(x, -3.0E7D, 3.0E7D); ++ double d4 = Mth.clamp(y, -3.0E7D, 3.0E7D); ++ ++ this.xo = d3; ++ this.yo = d1; ++ this.zo = d4; ++ this.setPos(d3, d1, d4); ++ if (valid) level.getChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4); // CraftBukkit + } + + public void moveTo(Vec3 vec) { +@@ -1549,6 +1828,12 @@ + return false; + } + ++ // CraftBukkit start - collidable API ++ public boolean canCollideWithBukkit(Entity entity) { ++ return isPushable(); ++ } ++ // CraftBukkit end ++ + public void awardKillScore(Entity killed, int scoreValue, DamageSource source) { + if (killed instanceof ServerPlayer) { + CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer)killed, this, source); +@@ -1574,15 +1862,22 @@ + } + + public boolean saveAsPassenger(CompoundTag compound) { ++ // CraftBukkit start - allow excluding certain data when saving ++ return saveAsPassenger(compound, true); ++ } ++ ++ public boolean saveAsPassenger(CompoundTag nbttagcompound, boolean includeAll) { ++ // CraftBukkit end + if (this.removalReason != null && !this.removalReason.shouldSave()) { + return false; + } else { +- String encodeId = this.getEncodeId(); +- if (encodeId == null) { ++ String s = this.getEncodeId(); ++ ++ if (!this.persist || s == null) { // CraftBukkit - persist flag + return false; + } else { +- compound.putString("id", encodeId); +- this.saveWithoutId(compound); ++ nbttagcompound.putString("id", s); ++ this.saveWithoutId(nbttagcompound, includeAll); // CraftBukkit - pass on includeAll + return true; + } + } +@@ -1593,28 +1888,73 @@ + } + + public CompoundTag saveWithoutId(CompoundTag compound) { ++ // CraftBukkit start - allow excluding certain data when saving ++ return saveWithoutId(compound, true); ++ } ++ ++ public CompoundTag saveWithoutId(CompoundTag nbttagcompound, boolean includeAll) { ++ // CraftBukkit end + try { +- if (this.vehicle != null) { +- compound.put("Pos", this.newDoubleList(this.vehicle.getX(), this.getY(), this.vehicle.getZ())); +- } else { +- compound.put("Pos", this.newDoubleList(this.getX(), this.getY(), this.getZ())); ++ // CraftBukkit start - selectively save position ++ if (includeAll) { ++ if (this.vehicle != null) { ++ nbttagcompound.put("Pos", this.newDoubleList(this.vehicle.getX(), this.getY(), this.vehicle.getZ())); ++ } else { ++ nbttagcompound.put("Pos", this.newDoubleList(this.getX(), this.getY(), this.getZ())); ++ } + } ++ // CraftBukkit end + +- Vec3 deltaMovement = this.getDeltaMovement(); +- compound.put("Motion", this.newDoubleList(deltaMovement.x, deltaMovement.y, deltaMovement.z)); +- compound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot())); +- compound.putFloat("FallDistance", this.fallDistance); +- compound.putShort("Fire", (short)this.remainingFireTicks); +- compound.putShort("Air", (short)this.getAirSupply()); +- compound.putBoolean("OnGround", this.onGround()); +- compound.putBoolean("Invulnerable", this.invulnerable); +- compound.putInt("PortalCooldown", this.portalCooldown); +- compound.putUUID("UUID", this.getUUID()); +- Component customName = this.getCustomName(); +- if (customName != null) { +- compound.putString("CustomName", Component.Serializer.toJson(customName)); ++ Vec3 vec3d = this.getDeltaMovement(); ++ ++ nbttagcompound.put("Motion", this.newDoubleList(vec3d.x, vec3d.y, vec3d.z)); ++ ++ // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero ++ // TODO: make sure this is the best way to address this. ++ if (Float.isNaN(this.yRot)) { ++ this.yRot = 0; + } + ++ if (Float.isNaN(this.xRot)) { ++ this.xRot = 0; ++ } ++ // CraftBukkit end ++ ++ nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot())); ++ nbttagcompound.putFloat("FallDistance", this.fallDistance); ++ nbttagcompound.putShort("Fire", (short) this.remainingFireTicks); ++ nbttagcompound.putShort("Air", (short) this.getAirSupply()); ++ nbttagcompound.putBoolean("OnGround", this.onGround()); ++ nbttagcompound.putBoolean("Invulnerable", this.invulnerable); ++ nbttagcompound.putInt("PortalCooldown", this.portalCooldown); ++ // CraftBukkit start - selectively save uuid and world ++ if (includeAll) { ++ nbttagcompound.putUUID("UUID", this.getUUID()); ++ // PAIL: Check above UUID reads 1.8 properly, ie: UUIDMost / UUIDLeast ++ nbttagcompound.putLong("WorldUUIDLeast", ((ServerLevel) this.level).getWorld().getUID().getLeastSignificantBits()); ++ nbttagcompound.putLong("WorldUUIDMost", ((ServerLevel) this.level).getWorld().getUID().getMostSignificantBits()); ++ } ++ nbttagcompound.putInt("Bukkit.updateLevel", CURRENT_LEVEL); ++ if (!this.persist) { ++ nbttagcompound.putBoolean("Bukkit.persist", this.persist); ++ } ++ if (!this.visibleByDefault) { ++ nbttagcompound.putBoolean("Bukkit.visibleByDefault", this.visibleByDefault); ++ } ++ if (this.persistentInvisibility) { ++ nbttagcompound.putBoolean("Bukkit.invisible", this.persistentInvisibility); ++ } ++ // SPIGOT-6907: re-implement LivingEntity#setMaximumAir() ++ if (maxAirTicks != getDefaultMaxAirSupply()) { ++ nbttagcompound.putInt("Bukkit.MaxAirSupply", getMaxAirSupply()); ++ } ++ // CraftBukkit end ++ Component ichatbasecomponent = this.getCustomName(); ++ ++ if (ichatbasecomponent != null) { ++ nbttagcompound.putString("CustomName", Component.Serializer.toJson(ichatbasecomponent)); ++ } ++ + if (this.isCustomNameVisible()) { + compound.putBoolean("CustomNameVisible", this.isCustomNameVisible()); + } +@@ -1650,14 +1997,16 @@ + compound.put("Tags", list); + } + +- this.addAdditionalSaveData(compound); ++ this.addAdditionalSaveData(nbttagcompound, includeAll); // CraftBukkit - pass on includeAll + if (this.isVehicle()) { + ListTag list = new ListTag(); + +- for (Entity entity : this.getPassengers()) { +- CompoundTag compoundTag = new CompoundTag(); +- if (entity.saveAsPassenger(compoundTag)) { +- list.add(compoundTag); ++ while (iterator.hasNext()) { ++ Entity entity = (Entity) iterator.next(); ++ CompoundTag nbttagcompound1 = new CompoundTag(); ++ ++ if (entity.saveAsPassenger(nbttagcompound1, includeAll)) { // CraftBukkit - pass on includeAll ++ nbttaglist.add(nbttagcompound1); + } + } + +@@ -1666,12 +2016,18 @@ + } + } + +- return compound; +- } catch (Throwable var9) { +- CrashReport crashReport = CrashReport.forThrowable(var9, "Saving entity NBT"); +- CrashReportCategory crashReportCategory = crashReport.addCategory("Entity being saved"); +- this.fillCrashReportCategory(crashReportCategory); +- throw new ReportedException(crashReport); ++ // CraftBukkit start - stores eventually existing bukkit values ++ if (this.bukkitEntity != null) { ++ this.bukkitEntity.storeBukkitValues(nbttagcompound); ++ } ++ // CraftBukkit end ++ return nbttagcompound; ++ } catch (Throwable throwable) { ++ CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); ++ CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved"); ++ ++ this.fillCrashReportCategory(crashreportsystemdetails); ++ throw new ReportedException(crashreport); + } + } + +@@ -1749,11 +2104,51 @@ + } else { + throw new IllegalStateException("Entity has invalid rotation"); + } +- } catch (Throwable var17) { +- CrashReport crashReport = CrashReport.forThrowable(var17, "Loading entity NBT"); +- CrashReportCategory crashReportCategory = crashReport.addCategory("Entity being loaded"); +- this.fillCrashReportCategory(crashReportCategory); +- throw new ReportedException(crashReport); ++ ++ // CraftBukkit start ++ this.persist = !compound.contains("Bukkit.persist") || compound.getBoolean("Bukkit.persist"); ++ this.visibleByDefault = !compound.contains("Bukkit.visibleByDefault") || compound.getBoolean("Bukkit.visibleByDefault"); ++ // SPIGOT-6907: re-implement LivingEntity#setMaximumAir() ++ if (compound.contains("Bukkit.MaxAirSupply")) { ++ maxAirTicks = compound.getInt("Bukkit.MaxAirSupply"); ++ } ++ // CraftBukkit end ++ ++ // CraftBukkit start - Reset world ++ if (this instanceof ServerPlayer) { ++ Server server = Bukkit.getServer(); ++ org.bukkit.World bworld = null; ++ ++ // TODO: Remove World related checks, replaced with WorldUID ++ String worldName = compound.getString("world"); ++ ++ if (compound.contains("WorldUUIDMost") && compound.contains("WorldUUIDLeast")) { ++ UUID uid = new UUID(compound.getLong("WorldUUIDMost"), compound.getLong("WorldUUIDLeast")); ++ bworld = server.getWorld(uid); ++ } else { ++ bworld = server.getWorld(worldName); ++ } ++ ++ if (bworld == null) { ++ bworld = ((org.bukkit.craftbukkit.CraftServer) server).getServer().getLevel(Level.OVERWORLD).getWorld(); ++ } ++ ++ ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle()); ++ } ++ this.getBukkitEntity().readBukkitValues(compound); ++ if (compound.contains("Bukkit.invisible")) { ++ boolean bukkitInvisible = compound.getBoolean("Bukkit.invisible"); ++ this.setInvisible(bukkitInvisible); ++ this.persistentInvisibility = bukkitInvisible; ++ } ++ // CraftBukkit end ++ ++ } catch (Throwable throwable) { ++ CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); ++ CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); ++ ++ this.fillCrashReportCategory(crashreportsystemdetails); ++ throw new ReportedException(crashreport); + } + } + +@@ -1768,6 +2164,12 @@ + return type.canSerialize() && key != null ? key.toString() : null; + } + ++ // CraftBukkit start - allow excluding certain data when saving ++ protected void addAdditionalSaveData(CompoundTag nbttagcompound, boolean includeAll) { ++ addAdditionalSaveData(nbttagcompound); ++ } ++ // CraftBukkit end ++ + protected abstract void readAdditionalSaveData(CompoundTag compound); + + protected abstract void addAdditionalSaveData(CompoundTag compound); +@@ -1814,10 +2224,24 @@ + } else if (this.level().isClientSide) { + return null; + } else { +- ItemEntity itemEntity = new ItemEntity(this.level(), this.getX(), this.getY() + (double)offsetY, this.getZ(), stack); +- itemEntity.setDefaultPickUpDelay(); +- this.level().addFreshEntity(itemEntity); +- return itemEntity; ++ // CraftBukkit start - Capture drops for death event ++ if (this instanceof net.minecraft.world.entity.LivingEntity && !((net.minecraft.world.entity.LivingEntity) this).forceDrops) { ++ ((net.minecraft.world.entity.LivingEntity) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(stack)); ++ return null; ++ } ++ // CraftBukkit end ++ ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY() + (double) offsetY, this.getZ(), stack); ++ ++ entityitem.setDefaultPickUpDelay(); ++ // CraftBukkit start ++ EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); ++ Bukkit.getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return null; ++ } ++ // CraftBukkit end ++ this.level().addFreshEntity(entityitem); ++ return entityitem; + } + } + +@@ -1918,7 +2334,21 @@ + } + } + +- if (force || this.canRide(vehicle) && vehicle.canAddPassenger(this)) { ++ if (!force && (!this.canRide(vehicle) || !vehicle.canAddPassenger(this))) { ++ return false; ++ } else { ++ // CraftBukkit start ++ if (vehicle.getBukkitEntity() instanceof Vehicle && this.getBukkitEntity() instanceof LivingEntity) { ++ VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) vehicle.getBukkitEntity(), this.getBukkitEntity()); ++ // Suppress during worldgen ++ if (this.valid) { ++ Bukkit.getPluginManager().callEvent(event); ++ } ++ if (event.isCancelled()) { ++ return false; ++ } ++ } ++ // CraftBukkit end + if (this.isPassenger()) { + this.stopRiding(); + } +@@ -1950,7 +2382,7 @@ + if (this.vehicle != null) { + Entity entity = this.vehicle; + this.vehicle = null; +- entity.removePassenger(this); ++ if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit + } + } + +@@ -1979,11 +2413,30 @@ + } + } + +- protected void removePassenger(Entity passenger) { +- if (passenger.getVehicle() == this) { ++ protected boolean removePassenger(Entity entity) { // CraftBukkit ++ if (entity.getVehicle() == this) { + throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)"); + } else { +- if (this.passengers.size() == 1 && this.passengers.get(0) == passenger) { ++ // CraftBukkit start ++ CraftEntity craft = (CraftEntity) entity.getBukkitEntity().getVehicle(); ++ Entity orig = craft == null ? null : craft.getHandle(); ++ if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) { ++ VehicleExitEvent event = new VehicleExitEvent( ++ (Vehicle) getBukkitEntity(), ++ (LivingEntity) entity.getBukkitEntity() ++ ); ++ // Suppress during worldgen ++ if (this.valid) { ++ Bukkit.getPluginManager().callEvent(event); ++ } ++ CraftEntity craftn = (CraftEntity) entity.getBukkitEntity().getVehicle(); ++ Entity n = craftn == null ? null : craftn.getHandle(); ++ if (event.isCancelled() || n != orig) { ++ return false; ++ } ++ } ++ // CraftBukkit end ++ if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { + this.passengers = ImmutableList.of(); + } else { + this.passengers = this.passengers.stream().filter(entity -> entity != passenger).collect(ImmutableList.toImmutableList()); +@@ -1992,6 +2447,7 @@ + passenger.boardingCooldown = 60; + this.gameEvent(GameEvent.ENTITY_DISMOUNT, passenger); + } ++ return true; // CraftBukkit + } + + protected boolean canAddPassenger(Entity passenger) { +@@ -2074,14 +2533,21 @@ + int portalWaitTime = this.getPortalWaitTime(); + ServerLevel serverLevel = (ServerLevel)this.level(); + if (this.isInsidePortal) { +- MinecraftServer server = serverLevel.getServer(); +- ResourceKey<Level> resourceKey = this.level().dimension() == Level.NETHER ? Level.OVERWORLD : Level.NETHER; +- ServerLevel level = server.getLevel(resourceKey); +- if (level != null && server.isNetherEnabled() && !this.isPassenger() && this.portalTime++ >= portalWaitTime) { ++ MinecraftServer minecraftserver = worldserver.getServer(); ++ ResourceKey<Level> resourcekey = this.level().getTypeKey() == LevelStem.NETHER ? Level.OVERWORLD : Level.NETHER; // CraftBukkit ++ ServerLevel worldserver1 = minecraftserver.getLevel(resourcekey); ++ ++ if (true && !this.isPassenger() && this.portalTime++ >= i) { // CraftBukkit + this.level().getProfiler().push("portal"); + this.portalTime = portalWaitTime; + this.setPortalCooldown(); +- this.changeDimension(level); ++ // CraftBukkit start ++ if (this instanceof ServerPlayer) { ++ ((ServerPlayer) this).changeDimension(worldserver1, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); ++ } else { ++ this.changeDimension(worldserver1); ++ } ++ // CraftBukkit end + this.level().getProfiler().pop(); + } + +@@ -2206,6 +2671,13 @@ + } + + public void setSwimming(boolean swimming) { ++ // CraftBukkit start ++ if (valid && this.isSwimming() != swimming && this instanceof net.minecraft.world.entity.LivingEntity) { ++ if (CraftEventFactory.callToggleSwimEvent((net.minecraft.world.entity.LivingEntity) this, swimming).isCancelled()) { ++ return; ++ } ++ } ++ // CraftBukkit end + this.setSharedFlag(4, swimming); + } + +@@ -2255,8 +2727,12 @@ + return this.getTeam() != null && this.getTeam().isAlliedTo(team); + } + ++ // CraftBukkit - start + public void setInvisible(boolean invisible) { +- this.setSharedFlag(5, invisible); ++ if (!this.persistentInvisibility) { // Prevent Minecraft from removing our invisibility flag ++ this.setSharedFlag(5, invisible); ++ } ++ // CraftBukkit - end + } + + protected boolean getSharedFlag(int flag) { +@@ -2273,7 +2751,7 @@ + } + + public int getMaxAirSupply() { +- return 300; ++ return maxAirTicks; // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() + } + + public int getAirSupply() { +@@ -2281,7 +2759,18 @@ + } + + public void setAirSupply(int air) { +- this.entityData.set(DATA_AIR_SUPPLY_ID, air); ++ // CraftBukkit start ++ EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), air); ++ // Suppress during worldgen ++ if (this.valid) { ++ event.getEntity().getServer().getPluginManager().callEvent(event); ++ } ++ if (event.isCancelled() && this.getAirSupply() != air) { ++ this.entityData.markDirty(Entity.DATA_AIR_SUPPLY_ID); ++ return; ++ } ++ this.entityData.set(Entity.DATA_AIR_SUPPLY_ID, event.getAmount()); ++ // CraftBukkit end + } + + public int getTicksFrozen() { +@@ -2307,11 +2797,41 @@ + + public void thunderHit(ServerLevel level, LightningBolt lightning) { + this.setRemainingFireTicks(this.remainingFireTicks + 1); ++ // CraftBukkit start ++ final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); ++ final org.bukkit.entity.Entity stormBukkitEntity = lightning.getBukkitEntity(); ++ final PluginManager pluginManager = Bukkit.getPluginManager(); ++ // CraftBukkit end ++ + if (this.remainingFireTicks == 0) { +- this.setSecondsOnFire(8); ++ // CraftBukkit start - Call a combust event when lightning strikes ++ EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8); ++ pluginManager.callEvent(entityCombustEvent); ++ if (!entityCombustEvent.isCancelled()) { ++ this.setSecondsOnFire(entityCombustEvent.getDuration(), false); ++ } ++ // CraftBukkit end + } + +- this.hurt(this.damageSources().lightningBolt(), 5.0F); ++ // CraftBukkit start ++ if (thisBukkitEntity instanceof Hanging) { ++ HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity); ++ pluginManager.callEvent(hangingEvent); ++ ++ if (hangingEvent.isCancelled()) { ++ return; ++ } ++ } ++ ++ if (this.fireImmune()) { ++ return; ++ } ++ CraftEventFactory.entityDamage = lightning; ++ if (!this.hurt(this.damageSources().lightningBolt(), 5.0F)) { ++ CraftEventFactory.entityDamage = null; ++ return; ++ } ++ // CraftBukkit end + } + + public void onAboveBubbleCol(boolean downwards) { +@@ -2489,24 +2996,60 @@ + + @Nullable + public Entity changeDimension(ServerLevel destination) { ++ // CraftBukkit start ++ return teleportTo(destination, null); ++ } ++ ++ @Nullable ++ public Entity teleportTo(ServerLevel worldserver, Vec3 location) { ++ // CraftBukkit end + if (this.level() instanceof ServerLevel && !this.isRemoved()) { + this.level().getProfiler().push("changeDimension"); +- this.unRide(); ++ // CraftBukkit start ++ // this.unRide(); ++ if (worldserver == null) { ++ return null; ++ } ++ // CraftBukkit end + this.level().getProfiler().push("reposition"); +- PortalInfo portalInfo = this.findDimensionEntryPoint(destination); +- if (portalInfo == null) { ++ PortalInfo shapedetectorshape = (location == null) ? this.findDimensionEntryPoint(worldserver) : new PortalInfo(new Vec3(location.x(), location.y(), location.z()), Vec3.ZERO, this.yRot, this.xRot, worldserver, null); // CraftBukkit ++ ++ if (shapedetectorshape == null) { + return null; + } else { ++ // CraftBukkit start ++ worldserver = shapedetectorshape.world; ++ if (worldserver == level) { ++ // SPIGOT-6782: Just move the entity if a plugin changed the world to the one the entity is already in ++ moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, shapedetectorshape.xRot); ++ setDeltaMovement(shapedetectorshape.speed); ++ return this; ++ } ++ this.unRide(); ++ // CraftBukkit end ++ + this.level().getProfiler().popPush("reloading"); + Entity entity = this.getType().create(destination); + if (entity != null) { + entity.restoreFrom(this); +- entity.moveTo(portalInfo.pos.x, portalInfo.pos.y, portalInfo.pos.z, portalInfo.yRot, entity.getXRot()); +- entity.setDeltaMovement(portalInfo.speed); +- destination.addDuringTeleport(entity); +- if (destination.dimension() == Level.END) { +- ServerLevel.makeObsidianPlatform(destination); ++ entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot()); ++ entity.setDeltaMovement(shapedetectorshape.speed); ++ // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned ++ if (this.inWorld) { ++ worldserver.addDuringTeleport(entity); ++ if (worldserver.getTypeKey() == LevelStem.END) { // CraftBukkit ++ ServerLevel.makeObsidianPlatform(worldserver, this); // CraftBukkit ++ } + } ++ // CraftBukkit end ++ // CraftBukkit start - Forward the CraftEntity to the new entity ++ this.getBukkitEntity().setHandle(entity); ++ entity.bukkitEntity = this.getBukkitEntity(); ++ ++ if (this instanceof Mob) { ++ ((Mob) this).dropLeash(true, false); // Unleash to prevent duping of leads. ++ } ++ // CraftBukkit end + } + + this.removeAfterChangingDimensions(); +@@ -2527,39 +3071,52 @@ + + @Nullable + protected PortalInfo findDimensionEntryPoint(ServerLevel destination) { +- boolean flag = this.level().dimension() == Level.END && destination.dimension() == Level.OVERWORLD; +- boolean flag1 = destination.dimension() == Level.END; ++ // CraftBukkit start ++ if (destination == null) { ++ return null; ++ } ++ boolean flag = this.level().getTypeKey() == LevelStem.END && destination.getTypeKey() == LevelStem.OVERWORLD; // fromEndToOverworld ++ boolean flag1 = destination.getTypeKey() == LevelStem.END; // targetIsEnd ++ // CraftBukkit end ++ + if (!flag && !flag1) { +- boolean flag2 = destination.dimension() == Level.NETHER; +- if (this.level().dimension() != Level.NETHER && !flag2) { ++ boolean flag2 = destination.getTypeKey() == LevelStem.NETHER; // CraftBukkit ++ ++ if (this.level().getTypeKey() != LevelStem.NETHER && !flag2) { // CraftBukkit + return null; + } else { +- WorldBorder worldBorder = destination.getWorldBorder(); +- double teleportationScale = DimensionType.getTeleportationScale(this.level().dimensionType(), destination.dimensionType()); +- BlockPos blockPos1 = worldBorder.clampToBounds(this.getX() * teleportationScale, this.getY(), this.getZ() * teleportationScale); +- return this.getExitPortal(destination, blockPos1, flag2, worldBorder) +- .map( +- foundRectangle -> { +- BlockState blockState = this.level().getBlockState(this.portalEntrancePos); +- Direction.Axis axis; +- Vec3 relativePortalPosition; +- if (blockState.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) { +- axis = blockState.getValue(BlockStateProperties.HORIZONTAL_AXIS); +- BlockUtil.FoundRectangle largestRectangleAround = BlockUtil.getLargestRectangleAround( +- this.portalEntrancePos, axis, 21, Direction.Axis.Y, 21, blockPos2 -> this.level().getBlockState(blockPos2) == blockState +- ); +- relativePortalPosition = this.getRelativePortalPosition(axis, largestRectangleAround); +- } else { +- axis = Direction.Axis.X; +- relativePortalPosition = new Vec3(0.5, 0.0, 0.0); +- } +- +- return PortalShape.createPortalInfo( +- destination, foundRectangle, axis, relativePortalPosition, this, this.getDeltaMovement(), this.getYRot(), this.getXRot() +- ); +- } +- ) +- .orElse(null); ++ WorldBorder worldborder = destination.getWorldBorder(); ++ double d0 = DimensionType.getTeleportationScale(this.level().dimensionType(), destination.dimensionType()); ++ BlockPos blockposition = worldborder.clampToBounds(this.getX() * d0, this.getY(), this.getZ() * d0); ++ // CraftBukkit start ++ CraftPortalEvent event = callPortalEvent(this, destination, new Vec3(blockposition.getX(), blockposition.getY(), blockposition.getZ()), PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag2 ? 16 : 128, 16); ++ if (event == null) { ++ return null; ++ } ++ final ServerLevel worldserverFinal = destination = ((CraftWorld) event.getTo().getWorld()).getHandle(); ++ worldborder = worldserverFinal.getWorldBorder(); ++ blockposition = worldborder.clampToBounds(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); ++ ++ return (PortalInfo) this.getExitPortal(destination, blockposition, flag2, worldborder, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((blockutil_rectangle) -> { ++ // CraftBukkit end ++ IBlockData iblockdata = this.level().getBlockState(this.portalEntrancePos); ++ Direction.Axis enumdirection_enumaxis; ++ Vec3 vec3d; ++ ++ if (iblockdata.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) { ++ enumdirection_enumaxis = (Direction.Axis) iblockdata.getValue(BlockStateProperties.HORIZONTAL_AXIS); ++ BlockUtil.FoundRectangle blockutil_rectangle1 = BlockUtil.getLargestRectangleAround(this.portalEntrancePos, enumdirection_enumaxis, 21, Direction.Axis.Y, 21, (blockposition1) -> { ++ return this.level().getBlockState(blockposition1) == iblockdata; ++ }); ++ ++ vec3d = this.getRelativePortalPosition(enumdirection_enumaxis, blockutil_rectangle1); ++ } else { ++ enumdirection_enumaxis = Direction.Axis.X; ++ vec3d = new Vec3(0.5D, 0.0D, 0.0D); ++ } ++ ++ return PortalShape.createPortalInfo(worldserverFinal, blockutil_rectangle, enumdirection_enumaxis, vec3d, this, this.getDeltaMovement(), this.getYRot(), this.getXRot(), event); // CraftBukkit ++ }).orElse(null); // CraftBukkit - decompile error + } + } else { + BlockPos blockPos; +@@ -2568,13 +3126,14 @@ + } else { + blockPos = destination.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, destination.getSharedSpawnPos()); + } ++ // CraftBukkit start ++ CraftPortalEvent event = callPortalEvent(this, destination, new Vec3(blockposition1.getX() + 0.5D, blockposition1.getY(), blockposition1.getZ() + 0.5D), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); ++ if (event == null) { ++ return null; ++ } + +- return new PortalInfo( +- new Vec3((double)blockPos.getX() + 0.5, (double)blockPos.getY(), (double)blockPos.getZ() + 0.5), +- this.getDeltaMovement(), +- this.getYRot(), +- this.getXRot() +- ); ++ return new PortalInfo(new Vec3(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event); ++ // CraftBukkit end + } + } + +@@ -2582,10 +3141,25 @@ + return PortalShape.getRelativePosition(portal, axis, this.position(), this.getDimensions(this.getPose())); + } + +- protected Optional<BlockUtil.FoundRectangle> getExitPortal(ServerLevel destination, BlockPos findFrom, boolean isToNether, WorldBorder worldBorder) { +- return destination.getPortalForcer().findPortalAround(findFrom, isToNether, worldBorder); ++ // CraftBukkit start ++ protected CraftPortalEvent callPortalEvent(Entity entity, ServerLevel exitWorldServer, Vec3 exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { ++ org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity(); ++ Location enter = bukkitEntity.getLocation(); ++ Location exit = CraftLocation.toBukkit(exitPosition, exitWorldServer.getWorld()); ++ ++ EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius); ++ event.getEntity().getServer().getPluginManager().callEvent(event); ++ if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !entity.isAlive()) { ++ return null; ++ } ++ return new CraftPortalEvent(event); + } + ++ protected Optional<BlockUtil.FoundRectangle> getExitPortal(ServerLevel worldserver, BlockPos blockposition, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) { ++ return worldserver.getPortalForcer().findPortalAround(blockposition, worldborder, searchRadius); ++ // CraftBukkit end ++ } ++ + public boolean canChangeDimensions() { + return !this.isPassenger() && !this.isVehicle(); + } +@@ -2695,8 +3278,15 @@ + } + } + +- public boolean teleportTo(ServerLevel level, double x, double y, double z, Set<RelativeMovement> relativeMovements, float yRot, float xRot) { +- float f = Mth.clamp(xRot, -90.0F, 90.0F); ++ // CraftBukkit start ++ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { ++ return this.teleportTo(worldserver, d0, d1, d2, set, f, f1); ++ } ++ // CraftBukkit end ++ ++ public boolean teleportTo(ServerLevel level, double x, double d1, double y, Set<RelativeMovement> set, float z, float f1) { ++ float f2 = Mth.clamp(f1, -90.0F, 90.0F); ++ + if (level == this.level()) { + this.moveTo(x, y, z, yRot, f); + this.teleportPassengers(); +@@ -2712,7 +3303,11 @@ + entity.moveTo(x, y, z, yRot, f); + entity.setYHeadRot(yRot); + this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); +- level.addDuringTeleport(entity); ++ // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned ++ if (inWorld) { ++ level.addDuringTeleport(entity); ++ } ++ // CraftBukkit end + } + + return true; +@@ -2812,7 +3413,26 @@ + } + + public final void setBoundingBox(AABB bb) { +- this.bb = bb; ++ // CraftBukkit start - block invalid bounding boxes ++ double minX = bb.minX, ++ minY = bb.minY, ++ minZ = bb.minZ, ++ maxX = bb.maxX, ++ maxY = bb.maxY, ++ maxZ = bb.maxZ; ++ double len = bb.maxX - bb.minX; ++ if (len < 0) maxX = minX; ++ if (len > 64) maxX = minX + 64.0; ++ ++ len = bb.maxY - bb.minY; ++ if (len < 0) maxY = minY; ++ if (len > 64) maxY = minY + 64.0; ++ ++ len = bb.maxZ - bb.minZ; ++ if (len < 0) maxZ = minZ; ++ if (len > 64) maxZ = minZ + 64.0; ++ this.bb = new AABB(minX, minY, minZ, maxX, maxY, maxZ); ++ // CraftBukkit end + } + + protected float getEyeHeight(Pose pose, EntityDimensions dimensions) { +@@ -3114,6 +3747,11 @@ + vec3 = vec3.add(flow); + i++; + } ++ // CraftBukkit start - store last lava contact location ++ if (fluidTag == FluidTags.LAVA) { ++ this.lastLavaContact = blockposition_mutableblockposition.immutable(); ++ } ++ // CraftBukkit end + } + } + } |