Spaces:
Build error
Build error
File size: 19,626 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
package net.minecraft.world.phys;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import org.joml.Vector3f;
public class AABB {
private static final double EPSILON = 1.0E-7;
public final double minX;
public final double minY;
public final double minZ;
public final double maxX;
public final double maxY;
public final double maxZ;
public AABB(double p_82295_, double p_82296_, double p_82297_, double p_82298_, double p_82299_, double p_82300_) {
this.minX = Math.min(p_82295_, p_82298_);
this.minY = Math.min(p_82296_, p_82299_);
this.minZ = Math.min(p_82297_, p_82300_);
this.maxX = Math.max(p_82295_, p_82298_);
this.maxY = Math.max(p_82296_, p_82299_);
this.maxZ = Math.max(p_82297_, p_82300_);
}
public AABB(BlockPos p_82305_) {
this(
(double)p_82305_.getX(),
(double)p_82305_.getY(),
(double)p_82305_.getZ(),
(double)(p_82305_.getX() + 1),
(double)(p_82305_.getY() + 1),
(double)(p_82305_.getZ() + 1)
);
}
public AABB(Vec3 p_82302_, Vec3 p_82303_) {
this(p_82302_.x, p_82302_.y, p_82302_.z, p_82303_.x, p_82303_.y, p_82303_.z);
}
public static AABB of(BoundingBox p_82322_) {
return new AABB(
(double)p_82322_.minX(),
(double)p_82322_.minY(),
(double)p_82322_.minZ(),
(double)(p_82322_.maxX() + 1),
(double)(p_82322_.maxY() + 1),
(double)(p_82322_.maxZ() + 1)
);
}
public static AABB unitCubeFromLowerCorner(Vec3 p_82334_) {
return new AABB(p_82334_.x, p_82334_.y, p_82334_.z, p_82334_.x + 1.0, p_82334_.y + 1.0, p_82334_.z + 1.0);
}
public static AABB encapsulatingFullBlocks(BlockPos p_310039_, BlockPos p_309686_) {
return new AABB(
(double)Math.min(p_310039_.getX(), p_309686_.getX()),
(double)Math.min(p_310039_.getY(), p_309686_.getY()),
(double)Math.min(p_310039_.getZ(), p_309686_.getZ()),
(double)(Math.max(p_310039_.getX(), p_309686_.getX()) + 1),
(double)(Math.max(p_310039_.getY(), p_309686_.getY()) + 1),
(double)(Math.max(p_310039_.getZ(), p_309686_.getZ()) + 1)
);
}
public AABB setMinX(double p_165881_) {
return new AABB(p_165881_, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
}
public AABB setMinY(double p_165888_) {
return new AABB(this.minX, p_165888_, this.minZ, this.maxX, this.maxY, this.maxZ);
}
public AABB setMinZ(double p_165890_) {
return new AABB(this.minX, this.minY, p_165890_, this.maxX, this.maxY, this.maxZ);
}
public AABB setMaxX(double p_165892_) {
return new AABB(this.minX, this.minY, this.minZ, p_165892_, this.maxY, this.maxZ);
}
public AABB setMaxY(double p_165894_) {
return new AABB(this.minX, this.minY, this.minZ, this.maxX, p_165894_, this.maxZ);
}
public AABB setMaxZ(double p_165896_) {
return new AABB(this.minX, this.minY, this.minZ, this.maxX, this.maxY, p_165896_);
}
public double min(Direction.Axis p_82341_) {
return p_82341_.choose(this.minX, this.minY, this.minZ);
}
public double max(Direction.Axis p_82375_) {
return p_82375_.choose(this.maxX, this.maxY, this.maxZ);
}
@Override
public boolean equals(Object p_82398_) {
if (this == p_82398_) {
return true;
} else if (!(p_82398_ instanceof AABB aabb)) {
return false;
} else if (Double.compare(aabb.minX, this.minX) != 0) {
return false;
} else if (Double.compare(aabb.minY, this.minY) != 0) {
return false;
} else if (Double.compare(aabb.minZ, this.minZ) != 0) {
return false;
} else if (Double.compare(aabb.maxX, this.maxX) != 0) {
return false;
} else {
return Double.compare(aabb.maxY, this.maxY) != 0 ? false : Double.compare(aabb.maxZ, this.maxZ) == 0;
}
}
@Override
public int hashCode() {
long i = Double.doubleToLongBits(this.minX);
int j = (int)(i ^ i >>> 32);
i = Double.doubleToLongBits(this.minY);
j = 31 * j + (int)(i ^ i >>> 32);
i = Double.doubleToLongBits(this.minZ);
j = 31 * j + (int)(i ^ i >>> 32);
i = Double.doubleToLongBits(this.maxX);
j = 31 * j + (int)(i ^ i >>> 32);
i = Double.doubleToLongBits(this.maxY);
j = 31 * j + (int)(i ^ i >>> 32);
i = Double.doubleToLongBits(this.maxZ);
return 31 * j + (int)(i ^ i >>> 32);
}
public AABB contract(double p_82311_, double p_82312_, double p_82313_) {
double d0 = this.minX;
double d1 = this.minY;
double d2 = this.minZ;
double d3 = this.maxX;
double d4 = this.maxY;
double d5 = this.maxZ;
if (p_82311_ < 0.0) {
d0 -= p_82311_;
} else if (p_82311_ > 0.0) {
d3 -= p_82311_;
}
if (p_82312_ < 0.0) {
d1 -= p_82312_;
} else if (p_82312_ > 0.0) {
d4 -= p_82312_;
}
if (p_82313_ < 0.0) {
d2 -= p_82313_;
} else if (p_82313_ > 0.0) {
d5 -= p_82313_;
}
return new AABB(d0, d1, d2, d3, d4, d5);
}
public AABB expandTowards(Vec3 p_82370_) {
return this.expandTowards(p_82370_.x, p_82370_.y, p_82370_.z);
}
public AABB expandTowards(double p_82364_, double p_82365_, double p_82366_) {
double d0 = this.minX;
double d1 = this.minY;
double d2 = this.minZ;
double d3 = this.maxX;
double d4 = this.maxY;
double d5 = this.maxZ;
if (p_82364_ < 0.0) {
d0 += p_82364_;
} else if (p_82364_ > 0.0) {
d3 += p_82364_;
}
if (p_82365_ < 0.0) {
d1 += p_82365_;
} else if (p_82365_ > 0.0) {
d4 += p_82365_;
}
if (p_82366_ < 0.0) {
d2 += p_82366_;
} else if (p_82366_ > 0.0) {
d5 += p_82366_;
}
return new AABB(d0, d1, d2, d3, d4, d5);
}
public AABB inflate(double p_82378_, double p_82379_, double p_82380_) {
double d0 = this.minX - p_82378_;
double d1 = this.minY - p_82379_;
double d2 = this.minZ - p_82380_;
double d3 = this.maxX + p_82378_;
double d4 = this.maxY + p_82379_;
double d5 = this.maxZ + p_82380_;
return new AABB(d0, d1, d2, d3, d4, d5);
}
public AABB inflate(double p_82401_) {
return this.inflate(p_82401_, p_82401_, p_82401_);
}
public AABB intersect(AABB p_82324_) {
double d0 = Math.max(this.minX, p_82324_.minX);
double d1 = Math.max(this.minY, p_82324_.minY);
double d2 = Math.max(this.minZ, p_82324_.minZ);
double d3 = Math.min(this.maxX, p_82324_.maxX);
double d4 = Math.min(this.maxY, p_82324_.maxY);
double d5 = Math.min(this.maxZ, p_82324_.maxZ);
return new AABB(d0, d1, d2, d3, d4, d5);
}
public AABB minmax(AABB p_82368_) {
double d0 = Math.min(this.minX, p_82368_.minX);
double d1 = Math.min(this.minY, p_82368_.minY);
double d2 = Math.min(this.minZ, p_82368_.minZ);
double d3 = Math.max(this.maxX, p_82368_.maxX);
double d4 = Math.max(this.maxY, p_82368_.maxY);
double d5 = Math.max(this.maxZ, p_82368_.maxZ);
return new AABB(d0, d1, d2, d3, d4, d5);
}
public AABB move(double p_82387_, double p_82388_, double p_82389_) {
return new AABB(
this.minX + p_82387_,
this.minY + p_82388_,
this.minZ + p_82389_,
this.maxX + p_82387_,
this.maxY + p_82388_,
this.maxZ + p_82389_
);
}
public AABB move(BlockPos p_82339_) {
return new AABB(
this.minX + (double)p_82339_.getX(),
this.minY + (double)p_82339_.getY(),
this.minZ + (double)p_82339_.getZ(),
this.maxX + (double)p_82339_.getX(),
this.maxY + (double)p_82339_.getY(),
this.maxZ + (double)p_82339_.getZ()
);
}
public AABB move(Vec3 p_82384_) {
return this.move(p_82384_.x, p_82384_.y, p_82384_.z);
}
public AABB move(Vector3f p_342207_) {
return this.move((double)p_342207_.x, (double)p_342207_.y, (double)p_342207_.z);
}
public boolean intersects(AABB p_82382_) {
return this.intersects(p_82382_.minX, p_82382_.minY, p_82382_.minZ, p_82382_.maxX, p_82382_.maxY, p_82382_.maxZ);
}
public boolean intersects(double p_82315_, double p_82316_, double p_82317_, double p_82318_, double p_82319_, double p_82320_) {
return this.minX < p_82318_
&& this.maxX > p_82315_
&& this.minY < p_82319_
&& this.maxY > p_82316_
&& this.minZ < p_82320_
&& this.maxZ > p_82317_;
}
public boolean intersects(Vec3 p_82336_, Vec3 p_82337_) {
return this.intersects(
Math.min(p_82336_.x, p_82337_.x),
Math.min(p_82336_.y, p_82337_.y),
Math.min(p_82336_.z, p_82337_.z),
Math.max(p_82336_.x, p_82337_.x),
Math.max(p_82336_.y, p_82337_.y),
Math.max(p_82336_.z, p_82337_.z)
);
}
public boolean contains(Vec3 p_82391_) {
return this.contains(p_82391_.x, p_82391_.y, p_82391_.z);
}
public boolean contains(double p_82394_, double p_82395_, double p_82396_) {
return p_82394_ >= this.minX
&& p_82394_ < this.maxX
&& p_82395_ >= this.minY
&& p_82395_ < this.maxY
&& p_82396_ >= this.minZ
&& p_82396_ < this.maxZ;
}
public double getSize() {
double d0 = this.getXsize();
double d1 = this.getYsize();
double d2 = this.getZsize();
return (d0 + d1 + d2) / 3.0;
}
public double getXsize() {
return this.maxX - this.minX;
}
public double getYsize() {
return this.maxY - this.minY;
}
public double getZsize() {
return this.maxZ - this.minZ;
}
public AABB deflate(double p_165898_, double p_165899_, double p_165900_) {
return this.inflate(-p_165898_, -p_165899_, -p_165900_);
}
public AABB deflate(double p_82407_) {
return this.inflate(-p_82407_);
}
public Optional<Vec3> clip(Vec3 p_82372_, Vec3 p_82373_) {
return clip(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ, p_82372_, p_82373_);
}
public static Optional<Vec3> clip(
double p_368264_, double p_369692_, double p_366920_, double p_361220_, double p_363635_, double p_362259_, Vec3 p_361125_, Vec3 p_369663_
) {
double[] adouble = new double[]{1.0};
double d0 = p_369663_.x - p_361125_.x;
double d1 = p_369663_.y - p_361125_.y;
double d2 = p_369663_.z - p_361125_.z;
Direction direction = getDirection(p_368264_, p_369692_, p_366920_, p_361220_, p_363635_, p_362259_, p_361125_, adouble, null, d0, d1, d2);
if (direction == null) {
return Optional.empty();
} else {
double d3 = adouble[0];
return Optional.of(p_361125_.add(d3 * d0, d3 * d1, d3 * d2));
}
}
@Nullable
public static BlockHitResult clip(Iterable<AABB> p_82343_, Vec3 p_82344_, Vec3 p_82345_, BlockPos p_82346_) {
double[] adouble = new double[]{1.0};
Direction direction = null;
double d0 = p_82345_.x - p_82344_.x;
double d1 = p_82345_.y - p_82344_.y;
double d2 = p_82345_.z - p_82344_.z;
for (AABB aabb : p_82343_) {
direction = getDirection(aabb.move(p_82346_), p_82344_, adouble, direction, d0, d1, d2);
}
if (direction == null) {
return null;
} else {
double d3 = adouble[0];
return new BlockHitResult(p_82344_.add(d3 * d0, d3 * d1, d3 * d2), direction, p_82346_, false);
}
}
@Nullable
private static Direction getDirection(
AABB p_82326_, Vec3 p_82327_, double[] p_82328_, @Nullable Direction p_82329_, double p_82330_, double p_82331_, double p_82332_
) {
return getDirection(
p_82326_.minX,
p_82326_.minY,
p_82326_.minZ,
p_82326_.maxX,
p_82326_.maxY,
p_82326_.maxZ,
p_82327_,
p_82328_,
p_82329_,
p_82330_,
p_82331_,
p_82332_
);
}
@Nullable
private static Direction getDirection(
double p_364616_,
double p_368982_,
double p_364885_,
double p_362338_,
double p_370222_,
double p_367138_,
Vec3 p_362780_,
double[] p_363085_,
@Nullable Direction p_366277_,
double p_361004_,
double p_368538_,
double p_364338_
) {
if (p_361004_ > 1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_361004_,
p_368538_,
p_364338_,
p_364616_,
p_368982_,
p_370222_,
p_364885_,
p_367138_,
Direction.WEST,
p_362780_.x,
p_362780_.y,
p_362780_.z
);
} else if (p_361004_ < -1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_361004_,
p_368538_,
p_364338_,
p_362338_,
p_368982_,
p_370222_,
p_364885_,
p_367138_,
Direction.EAST,
p_362780_.x,
p_362780_.y,
p_362780_.z
);
}
if (p_368538_ > 1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_368538_,
p_364338_,
p_361004_,
p_368982_,
p_364885_,
p_367138_,
p_364616_,
p_362338_,
Direction.DOWN,
p_362780_.y,
p_362780_.z,
p_362780_.x
);
} else if (p_368538_ < -1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_368538_,
p_364338_,
p_361004_,
p_370222_,
p_364885_,
p_367138_,
p_364616_,
p_362338_,
Direction.UP,
p_362780_.y,
p_362780_.z,
p_362780_.x
);
}
if (p_364338_ > 1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_364338_,
p_361004_,
p_368538_,
p_364885_,
p_364616_,
p_362338_,
p_368982_,
p_370222_,
Direction.NORTH,
p_362780_.z,
p_362780_.x,
p_362780_.y
);
} else if (p_364338_ < -1.0E-7) {
p_366277_ = clipPoint(
p_363085_,
p_366277_,
p_364338_,
p_361004_,
p_368538_,
p_367138_,
p_364616_,
p_362338_,
p_368982_,
p_370222_,
Direction.SOUTH,
p_362780_.z,
p_362780_.x,
p_362780_.y
);
}
return p_366277_;
}
@Nullable
private static Direction clipPoint(
double[] p_82348_,
@Nullable Direction p_82349_,
double p_82350_,
double p_82351_,
double p_82352_,
double p_82353_,
double p_82354_,
double p_82355_,
double p_82356_,
double p_82357_,
Direction p_82358_,
double p_82359_,
double p_82360_,
double p_82361_
) {
double d0 = (p_82353_ - p_82359_) / p_82350_;
double d1 = p_82360_ + d0 * p_82351_;
double d2 = p_82361_ + d0 * p_82352_;
if (0.0 < d0 && d0 < p_82348_[0] && p_82354_ - 1.0E-7 < d1 && d1 < p_82355_ + 1.0E-7 && p_82356_ - 1.0E-7 < d2 && d2 < p_82357_ + 1.0E-7) {
p_82348_[0] = d0;
return p_82358_;
} else {
return p_82349_;
}
}
public boolean collidedAlongVector(Vec3 p_367135_, List<AABB> p_368156_) {
Vec3 vec3 = this.getCenter();
Vec3 vec31 = vec3.add(p_367135_);
for (AABB aabb : p_368156_) {
AABB aabb1 = aabb.inflate(this.getXsize() * 0.5, this.getYsize() * 0.5, this.getZsize() * 0.5);
if (aabb1.contains(vec31) || aabb1.contains(vec3)) {
return true;
}
if (aabb1.clip(vec3, vec31).isPresent()) {
return true;
}
}
return false;
}
public double distanceToSqr(Vec3 p_273572_) {
double d0 = Math.max(Math.max(this.minX - p_273572_.x, p_273572_.x - this.maxX), 0.0);
double d1 = Math.max(Math.max(this.minY - p_273572_.y, p_273572_.y - this.maxY), 0.0);
double d2 = Math.max(Math.max(this.minZ - p_273572_.z, p_273572_.z - this.maxZ), 0.0);
return Mth.lengthSquared(d0, d1, d2);
}
@Override
public String toString() {
return "AABB["
+ this.minX
+ ", "
+ this.minY
+ ", "
+ this.minZ
+ "] -> ["
+ this.maxX
+ ", "
+ this.maxY
+ ", "
+ this.maxZ
+ "]";
}
public boolean hasNaN() {
return Double.isNaN(this.minX)
|| Double.isNaN(this.minY)
|| Double.isNaN(this.minZ)
|| Double.isNaN(this.maxX)
|| Double.isNaN(this.maxY)
|| Double.isNaN(this.maxZ);
}
public Vec3 getCenter() {
return new Vec3(
Mth.lerp(0.5, this.minX, this.maxX), Mth.lerp(0.5, this.minY, this.maxY), Mth.lerp(0.5, this.minZ, this.maxZ)
);
}
public Vec3 getBottomCenter() {
return new Vec3(Mth.lerp(0.5, this.minX, this.maxX), this.minY, Mth.lerp(0.5, this.minZ, this.maxZ));
}
public Vec3 getMinPosition() {
return new Vec3(this.minX, this.minY, this.minZ);
}
public Vec3 getMaxPosition() {
return new Vec3(this.maxX, this.maxY, this.maxZ);
}
public static AABB ofSize(Vec3 p_165883_, double p_165884_, double p_165885_, double p_165886_) {
return new AABB(
p_165883_.x - p_165884_ / 2.0,
p_165883_.y - p_165885_ / 2.0,
p_165883_.z - p_165886_ / 2.0,
p_165883_.x + p_165884_ / 2.0,
p_165883_.y + p_165885_ / 2.0,
p_165883_.z + p_165886_ / 2.0
);
}
} |