Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/** Default implementation of IBoundingBox, do not use directly! */
public class DefaultBoundingBox implements IBoundingBox {
protected final AxisAlignedBB internal;
public final AxisAlignedBB internal;
private Vec3d minCached;
private Vec3d maxCached;

Expand Down
31 changes: 29 additions & 2 deletions src/main/java/cam72cam/mod/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cam72cam.mod.block.tile.TileEntity;
import cam72cam.mod.entity.*;
import cam72cam.mod.entity.boundingbox.BoundingBox;
import cam72cam.mod.entity.boundingbox.DefaultBoundingBox;
import cam72cam.mod.entity.boundingbox.IBoundingBox;
import cam72cam.mod.event.ClientEvents;
import cam72cam.mod.event.CommonEvents;
Expand All @@ -27,11 +28,9 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.IPlantable;
Expand Down Expand Up @@ -274,6 +273,34 @@ public <T extends Entity> List<T> getEntities(Predicate<T> filter, Class<T> type
return list;
}

/**
* Find UMC Entities which within the BB and are of the given type
* <p>
* More performant when region is known
* */
public <T extends Entity> List<T> getEntitiesWithinBB(IBoundingBox bb, Class<T> type) {
return getEntitiesWithinBB(bb, (T val) -> true, type);
}

/**
* Find UMC Entities which within the BB, match the filter and are of the given type
* <p>
* More performant when region is known
* */
public <T extends Entity> List<T> getEntitiesWithinBB(IBoundingBox bb , Predicate<T> filter, Class<T> type) {
List<net.minecraft.entity.Entity> entitiesWithinAABB = internal.getEntitiesWithinAABB(net.minecraft.entity.Entity.class,
bb instanceof DefaultBoundingBox
? ((DefaultBoundingBox)bb).internal
: new AxisAlignedBB(bb.min().internal(), bb.max().internal()));

return entitiesWithinAABB.stream()
.map(this::getEntity)
.filter(type::isInstance)
.map(type::cast)
.filter(filter)
.collect(Collectors.toList());
}

/** Add a constructed entity to the world */
public boolean spawnEntity(Entity ent) {
return internal.spawnEntity(ent.internal);
Expand Down