From 7cef1db0b80348279097af25b09de16ebe029004 Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Sun, 10 Apr 2022 23:59:43 +0800 Subject: [PATCH] feat(utils): entity predicates --- .../arnicalib/utils/game/EntityUtils.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/EntityUtils.java b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/EntityUtils.java index 9626d5e5..371b59f8 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/EntityUtils.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/EntityUtils.java @@ -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; @@ -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); @@ -126,4 +131,40 @@ static int rayHitLivingEntityOrBlock(Entity entity, double rayLength, Function IS_LIVING = (entity) -> entity instanceof LivingEntity; + Predicate IS_PLAYER = (entity) -> entity instanceof net.minecraft.world.entity.player.Player; + Predicate IS_LOCAL_PLAYER = (entity) -> entity instanceof net.minecraft.client.player.LocalPlayer; + Predicate IS_SERVER_PLAYER = (entity) -> entity instanceof net.minecraft.server.level.ServerPlayer; + Predicate IS_FAKE_PLAYER = (entity) -> entity instanceof net.minecraftforge.common.util.FakePlayer; + Predicate IS_PROJECTILE = (entity) -> entity instanceof net.minecraft.world.entity.projectile.Projectile; + + static MobCategory getCategory(Entity entity) { + return entity.getType().getCategory(); + } + + Predicate IS_FRIENDLY = (entity) -> getCategory(entity).isFriendly(); + Predicate IS_PERSISTENT = (entity) -> getCategory(entity).isPersistent(); + Predicate IS_MISC = (entity) -> getCategory(entity) == MobCategory.MISC; + Predicate IS_MONSTER = (entity) -> getCategory(entity) == MobCategory.MONSTER; + Predicate IS_CREATURE = (entity) -> getCategory(entity) == MobCategory.CREATURE; + Predicate IS_AMBIENT = (entity) -> getCategory(entity) == MobCategory.AMBIENT; + Predicate IS_AXOLOTLS = (entity) -> getCategory(entity) == MobCategory.AXOLOTLS; + Predicate IS_UNDERGROUND_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.UNDERGROUND_WATER_CREATURE; + Predicate IS_WATER_CREATURE = (entity) -> getCategory(entity) == MobCategory.WATER_CREATURE; + Predicate IS_WATER_AMBIENT = (entity) -> getCategory(entity) == MobCategory.WATER_AMBIENT; + + Predicate IS_UNDEFINED = (living) -> living.getMobType() == MobType.UNDEFINED; + Predicate IS_DEFINED = (living) -> living.getMobType() != MobType.UNDEFINED; + Predicate IS_UNDEAD = (living) -> living.getMobType() == MobType.UNDEAD; + Predicate IS_ARTHROPOD = (living) -> living.getMobType() == MobType.ARTHROPOD; + Predicate IS_ILLAGER = (living) -> living.getMobType() == MobType.ILLAGER; + Predicate IS_WATER = (living) -> living.getMobType() == MobType.WATER; + + // #endregion Predicates + }