mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-02 21:41:41 +01:00
Avoid stream for placement collision
This commit is contained in:
parent
baca58daa6
commit
db2d00819c
@ -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,33 +330,27 @@ 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();
|
||||||
|
if (type == EntityType.ITEM)
|
||||||
|
continue;
|
||||||
|
// Marker Armor Stands should not prevent block placement
|
||||||
|
if (entity.getEntityMeta() instanceof ArmorStandMeta armorStandMeta && armorStandMeta.isMarker())
|
||||||
|
continue;
|
||||||
|
|
||||||
return entities
|
final boolean intersects;
|
||||||
.stream()
|
if (type == EntityType.PLAYER) {
|
||||||
.filter(entity -> entity.getEntityType() != EntityType.ITEM)
|
// Need to move player slightly away from block we're placing.
|
||||||
.filter(entity -> {
|
// 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]
|
||||||
// Marker Armor Stands should not prevent block placement
|
// For this reason we subtract a small amount from the player position
|
||||||
if (entity.getEntityMeta() instanceof ArmorStandMeta armorStandMeta) {
|
Point playerPos = entity.getPosition().add(entity.getPosition().sub(blockPos).mul(0.01));
|
||||||
return !armorStandMeta.isMarker();
|
intersects = b.registry().collisionShape().intersectBox(playerPos.sub(blockPos), entity.getBoundingBox());
|
||||||
}
|
} else {
|
||||||
return true;
|
intersects = b.registry().collisionShape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox());
|
||||||
})
|
}
|
||||||
.noneMatch(entity -> {
|
if (intersects) return false;
|
||||||
boolean intersects;
|
}
|
||||||
|
return true;
|
||||||
if (entity.getEntityType() == EntityType.PLAYER) {
|
|
||||||
// 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]
|
|
||||||
// For this reason we subtract a small amount from the player position
|
|
||||||
Point playerPos = entity.getPosition().add(entity.getPosition().sub(blockPos).mul(0.01));
|
|
||||||
intersects = b.registry().collisionShape().intersectBox(playerPos.sub(blockPos), entity.getBoundingBox());
|
|
||||||
} else {
|
|
||||||
intersects = b.registry().collisionShape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox());
|
|
||||||
}
|
|
||||||
|
|
||||||
return intersects;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user