Skip to content

Commit

Permalink
feat(utils): entity predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Apr 10, 2022
1 parent 4f85654 commit 7cef1db
Showing 1 changed file with 41 additions and 0 deletions.
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
Expand All @@ -17,6 +19,9 @@

public interface EntityUtils {

/*================================================================================================================*/
// #region RayTrace

static Vec3[] getEntityViewRay(Entity entity, double rayLength) {
Vec3 entityViewVector = entity.getViewVector(1.0F);
Vec3 rayPath = entityViewVector.scale(rayLength);
Expand Down Expand Up @@ -126,4 +131,40 @@ static int rayHitLivingEntityOrBlock(Entity entity, double rayLength, Function<E
);
}

// #endregion RayTrace

/*================================================================================================================*/
// #region Predicates

Predicate<Entity> IS_LIVING = (entity) -> entity instanceof LivingEntity;
Predicate<Entity> IS_PLAYER = (entity) -> entity instanceof net.minecraft.world.entity.player.Player;
Predicate<Entity> IS_LOCAL_PLAYER = (entity) -> entity instanceof net.minecraft.client.player.LocalPlayer;
Predicate<Entity> IS_SERVER_PLAYER = (entity) -> entity instanceof net.minecraft.server.level.ServerPlayer;
Predicate<Entity> IS_FAKE_PLAYER = (entity) -> entity instanceof net.minecraftforge.common.util.FakePlayer;
Predicate<Entity> IS_PROJECTILE = (entity) -> entity instanceof net.minecraft.world.entity.projectile.Projectile;

static MobCategory getCategory(Entity entity) {
return entity.getType().getCategory();
}

Predicate<Entity> IS_FRIENDLY = (entity) -> getCategory(entity).isFriendly();
Predicate<Entity> IS_PERSISTENT = (entity) -> getCategory(entity).isPersistent();
Predicate<Entity> IS_MISC = (entity) -> getCategory(entity) == MobCategory.MISC;
Predicate<Entity> IS_MONSTER = (entity) -> getCategory(entity) == MobCategory.MONSTER;
Predicate<Entity> IS_CREATURE = (entity) -> getCategory(entity) == MobCategory.CREATURE;
Predicate<Entity> IS_AMBIENT = (entity) -> getCategory(entity) == MobCategory.AMBIENT;
Predicate<Entity> IS_AXOLOTLS = (entity) -> getCategory(entity) == MobCategory.AXOLOTLS;
Predicate<Entity> IS_UNDERGROUND_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.UNDERGROUND_WATER_CREATURE;
Predicate<Entity> IS_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.WATER_CREATURE;
Predicate<Entity> IS_WATER_AMBIENT = (entity) -> getCategory(entity) == MobCategory.WATER_AMBIENT;

Predicate<LivingEntity> IS_UNDEFINED = (living) -> living.getMobType() == MobType.UNDEFINED;
Predicate<LivingEntity> IS_DEFINED = (living) -> living.getMobType() != MobType.UNDEFINED;
Predicate<LivingEntity> IS_UNDEAD = (living) -> living.getMobType() == MobType.UNDEAD;
Predicate<LivingEntity> IS_ARTHROPOD = (living) -> living.getMobType() == MobType.ARTHROPOD;
Predicate<LivingEntity> IS_ILLAGER = (living) -> living.getMobType() == MobType.ILLAGER;
Predicate<LivingEntity> IS_WATER = (living) -> living.getMobType() == MobType.WATER;

// #endregion Predicates

}

0 comments on commit 7cef1db

Please sign in to comment.