Avoid stream for placement collision

This commit is contained in:
themode 2022-03-14 22:30:08 +01:00
parent baca58daa6
commit db2d00819c

View File

@ -11,8 +11,6 @@ import net.minestom.server.instance.block.Block;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection;
final class BlockCollision { final class BlockCollision {
// Minimum move amount, minimum final velocity // Minimum move amount, minimum final velocity
private static final double MIN_DELTA = 0.001; private static final double MIN_DELTA = 0.001;
@ -332,22 +330,16 @@ final class BlockCollision {
} }
static boolean canPlaceBlockAt(Instance instance, Point blockPos, Block b) { static boolean canPlaceBlockAt(Instance instance, Point blockPos, Block b) {
final Collection<Entity> entities = instance.getNearbyEntities(blockPos, 3); for (Entity entity : instance.getNearbyEntities(blockPos, 3)) {
final EntityType type = entity.getEntityType();
return entities if (type == EntityType.ITEM)
.stream() continue;
.filter(entity -> entity.getEntityType() != EntityType.ITEM)
.filter(entity -> {
// Marker Armor Stands should not prevent block placement // Marker Armor Stands should not prevent block placement
if (entity.getEntityMeta() instanceof ArmorStandMeta armorStandMeta) { if (entity.getEntityMeta() instanceof ArmorStandMeta armorStandMeta && armorStandMeta.isMarker())
return !armorStandMeta.isMarker(); continue;
}
return true;
})
.noneMatch(entity -> {
boolean intersects;
if (entity.getEntityType() == EntityType.PLAYER) { final boolean intersects;
if (type == EntityType.PLAYER) {
// Need to move player slightly away from block we're placing. // Need to move player slightly away from block we're placing.
// If player is at block 40 we cannot place a block at block 39 with side length 1 because the block will be in [39, 40] // If player is at block 40 we cannot place a block at block 39 with side length 1 because the block will be in [39, 40]
// For this reason we subtract a small amount from the player position // For this reason we subtract a small amount from the player position
@ -356,9 +348,9 @@ final class BlockCollision {
} else { } else {
intersects = b.registry().collisionShape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox()); intersects = b.registry().collisionShape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox());
} }
if (intersects) return false;
return intersects; }
}); return true;
} }
/** /**