Commits
Doc authored and md_5 committed 40945171bf8
24 24 | import net.minecraft.world.level.biome.BiomeBase; |
25 25 | import net.minecraft.world.level.block.BlockRedstoneWire; |
26 26 | import net.minecraft.world.level.block.BlockSapling; |
27 27 | import net.minecraft.world.level.block.Blocks; |
28 28 | import net.minecraft.world.level.block.state.IBlockData; |
29 29 | import net.minecraft.world.phys.AxisAlignedBB; |
30 30 | import net.minecraft.world.phys.MovingObjectPosition; |
31 31 | import net.minecraft.world.phys.MovingObjectPositionBlock; |
32 32 | import net.minecraft.world.phys.Vec3D; |
33 33 | import net.minecraft.world.phys.shapes.VoxelShape; |
34 - | import org.apache.commons.lang.Validate; |
35 34 | import org.bukkit.Bukkit; |
36 35 | import org.bukkit.Chunk; |
37 36 | import org.bukkit.FluidCollisionMode; |
38 37 | import org.bukkit.Location; |
39 38 | import org.bukkit.Material; |
40 39 | import org.bukkit.Registry; |
41 40 | import org.bukkit.TreeType; |
42 41 | import org.bukkit.World; |
43 42 | import org.bukkit.block.Biome; |
44 43 | import org.bukkit.block.Block; |
385 384 | |
386 385 | public boolean isBlockIndirectlyPowered() { |
387 386 | return world.getMinecraftWorld().hasNeighborSignal(position); |
388 387 | } |
389 388 | |
390 389 | |
391 390 | public boolean equals(Object o) { |
392 391 | if (o == this) { |
393 392 | return true; |
394 393 | } |
395 - | if (!(o instanceof CraftBlock)) { |
394 + | if (!(o instanceof CraftBlock other)) { |
396 395 | return false; |
397 396 | } |
398 - | CraftBlock other = (CraftBlock) o; |
399 397 | |
400 398 | return this.position.equals(other.position) && this.getWorld().equals(other.getWorld()); |
401 399 | } |
402 400 | |
403 401 | |
404 402 | public int hashCode() { |
405 403 | return this.position.hashCode() ^ this.getWorld().hashCode(); |
406 404 | } |
407 405 | |
408 406 | |
586 584 | getCraftWorld().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin); |
587 585 | } |
588 586 | |
589 587 | |
590 588 | public boolean isPassable() { |
591 589 | return this.getNMS().getCollisionShape(world, position).isEmpty(); |
592 590 | } |
593 591 | |
594 592 | |
595 593 | public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) { |
596 - | Validate.notNull(start, "Start location is null!"); |
597 - | Validate.isTrue(this.getWorld().equals(start.getWorld()), "Start location is from different world!"); |
594 + | Preconditions.checkArgument(start != null, "Location start cannot be null"); |
595 + | Preconditions.checkArgument(this.getWorld().equals(start.getWorld()), "Location start cannot be a different world"); |
598 596 | start.checkFinite(); |
599 597 | |
600 - | Validate.notNull(direction, "Direction is null!"); |
598 + | Preconditions.checkArgument(direction != null, "Vector direction cannot be null"); |
601 599 | direction.checkFinite(); |
602 - | Validate.isTrue(direction.lengthSquared() > 0, "Direction's magnitude is 0!"); |
600 + | Preconditions.checkArgument(direction.lengthSquared() > 0, "Direction's magnitude (%s) must be greater than 0", direction.lengthSquared()); |
603 601 | |
604 - | Validate.notNull(fluidCollisionMode, "Fluid collision mode is null!"); |
602 + | Preconditions.checkArgument(fluidCollisionMode != null, "FluidCollisionMode cannot be null"); |
605 603 | if (maxDistance < 0.0D) { |
606 604 | return null; |
607 605 | } |
608 606 | |
609 607 | Vector dir = direction.clone().normalize().multiply(maxDistance); |
610 608 | Vec3D startPos = CraftLocation.toVec3D(start); |
611 609 | Vec3D endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ()); |
612 610 | |
613 611 | MovingObjectPosition nmsHitResult = world.clip(new RayTrace(startPos, endPos, RayTrace.BlockCollisionOption.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), null), position); |
614 612 | return CraftRayTraceResult.fromNMS(this.getWorld(), nmsHitResult); |
627 625 | } |
628 626 | |
629 627 | |
630 628 | public org.bukkit.util.VoxelShape getCollisionShape() { |
631 629 | VoxelShape shape = getNMS().getCollisionShape(world, position); |
632 630 | return new CraftVoxelShape(shape); |
633 631 | } |
634 632 | |
635 633 | |
636 634 | public boolean canPlace(BlockData data) { |
637 - | Preconditions.checkArgument(data != null, "Provided block data is null!"); |
635 + | Preconditions.checkArgument(data != null, "BlockData cannot be null"); |
638 636 | net.minecraft.world.level.block.state.IBlockData iblockdata = ((CraftBlockData) data).getState(); |
639 637 | net.minecraft.world.level.World world = this.world.getMinecraftWorld(); |
640 638 | |
641 639 | return iblockdata.canSurvive(world, this.position); |
642 640 | } |
643 641 | |
644 642 | |
645 643 | public String getTranslationKey() { |
646 644 | return getNMS().getBlock().getDescriptionId(); |
647 645 | } |
648 646 | } |