--- a/net/minecraft/world/entity/EntitySelector.java
+++ b/net/minecraft/world/entity/EntitySelector.java
@@ -6,75 +6,120 @@
 import net.minecraft.world.Container;
 import net.minecraft.world.entity.player.Player;
 import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.scores.PlayerTeam;
 import net.minecraft.world.scores.Team;
 
 public final class EntitySelector {
+
     public static final Predicate<Entity> ENTITY_STILL_ALIVE = Entity::isAlive;
-    public static final Predicate<Entity> LIVING_ENTITY_STILL_ALIVE = entity -> entity.isAlive() && entity instanceof LivingEntity;
-    public static final Predicate<Entity> ENTITY_NOT_BEING_RIDDEN = entity -> entity.isAlive() && !entity.isVehicle() && !entity.isPassenger();
-    public static final Predicate<Entity> CONTAINER_ENTITY_SELECTOR = entity -> entity instanceof Container && entity.isAlive();
-    public static final Predicate<Entity> NO_CREATIVE_OR_SPECTATOR = entity -> !(entity instanceof Player)
-            || !entity.isSpectator() && !((Player)entity).isCreative();
-    public static final Predicate<Entity> NO_SPECTATORS = entity -> !entity.isSpectator();
-    public static final Predicate<Entity> CAN_BE_COLLIDED_WITH = NO_SPECTATORS.and(Entity::canBeCollidedWith);
+    public static final Predicate<Entity> LIVING_ENTITY_STILL_ALIVE = (entity) -> {
+        return entity.isAlive() && entity instanceof LivingEntity;
+    };
+    public static final Predicate<Entity> ENTITY_NOT_BEING_RIDDEN = (entity) -> {
+        return entity.isAlive() && !entity.isVehicle() && !entity.isPassenger();
+    };
+    public static final Predicate<Entity> CONTAINER_ENTITY_SELECTOR = (entity) -> {
+        return entity instanceof Container && entity.isAlive();
+    };
+    public static final Predicate<Entity> NO_CREATIVE_OR_SPECTATOR = (entity) -> {
+        return !(entity instanceof Player) || !entity.isSpectator() && !((Player) entity).isCreative();
+    };
+    public static final Predicate<Entity> NO_SPECTATORS = (entity) -> {
+        return !entity.isSpectator();
+    };
+    public static final Predicate<Entity> CAN_BE_COLLIDED_WITH = EntitySelector.NO_SPECTATORS.and(Entity::canBeCollidedWith);
+    // Paper start - Ability to control player's insomnia and phantoms
+    public static Predicate<Player> IS_INSOMNIAC = (player) -> {
+        net.minecraft.server.level.ServerPlayer serverPlayer = (net.minecraft.server.level.ServerPlayer) player;
+        int playerInsomniaTicks = serverPlayer.level().paperConfig().entities.behavior.playerInsomniaStartTicks;
 
-    private EntitySelector() {
-    }
+        if (playerInsomniaTicks <= 0) {
+            return false;
+        }
+
+        return net.minecraft.util.Mth.clamp(serverPlayer.getStats().getValue(net.minecraft.stats.Stats.CUSTOM.get(net.minecraft.stats.Stats.TIME_SINCE_REST)), 1, Integer.MAX_VALUE) >= playerInsomniaTicks;
+    };
+    // Paper end - Ability to control player's insomnia and phantoms
+
+    private EntitySelector() {}
+    // Paper start - Affects Spawning API
+    public static final Predicate<Entity> PLAYER_AFFECTS_SPAWNING = (entity) -> {
+        return !entity.isSpectator() && entity.isAlive() && entity instanceof Player player && player.affectsSpawning;
+    };
+    // Paper end - Affects Spawning API
 
     public static Predicate<Entity> withinDistance(double x, double y, double z, double max) {
-        double d = max * max;
-        return entity -> entity != null && entity.distanceToSqr(x, y, z) <= d;
+        double d4 = max * max;
+
+        return (entity) -> {
+            return entity != null && entity.distanceToSqr(x, y, z) <= d4;
+        };
     }
 
     public static Predicate<Entity> pushableBy(Entity entity) {
-        Team team = entity.getTeam();
-        Team.CollisionRule collisionRule = team == null ? Team.CollisionRule.ALWAYS : team.getCollisionRule();
-        return (Predicate<Entity>)(collisionRule == Team.CollisionRule.NEVER
-            ? Predicates.alwaysFalse()
-            : NO_SPECTATORS.and(
-                entityxx -> {
-                    if (!entityxx.isPushable()) {
-                        return false;
-                    } else if (!entity.level().isClientSide || entityxx instanceof Player && ((Player)entityxx).isLocalPlayer()) {
-                        Team team2 = entityxx.getTeam();
-                        Team.CollisionRule collisionRule2 = team2 == null ? Team.CollisionRule.ALWAYS : team2.getCollisionRule();
-                        if (collisionRule2 == Team.CollisionRule.NEVER) {
-                            return false;
-                        } else {
-                            boolean bl = team != null && team.isAlliedTo(team2);
-                            return (collisionRule != Team.CollisionRule.PUSH_OWN_TEAM && collisionRule2 != Team.CollisionRule.PUSH_OWN_TEAM || !bl)
-                                && (collisionRule != Team.CollisionRule.PUSH_OTHER_TEAMS && collisionRule2 != Team.CollisionRule.PUSH_OTHER_TEAMS || bl);
-                        }
-                    } else {
-                        return false;
-                    }
+        // Paper start - Climbing should not bypass cramming gamerule
+        return pushable(entity, false);
+    }
+    public static Predicate<Entity> pushable(Entity entity, boolean ignoreClimbing) {
+        // Paper end - Climbing should not bypass cramming gamerule
+        PlayerTeam scoreboardteam = entity.getTeam();
+        Team.CollisionRule scoreboardteambase_enumteampush = scoreboardteam == null ? Team.CollisionRule.ALWAYS : scoreboardteam.getCollisionRule();
+
+        return (Predicate) (scoreboardteambase_enumteampush == Team.CollisionRule.NEVER ? Predicates.alwaysFalse() : EntitySelector.NO_SPECTATORS.and((entity1) -> {
+            if (!entity1.isCollidable(ignoreClimbing) || !entity1.canCollideWithBukkit(entity) || !entity.canCollideWithBukkit(entity1)) { // CraftBukkit - collidable API // Paper - Climbing should not bypass cramming gamerule
+                return false;
+            } else if (entity.level().isClientSide && (!(entity1 instanceof Player) || !((Player) entity1).isLocalPlayer())) {
+                return false;
+            } else {
+                PlayerTeam scoreboardteam1 = entity1.getTeam();
+                Team.CollisionRule scoreboardteambase_enumteampush1 = scoreboardteam1 == null ? Team.CollisionRule.ALWAYS : scoreboardteam1.getCollisionRule();
+
+                if (scoreboardteambase_enumteampush1 == Team.CollisionRule.NEVER) {
+                    return false;
+                } else {
+                    boolean flag = scoreboardteam != null && scoreboardteam.isAlliedTo(scoreboardteam1);
+
+                    return (scoreboardteambase_enumteampush == Team.CollisionRule.PUSH_OWN_TEAM || scoreboardteambase_enumteampush1 == Team.CollisionRule.PUSH_OWN_TEAM) && flag ? false : scoreboardteambase_enumteampush != Team.CollisionRule.PUSH_OTHER_TEAMS && scoreboardteambase_enumteampush1 != Team.CollisionRule.PUSH_OTHER_TEAMS || flag;
                 }
-            ));
+            }
+        }));
     }
 
     public static Predicate<Entity> notRiding(Entity entity) {
-        return testedEntity -> {
-            while (testedEntity.isPassenger()) {
-                testedEntity = testedEntity.getVehicle();
-                if (testedEntity == entity) {
+        return (entity1) -> {
+            while (true) {
+                if (entity1.isPassenger()) {
+                    entity1 = entity1.getVehicle();
+                    if (entity1 != entity) {
+                        continue;
+                    }
+
                     return false;
                 }
-            }
 
-            return true;
+                return true;
+            }
         };
     }
 
     public static class MobCanWearArmorEntitySelector implements Predicate<Entity> {
+
         private final ItemStack itemStack;
 
         public MobCanWearArmorEntitySelector(ItemStack stack) {
             this.itemStack = stack;
         }
 
-        @Override
         public boolean test(@Nullable Entity entity) {
-            return entity.isAlive() && entity instanceof LivingEntity livingEntity && livingEntity.canTakeItem(this.itemStack);
+            if (!entity.isAlive()) {
+                return false;
+            } else if (!(entity instanceof LivingEntity)) {
+                return false;
+            } else {
+                LivingEntity entityliving = (LivingEntity) entity;
+
+                return entityliving.canTakeItem(this.itemStack);
+            }
         }
     }
 }
