#855: Add Block#getCollisionShape and associated API

By: konsolas <vincentyntang@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2021-06-14 08:33:32 +10:00
parent 55abb0fd8c
commit 9a2165ab37
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package org.bukkit.craftbukkit.util;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.bukkit.util.BoundingBox;
public final class CraftVoxelShape implements org.bukkit.util.VoxelShape {
private final VoxelShape shape;
public CraftVoxelShape(VoxelShape shape) {
this.shape = shape;
}
@Override
public Collection<BoundingBox> getBoundingBoxes() {
List<AxisAlignedBB> boxes = shape.d(); // PAIL rename toList
List<BoundingBox> craftBoxes = new ArrayList<>(boxes.size());
for (AxisAlignedBB aabb : boxes) {
craftBoxes.add(new BoundingBox(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ));
}
return craftBoxes;
}
@Override
public boolean overlaps(BoundingBox other) {
Preconditions.checkArgument(other != null, "Other cannot be null");
for (BoundingBox box : getBoundingBoxes()) {
if (box.overlaps(other)) {
return true;
}
}
return false;
}
}