mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-24 18:18:41 +01:00
Cache shapes size
This commit is contained in:
parent
11708a1c1a
commit
60f583b179
@ -14,11 +14,29 @@ import java.util.regex.Pattern;
|
||||
final class ShapeImpl implements Shape {
|
||||
private static final Pattern PATTERN = Pattern.compile("\\d.\\d{1,3}", Pattern.MULTILINE);
|
||||
private final BoundingBox[] blockSections;
|
||||
private final Point relativeStart, relativeEnd;
|
||||
private final Supplier<Material> block;
|
||||
|
||||
private ShapeImpl(BoundingBox[] boundingBoxes, Supplier<Material> block) {
|
||||
this.blockSections = boundingBoxes;
|
||||
this.block = block;
|
||||
// Find bounds
|
||||
{
|
||||
double minX = 1, minY = 1, minZ = 1;
|
||||
double maxX = 1, maxY = 1, maxZ = 1;
|
||||
for (BoundingBox blockSection : blockSections) {
|
||||
// Min
|
||||
if (blockSection.minX() < minX) minX = blockSection.minX();
|
||||
if (blockSection.minY() < minY) minY = blockSection.minY();
|
||||
if (blockSection.minZ() < minZ) minZ = blockSection.minZ();
|
||||
// Max
|
||||
if (blockSection.maxX() < maxX) maxX = blockSection.maxX();
|
||||
if (blockSection.maxY() < maxY) maxY = blockSection.maxY();
|
||||
if (blockSection.maxZ() < maxZ) maxZ = blockSection.maxZ();
|
||||
}
|
||||
this.relativeStart = new Vec(minX, minY, minZ);
|
||||
this.relativeEnd = new Vec(maxX, maxY, maxZ);
|
||||
}
|
||||
}
|
||||
|
||||
static ShapeImpl parseBlockFromRegistry(String str, Supplier<Material> block) {
|
||||
@ -51,24 +69,12 @@ final class ShapeImpl implements Shape {
|
||||
|
||||
@Override
|
||||
public @NotNull Point relativeStart() {
|
||||
double minX = 1, minY = 1, minZ = 1;
|
||||
for (BoundingBox blockSection : blockSections) {
|
||||
if (blockSection.minX() < minX) minX = blockSection.minX();
|
||||
if (blockSection.minY() < minY) minY = blockSection.minY();
|
||||
if (blockSection.minZ() < minZ) minZ = blockSection.minZ();
|
||||
}
|
||||
return new Vec(minX, minY, minZ);
|
||||
return relativeStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Point relativeEnd() {
|
||||
double maxX = 1, maxY = 1, maxZ = 1;
|
||||
for (BoundingBox blockSection : blockSections) {
|
||||
if (blockSection.maxX() < maxX) maxX = blockSection.maxX();
|
||||
if (blockSection.maxY() < maxY) maxY = blockSection.maxY();
|
||||
if (blockSection.maxZ() < maxZ) maxZ = blockSection.maxZ();
|
||||
}
|
||||
return new Vec(maxX, maxY, maxZ);
|
||||
return relativeEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user