#855: Add Block#getCollisionShape and associated API
This commit is contained in:
parent
e7c6472526
commit
ea1a84338c
@ -50,6 +50,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|||||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
|
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftVoxelShape;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -746,4 +747,10 @@ public class CraftBlock implements Block {
|
|||||||
AxisAlignedBB aabb = shape.getBoundingBox();
|
AxisAlignedBB aabb = shape.getBoundingBox();
|
||||||
return new BoundingBox(getX() + aabb.minX, getY() + aabb.minY, getZ() + aabb.minZ, getX() + aabb.maxX, getY() + aabb.maxY, getZ() + aabb.maxZ);
|
return new BoundingBox(getX() + aabb.minX, getY() + aabb.minY, getZ() + aabb.minZ, getX() + aabb.maxX, getY() + aabb.maxY, getZ() + aabb.maxZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bukkit.util.VoxelShape getCollisionShape() {
|
||||||
|
VoxelShape shape = getNMS().getCollisionShape(world, position);
|
||||||
|
return new CraftVoxelShape(shape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user