Skip to content

Commit

Permalink
No more taking enemies into soulhomes. Better selective entities allo…
Browse files Browse the repository at this point in the history
…wed to change dimensions.
  • Loading branch information
leafreynolds committed Jan 13, 2025
1 parent 366c796 commit ff0c810
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/leaf/soulhome/items/SoulKeyItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public void onUseTick(Level world, LivingEntity livingEntity, ItemStack stack, i

for (int i = particlesToCreate; i >= 0; --i)
{
float ang = (bits * i);// + (Math.random() * 10);
float ang = (bits * i);

livingEntity.level().addParticle(
ParticleTypes.POOF,
ParticleTypes.SOUL_FIRE_FLAME,
livingEntity.getX() + Mth.sin(Mth.wrapDegrees(ang)) * radius,
livingEntity.getY(),
livingEntity.getZ() + Mth.cos(Mth.wrapDegrees(ang)) * radius,
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/leaf/soulhome/utils/EntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
package leaf.soulhome.utils;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.phys.AABB;

import java.util.List;
import java.util.function.Predicate;

public class EntityHelper
{
Expand All @@ -29,16 +32,27 @@ public static List<LivingEntity> getLivingEntitiesInRange(LivingEntity selfEntit
return entitiesFound;
}

private static final Predicate<Entity> ALLOWED_TO_TELEPORT =
EntitySelector.NO_SPECTATORS
.and(EntitySelector.LIVING_ENTITY_STILL_ALIVE)
.and(Entity::canChangeDimensions)
.and((entity)->!(entity instanceof Enemy));

public static List<Entity> getEntitiesInRange(Entity entity, double range, boolean includeSelf)
{
AABB areaOfEffect = new AABB(entity.blockPosition());
areaOfEffect = areaOfEffect.inflate(range, range, range);

List<Entity> entitiesFound = entity.level().getEntitiesOfClass(Entity.class, areaOfEffect);

if (!includeSelf)
for (Entity ent : entitiesFound)
{
entitiesFound.remove(entity);
final boolean removeSelf = ent == entity && !includeSelf;
if (removeSelf || !ALLOWED_TO_TELEPORT.test(ent))
{
entitiesFound.remove(ent);
break;
}
}

return entitiesFound;
Expand Down

0 comments on commit ff0c810

Please sign in to comment.