mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-15 13:44:45 +00:00
Annotate all the things
This commit is contained in:
63 files changed
+623
-369
No files matched your search
@@ -33,8 +33,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.Vec3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.ArrayList;
|
||||
@@ -53,6 +51,7 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* An immutable block pos with zero as all coordinates.
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static final BlockPos ORIGIN = new BlockPos(0, 0, 0);
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int NUM_X_BITS = 1 + MathUtil.log2(MathUtil.smallestEncompassingPowerOfTwo(30000000));
|
||||
@@ -64,22 +63,27 @@ public class BlockPos extends Vec3i {
|
||||
private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
|
||||
private static final long X_MASK = (1L << NUM_X_BITS) - 1L;
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos(@NonNull Entity source) {
|
||||
this(source.posX, source.posY, source.posZ);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos(double x, double y, double z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos(@NonNull Vec3 vec) {
|
||||
this(vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos(@NonNull Vec3i source) {
|
||||
this(source.getX(), source.getY(), source.getZ());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
@@ -87,6 +91,7 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* Create a BlockPos from a serialized long value (created by toLong)
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static BlockPos fromLong(long serialized) {
|
||||
return new BlockPos((int) (serialized << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS),
|
||||
(int) (serialized << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS),
|
||||
@@ -99,13 +104,14 @@ public class BlockPos extends Vec3i {
|
||||
* <p>
|
||||
* In situations where it is usable, prefer
|
||||
* {@link #getAllInBoxMutable(BlockPos, BlockPos) instead as it has better performance (fewer allocations)
|
||||
*
|
||||
* <p>
|
||||
* @param from One corner of the box
|
||||
* @param to Another corner of the box
|
||||
*
|
||||
* <p>
|
||||
* @see #getAllInBox(int, int, int, int, int, int)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static Iterable<BlockPos> getAllInBox(@NonNull BlockPos from, @NonNull BlockPos to) {
|
||||
return getAllInBox(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
|
||||
@@ -118,17 +124,18 @@ public class BlockPos extends Vec3i {
|
||||
* <p>
|
||||
* In situations where it is usable, prefer
|
||||
* {@link #getAllInBoxMutable(BlockPos, BlockPos) instead as it has better performance (fewer allocations)
|
||||
*
|
||||
* <p>
|
||||
* @param x0 The lower x coordinate
|
||||
* @param y0 The lower y coordinate
|
||||
* @param z0 The lower z coordinate
|
||||
* @param x1 The upper x coordinate
|
||||
* @param y1 The upper y coordinate
|
||||
* @param z1 The upper z coordinate
|
||||
*
|
||||
* <p>
|
||||
* @see #getAllInBox(BlockPos, BlockPos)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static Iterable<BlockPos> getAllInBox(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
|
||||
return () -> new AbstractIterator<BlockPos>() {
|
||||
private boolean first = true;
|
||||
@@ -179,6 +186,7 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBox(int, int, int, int, int, int)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(@NonNull BlockPos from, @NonNull BlockPos to) {
|
||||
return getAllInBoxMutable(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
|
||||
@@ -205,6 +213,7 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBox(int, int, int, int, int, int)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
|
||||
return () -> new AbstractIterator<MutableBlockPos>() {
|
||||
private MutableBlockPos pos;
|
||||
@@ -233,6 +242,7 @@ public class BlockPos extends Vec3i {
|
||||
};
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public long toLong() {
|
||||
return ((long) x & X_MASK) << X_SHIFT | ((long) y & Y_MASK) << Y_SHIFT | ((long) z & Z_MASK);
|
||||
}
|
||||
@@ -240,6 +250,7 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* Add the given coordinates to the coordinates of this BlockPos
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public BlockPos add(double x, double y, double z) {
|
||||
if (x == 0.0D && y == 0.0D && z == 0.0D) {
|
||||
return this;
|
||||
@@ -250,6 +261,7 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* Add the given Vector to this BlockPos
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public BlockPos add(@NonNull Vec3i vec) {
|
||||
return add(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
@@ -257,6 +269,7 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* Add the given coordinates to the coordinates of this BlockPos
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public BlockPos add(int x, int y, int z) {
|
||||
if (x == 0 && y == 0 && z == 0) {
|
||||
return this;
|
||||
@@ -267,18 +280,22 @@ public class BlockPos extends Vec3i {
|
||||
/**
|
||||
* Subtract the given Vector from this BlockPos
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public BlockPos subtract(@NonNull Vec3i vec) {
|
||||
return add(-vec.getX(), -vec.getY(), -vec.getZ());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos up() {
|
||||
return up(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos up(int blocks) {
|
||||
return offset(UP, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos offset(@NonNull EnumFacing facing, int blocks) {
|
||||
if (blocks == 0) {
|
||||
return this;
|
||||
@@ -287,50 +304,62 @@ public class BlockPos extends Vec3i {
|
||||
z + facing.getFrontOffsetZ() * blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos down() {
|
||||
return down(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos down(int blocks) {
|
||||
return offset(DOWN, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos north() {
|
||||
return north(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos north(int blocks) {
|
||||
return offset(NORTH, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos south() {
|
||||
return south(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos south(int blocks) {
|
||||
return offset(SOUTH, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos west() {
|
||||
return west(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos west(int blocks) {
|
||||
return offset(WEST, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos east() {
|
||||
return east(1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos east(int blocks) {
|
||||
return offset(EAST, blocks);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos offset(@NonNull EnumFacing facing) {
|
||||
return offset(facing, 1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos rotate(@NonNull Rotation rotation) {
|
||||
switch (rotation) {
|
||||
case NONE:
|
||||
@@ -351,12 +380,14 @@ public class BlockPos extends Vec3i {
|
||||
x * vec.getY() - y * vec.getX());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos toImmutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Setter(onMethod_ = @StableAPI.Expose)
|
||||
@Getter(onMethod_ = @StableAPI.Expose)
|
||||
@StableAPI(since = "0.10.0")
|
||||
public static class MutableBlockPos extends BlockPos {
|
||||
/**
|
||||
* Mutable X Coordinate
|
||||
@@ -371,14 +402,17 @@ public class BlockPos extends Vec3i {
|
||||
*/
|
||||
protected int z;
|
||||
|
||||
@StableAPI.Expose
|
||||
public MutableBlockPos() {
|
||||
this(ORIGIN);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public MutableBlockPos(@NonNull BlockPos blockPos) {
|
||||
this(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public MutableBlockPos(int x, int y, int z) {
|
||||
super(ORIGIN);
|
||||
this.x = x;
|
||||
@@ -406,19 +440,21 @@ public class BlockPos extends Vec3i {
|
||||
return super.rotate(rotation).toImmutable();
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos toImmutable() {
|
||||
return new BlockPos(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public BlockPos.MutableBlockPos setPos(@NonNull Entity entity) {
|
||||
return this.setPos(entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos.MutableBlockPos setPos(double x, double y, double z) {
|
||||
return setPos(MathUtil.floor(x), MathUtil.floor(y), MathUtil.floor(z));
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos.MutableBlockPos setPos(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -426,20 +462,24 @@ public class BlockPos extends Vec3i {
|
||||
return this;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos.MutableBlockPos setPos(@NonNull Vec3i vec) {
|
||||
return this.setPos(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing) {
|
||||
return this.move(facing, 1);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing, int blocks) {
|
||||
return this.setPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks,
|
||||
z + facing.getFrontOffsetZ() * blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public static final class PooledMutableBlockPos extends BlockPos.MutableBlockPos {
|
||||
private static final List<BlockPos.PooledMutableBlockPos> POOL = new ArrayList<>();
|
||||
private boolean released;
|
||||
@@ -448,10 +488,12 @@ public class BlockPos extends Vec3i {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static BlockPos.PooledMutableBlockPos retain() {
|
||||
return retain(0, 0, 0);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static BlockPos.PooledMutableBlockPos retain(int x, int y, int z) {
|
||||
synchronized (POOL) {
|
||||
if (!POOL.isEmpty()) {
|
||||
@@ -466,15 +508,17 @@ public class BlockPos extends Vec3i {
|
||||
return new BlockPos.PooledMutableBlockPos(x, y, z);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static BlockPos.PooledMutableBlockPos retain(double x, double y, double z) {
|
||||
return retain(MathUtil.floor(x), MathUtil.floor(y), MathUtil.floor(z));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@StableAPI.Expose
|
||||
public static BlockPos.PooledMutableBlockPos retain(@NonNull Vec3i vec) {
|
||||
return retain(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public void release() {
|
||||
synchronized (POOL) {
|
||||
if (POOL.size() < 100) {
|
||||
@@ -485,7 +529,6 @@ public class BlockPos extends Vec3i {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public BlockPos.PooledMutableBlockPos setPos(@NonNull Entity entity) {
|
||||
return (BlockPos.PooledMutableBlockPos) super.setPos(entity);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user