/** * Create a new instance. * * @param extent The extent * @param x The X-axis position * @param y The Y-axis position * @param z The Z-axis position */ public Location(E extent, int x, int y, int z) { this(extent, new Vector3i(x, y, z)); }
/** * Returns the position of the block that was hit. * * @return The coordinates of the hit block */ public Vector3i getBlockPosition() { if (this.blockPosition == null) { this.blockPosition = new Vector3i(this.xBlock, this.yBlock, this.zBlock); } return this.blockPosition; }
/** * Returns a new biome buffer of the desired size and minimum position. * * @param xMin The minimum point of the buffer on x * @param yMin The minimum point of the buffer on y * @param zMin The minimum point of the buffer on z * @param xSize The size of the buffer on x * @param ySize The size of the buffer on y * @param zSize The size of the buffer on z * @return A new biome buffer */ default MutableBiomeVolume createBiomeBuffer(int xMin, int yMin, int zMin, int xSize, int ySize, int zSize) { return createBiomeBuffer(new Vector3i(xMin, yMin, zMin), new Vector3i(xSize, ySize, zSize)); }
/** * Returns a new block buffer of the desired size. This buffer is thread * safe. * * @param xSize The size of the buffer on x * @param ySize The size of the buffer on y * @param zSize The size of the buffer on z * @return A new block buffer */ default MutableBlockVolume createThreadSafeBlockBuffer(int xSize, int ySize, int zSize) { return createThreadSafeBlockBuffer(new Vector3i(xSize, ySize, zSize)); }
/** * Returns a new biome buffer of the desired size. * * @param xSize The size of the buffer on x * @param ySize The size of the buffer on y * @param zSize The size of the buffer on z * @return A new biome buffer */ default MutableBiomeVolume createBiomeBuffer(int xSize, int ySize, int zSize) { return createBiomeBuffer(new Vector3i(xSize, ySize, zSize)); }
@Override default Location<World> getLocation(int x, int y, int z) { return getLocation(new Vector3i(x, y, z)); }
/** * Gets a location in this extent at the given position. Essentially, this * is a 3D pointer in the extent. * * @param x The X position * @param y The Y position * @param z The Z position * @return The location in this extent */ default Location<? extends Extent> getLocation(int x, int y, int z) { return getLocation(new Vector3i(x, y, z)); }
/** * Returns a new biome buffer of the desired size. This buffer is thread * safe. * * @param xSize The size of the buffer on x * @param ySize The size of the buffer on y * @param zSize The size of the buffer on z * @return A new biome buffer */ default MutableBiomeVolume createThreadSafeBiomeBuffer(int xSize, int ySize, int zSize) { return createThreadSafeBiomeBuffer(new Vector3i(xSize, ySize, zSize)); }
/** * Returns a new block buffer of the desired size. * * @param xSize The size of the buffer on x * @param ySize The size of the buffer on y * @param zSize The size of the buffer on z * @return A new block buffer */ default MutableBlockVolume createBlockBuffer(int xSize, int ySize, int zSize) { return createBlockBuffer(new Vector3i(xSize, ySize, zSize)); }
/** * Gets a location in this extent at the given position. Essentially, this * is a 3D pointer in the extent. This method supports sub-block positions. * Block-related methods use flooring to get integer coordinates. * * @param x The X position * @param y The Y position * @param z The Z position * @return The location in this extent */ default Location<? extends Extent> getLocation(double x, double y, double z) { return getLocation(new Vector3i(x, y, z)); }
@Override default Location<Chunk> getLocation(int x, int y, int z) { return getLocation(new Vector3i(x, y, z)); }
@Override public int getBlockLightLevel(BlockVector3 position) { checkNotNull(position); BlockState state = getWorld().getBlock(new Vector3i(position.getX(), position.getY(), position.getZ())); Optional<GroundLuminanceProperty> groundLuminanceProperty = state.getProperty(GroundLuminanceProperty.class); Optional<SkyLuminanceProperty> skyLuminanceProperty = state.getProperty(SkyLuminanceProperty.class); if (!groundLuminanceProperty.isPresent() || !skyLuminanceProperty.isPresent()) { return 0; } //noinspection ConstantConditions return (int) Math.max(groundLuminanceProperty.get().getValue(), skyLuminanceProperty.get().getValue()); }
/** * Transform a vector represented as a pair of * coordinates using this transform. * * @param x The x coordinate of the original vector * @param y The y coordinate of the original vector * @param z The z coordinate of the original vector * @return The transformed vector */ public Vector3i transform(int x, int y, int z) { return new Vector3i(transformX(x, y, z), transformY(x, y, z), transformZ(x, y, z)); }
/** * Gets the underlying biome position. * * @return The underlying biome position */ public Vector3i getBiomePosition() { if (this.biomePosition == null) { final Vector3i blockPosition = getBlockPosition(); this.biomePosition = new Vector3i(blockPosition.getX(), 0, blockPosition.getZ()); } return this.biomePosition; }
/** * Get the {@link Location} of the highest block that sunlight can reach in * the given column. * * <p>This method ignores all transparent blocks, providing the highest * opaque block.</p> * * @param position The column position * @return The highest opaque position */ default Vector3i getHighestPositionAt(Vector3i position) { return new Vector3i(position.getX(), getHighestYAt(position.getX(), position.getZ()), position.getZ()); }
/** * Returns the position that precipitation ends falling in the column * of the given position. * * <p>A position is still returned for positions in biomes which do not * receive precipitation.</p> * * @param position The position value * @return The position that precipitation ends */ default Vector3i getPrecipitationLevelAt(Vector3i position) { return new Vector3i(position.getX(), this.getPrecipitationLevelAt(position.getX(), position.getZ()), position.getZ()); }
@Test public void testContainsVector3i() { final AABB aabb = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); Assert.assertTrue(aabb.contains(new Vector3i(5, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3i(-1, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3i(5, 11, 11))); Assert.assertFalse(aabb.contains(new Vector3i(5, 3, 14))); }
@Test public void testOfVector3i() { final Vector3i vecGray = new Vector3i(128, 128, 384); final Color colorGray = Color.of(vecGray); assertTrue(Color.GRAY.equals(colorGray)); }
@Test public void testOffsetVector3i() { final AABB aabb1 = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); final AABB aabb2 = new AABB(new Vector3d(11, 0, 4), new Vector3d(17, 8, 14)); Assert.assertEquals(aabb2, aabb1.offset(new Vector3i(10, -2, 1))); }
@Test public void testExpandVector3i() { final AABB aabb1 = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); final AABB aabb2 = new AABB(new Vector3d(-4, 3, 2.5), new Vector3d(12, 9, 13.5)); Assert.assertEquals(aabb2, aabb1.expand(new Vector3i(10, -2, 1))); }