diff --git a/src/main/java/net/minecraft/block/properties/IProperty.java b/src/main/java/net/minecraft/block/properties/IProperty.java new file mode 100644 index 000000000..046b17e49 --- /dev/null +++ b/src/main/java/net/minecraft/block/properties/IProperty.java @@ -0,0 +1,19 @@ +package net.minecraft.block.properties; + +import java.util.Collection; + +/** This code is owned by Minecraft */ + +public interface IProperty> +{ + String getName(); + + Collection getAllowedValues(); + + Class getValueClass(); + + /** + * Get the name for the given value. + */ + String getName(T value); +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/block/state/IBlockState.java b/src/main/java/net/minecraft/block/state/IBlockState.java new file mode 100644 index 000000000..4dd685947 --- /dev/null +++ b/src/main/java/net/minecraft/block/state/IBlockState.java @@ -0,0 +1,23 @@ +package net.minecraft.block.state; + +import com.google.common.collect.ImmutableMap; +import java.util.Collection; +import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; + +/** This code is owned by Minecraft */ + +public interface IBlockState +{ + Collection getPropertyNames(); + + > T getValue(IProperty property); + + , V extends T> IBlockState withProperty(IProperty property, V value); + + > IBlockState cycleProperty(IProperty property); + + ImmutableMap getProperties(); + + Block getBlock(); +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/util/Vec3i.java b/src/main/java/net/minecraft/util/Vec3i.java new file mode 100644 index 000000000..c31a3e150 --- /dev/null +++ b/src/main/java/net/minecraft/util/Vec3i.java @@ -0,0 +1,123 @@ +package net.minecraft.util; + +import com.google.common.base.Objects; + +/** This code is owned by Minecraft */ + +public class Vec3i implements Comparable +{ + /** The Null vector constant (0, 0, 0) */ + public static final Vec3i NULL_VECTOR = new Vec3i(0, 0, 0); + /** X coordinate */ + private final int x; + /** Y coordinate */ + private final int y; + /** Z coordinate */ + private final int z; + + public Vec3i(int xIn, int yIn, int zIn) + { + this.x = xIn; + this.y = yIn; + this.z = zIn; + } + + public Vec3i(double xIn, double yIn, double zIn) + { + this(MathHelper.floor_double(xIn), MathHelper.floor_double(yIn), MathHelper.floor_double(zIn)); + } + + public boolean equals(Object p_equals_1_) + { + if (this == p_equals_1_) + { + return true; + } + else if (!(p_equals_1_ instanceof Vec3i)) + { + return false; + } + else + { + Vec3i vec3i = (Vec3i)p_equals_1_; + return this.getX() != vec3i.getX() ? false : (this.getY() != vec3i.getY() ? false : this.getZ() == vec3i.getZ()); + } + } + + public int hashCode() + { + return (this.getY() + this.getZ() * 31) * 31 + this.getX(); + } + + public int compareTo(Vec3i p_compareTo_1_) + { + return this.getY() == p_compareTo_1_.getY() ? (this.getZ() == p_compareTo_1_.getZ() ? this.getX() - p_compareTo_1_.getX() : this.getZ() - p_compareTo_1_.getZ()) : this.getY() - p_compareTo_1_.getY(); + } + + /** + * Get the X coordinate + */ + public int getX() + { + return this.x; + } + + /** + * Get the Y coordinate + */ + public int getY() + { + return this.y; + } + + /** + * Get the Z coordinate + */ + public int getZ() + { + return this.z; + } + + /** + * Calculate the cross product of this and the given Vector + */ + public Vec3i crossProduct(Vec3i vec) + { + return new Vec3i(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX()); + } + + /** + * Calculate squared distance to the given coordinates + */ + public double distanceSq(double toX, double toY, double toZ) + { + double d0 = (double)this.getX() - toX; + double d1 = (double)this.getY() - toY; + double d2 = (double)this.getZ() - toZ; + return d0 * d0 + d1 * d1 + d2 * d2; + } + + /** + * Compute square of distance from point x, y, z to center of this Block + */ + public double distanceSqToCenter(double xIn, double yIn, double zIn) + { + double d0 = (double)this.getX() + 0.5D - xIn; + double d1 = (double)this.getY() + 0.5D - yIn; + double d2 = (double)this.getZ() + 0.5D - zIn; + return d0 * d0 + d1 * d1 + d2 * d2; + } + + /** + * Calculate squared distance to the given Vector + */ + public double distanceSq(Vec3i to) + { + return this.distanceSq((double)to.getX(), (double)to.getY(), (double)to.getZ()); + } + + public String toString() + { + return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString(); + } +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/util/math/BlockPos.java b/src/main/java/net/minecraft/util/math/BlockPos.java new file mode 100644 index 000000000..87db5faf0 --- /dev/null +++ b/src/main/java/net/minecraft/util/math/BlockPos.java @@ -0,0 +1,407 @@ +package net.minecraft.util.math; + +import com.google.common.collect.AbstractIterator; +import java.util.Iterator; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraft.util.Vec3i; + +/** This code is owned by Minecraft */ + +public class BlockPos extends Vec3i{ + /** The BlockPos with all coordinates 0 */ + public static final BlockPos ORIGIN = new BlockPos(0, 0, 0); + private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); + private static final int NUM_Z_BITS = NUM_X_BITS; + private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS; + private static final int Y_SHIFT = 0 + NUM_Z_BITS; + private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS; + private static final long X_MASK = (1L << NUM_X_BITS) - 1L; + private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L; + private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L; + + public BlockPos(int x, int y, int z) + { + super(x, y, z); + } + + public BlockPos(double x, double y, double z) + { + super(x, y, z); + } + + public BlockPos(Entity source) + { + this(source.posX, source.posY, source.posZ); + } + + public BlockPos(Vec3 source) + { + this(source.xCoord, source.yCoord, source.zCoord); + } + + public BlockPos(Vec3i source) + { + this(source.getX(), source.getY(), source.getZ()); + } + + /** + * Add the given coordinates to the coordinates of this BlockPos + */ + public BlockPos add(double x, double y, double z) + { + return x == 0.0D && y == 0.0D && z == 0.0D ? this : new BlockPos((double)this.getX() + x, (double)this.getY() + y, (double)this.getZ() + z); + } + + /** + * Add the given coordinates to the coordinates of this BlockPos + */ + public BlockPos add(int x, int y, int z) + { + return x == 0 && y == 0 && z == 0 ? this : new BlockPos(this.getX() + x, this.getY() + y, this.getZ() + z); + } + + /** + * Add the given Vector to this BlockPos + */ + public BlockPos add(Vec3i vec) + { + return vec.getX() == 0 && vec.getY() == 0 && vec.getZ() == 0 ? this : new BlockPos(this.getX() + vec.getX(), this.getY() + vec.getY(), this.getZ() + vec.getZ()); + } + + /** + * Subtract the given Vector from this BlockPos + */ + public BlockPos subtract(Vec3i vec) + { + return vec.getX() == 0 && vec.getY() == 0 && vec.getZ() == 0 ? this : new BlockPos(this.getX() - vec.getX(), this.getY() - vec.getY(), this.getZ() - vec.getZ()); + } + + /** + * Offset this BlockPos 1 block up + */ + public BlockPos up() + { + return this.up(1); + } + + /** + * Offset this BlockPos n blocks up + */ + public BlockPos up(int n) + { + return this.offset(EnumFacing.UP, n); + } + + /** + * Offset this BlockPos 1 block down + */ + public BlockPos down() + { + return this.down(1); + } + + /** + * Offset this BlockPos n blocks down + */ + public BlockPos down(int n) + { + return this.offset(EnumFacing.DOWN, n); + } + + /** + * Offset this BlockPos 1 block in northern direction + */ + public BlockPos north() + { + return this.north(1); + } + + /** + * Offset this BlockPos n blocks in northern direction + */ + public BlockPos north(int n) + { + return this.offset(EnumFacing.NORTH, n); + } + + /** + * Offset this BlockPos 1 block in southern direction + */ + public BlockPos south() + { + return this.south(1); + } + + /** + * Offset this BlockPos n blocks in southern direction + */ + public BlockPos south(int n) + { + return this.offset(EnumFacing.SOUTH, n); + } + + /** + * Offset this BlockPos 1 block in western direction + */ + public BlockPos west() + { + return this.west(1); + } + + /** + * Offset this BlockPos n blocks in western direction + */ + public BlockPos west(int n) + { + return this.offset(EnumFacing.WEST, n); + } + + /** + * Offset this BlockPos 1 block in eastern direction + */ + public BlockPos east() + { + return this.east(1); + } + + /** + * Offset this BlockPos n blocks in eastern direction + */ + public BlockPos east(int n) + { + return this.offset(EnumFacing.EAST, n); + } + + /** + * Offset this BlockPos 1 block in the given direction + */ + public BlockPos offset(EnumFacing facing) + { + return this.offset(facing, 1); + } + + /** + * Offsets this BlockPos n blocks in the given direction + */ + public BlockPos offset(EnumFacing facing, int n) + { + return n == 0 ? this : new BlockPos(this.getX() + facing.getFrontOffsetX() * n, this.getY() + facing.getFrontOffsetY() * n, this.getZ() + facing.getFrontOffsetZ() * n); + } + + /** + * Calculate the cross product of this and the given Vector + */ + public BlockPos crossProduct(Vec3i vec) + { + return new BlockPos(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX()); + } + + /** + * Serialize this BlockPos into a long value + */ + public long toLong() + { + return ((long)this.getX() & X_MASK) << X_SHIFT | ((long)this.getY() & Y_MASK) << Y_SHIFT | ((long)this.getZ() & Z_MASK) << 0; + } + + /** + * Create a BlockPos from a serialized long value (created by toLong) + */ + public static BlockPos fromLong(long serialized) + { + int i = (int)(serialized << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS); + int j = (int)(serialized << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS); + int k = (int)(serialized << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS); + return new BlockPos(i, j, k); + } + + public static Iterable getAllInBox(BlockPos from, BlockPos to) + { + final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ())); + final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ())); + return new Iterable() + { + public Iterator iterator() + { + return new AbstractIterator() + { + private BlockPos lastReturned = null; + protected BlockPos computeNext() + { + if (this.lastReturned == null) + { + this.lastReturned = blockpos; + return this.lastReturned; + } + else if (this.lastReturned.equals(blockpos1)) + { + return (BlockPos)this.endOfData(); + } + else + { + int i = this.lastReturned.getX(); + int j = this.lastReturned.getY(); + int k = this.lastReturned.getZ(); + + if (i < blockpos1.getX()) + { + ++i; + } + else if (j < blockpos1.getY()) + { + i = blockpos.getX(); + ++j; + } + else if (k < blockpos1.getZ()) + { + i = blockpos.getX(); + j = blockpos.getY(); + ++k; + } + + this.lastReturned = new BlockPos(i, j, k); + return this.lastReturned; + } + } + }; + } + }; + } + + public static Iterable getAllInBoxMutable(BlockPos from, BlockPos to) + { + final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ())); + final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ())); + return new Iterable() + { + public Iterator iterator() + { + return new AbstractIterator() + { + private BlockPos.MutableBlockPos theBlockPos = null; + protected BlockPos.MutableBlockPos computeNext() + { + if (this.theBlockPos == null) + { + this.theBlockPos = new BlockPos.MutableBlockPos(blockpos.getX(), blockpos.getY(), blockpos.getZ()); + return this.theBlockPos; + } + else if (this.theBlockPos.equals(blockpos1)) + { + return (BlockPos.MutableBlockPos)this.endOfData(); + } + else + { + int i = this.theBlockPos.getX(); + int j = this.theBlockPos.getY(); + int k = this.theBlockPos.getZ(); + + if (i < blockpos1.getX()) + { + ++i; + } + else if (j < blockpos1.getY()) + { + i = blockpos.getX(); + ++j; + } + else if (k < blockpos1.getZ()) + { + i = blockpos.getX(); + j = blockpos.getY(); + ++k; + } + + this.theBlockPos.x = i; + this.theBlockPos.y = j; + this.theBlockPos.z = k; + return this.theBlockPos; + } + } + }; + } + }; + } + + /** + * Returns a version of this BlockPos that is guaranteed to be Immutable. + * In most cases this will return 'this', but if 'this' is an instance of + * MutableBlockPos it will return a new instance of BlockPos with the same values. + * + * When storing a parameter given to you for an extended period of time, make sure you + * use this in case the value is changed internally. + * + * @return An immutable BlockPos. + */ + public BlockPos getImmutable() + { + return this; + } + + public static final class MutableBlockPos extends BlockPos + { + /** Mutable X Coordinate */ + private int x; + /** Mutable Y Coordinate */ + private int y; + /** Mutable Z Coordinate */ + private int z; + + public MutableBlockPos() + { + this(0, 0, 0); + } + + public MutableBlockPos(int x_, int y_, int z_) + { + super(0, 0, 0); + this.x = x_; + this.y = y_; + this.z = z_; + } + + /** + * Get the X coordinate + */ + public int getX() + { + return this.x; + } + + /** + * Get the Y coordinate + */ + public int getY() + { + return this.y; + } + + /** + * Get the Z coordinate + */ + public int getZ() + { + return this.z; + } + + /** + * Set the values + * + * @param xIn The X value + * @param yIn The Y value + * @param zIn The Z value + */ + public BlockPos.MutableBlockPos set(int xIn, int yIn, int zIn) + { + this.x = xIn; + this.y = yIn; + this.z = zIn; + return this; + } + + @Override public BlockPos getImmutable() { return new BlockPos(this); } + } +} \ No newline at end of file