diff --git a/codechicken/lib/vec/CuboidCoord.java b/codechicken/lib/vec/CuboidCoord.java index 90b69ba..5551630 100644 --- a/codechicken/lib/vec/CuboidCoord.java +++ b/codechicken/lib/vec/CuboidCoord.java @@ -2,11 +2,19 @@ package codechicken.lib.vec; import net.minecraft.util.AxisAlignedBB; -public class CuboidCoord +import java.util.Iterator; + +public class CuboidCoord implements Iterable { public BlockCoord min; public BlockCoord max; - + + public CuboidCoord() + { + min = new BlockCoord(); + max = new BlockCoord(); + } + public CuboidCoord(BlockCoord min, BlockCoord max) { this.min = min; @@ -128,4 +136,37 @@ public class CuboidCoord { return set(ia[0], ia[1], ia[2], ia[3], ia[4], ia[5]); } + + public Iterator iterator() { + return new Iterator() { + BlockCoord b = null; + + public boolean hasNext() { + return b == null || !b.equals(max); + } + + public BlockCoord next() { + if(b == null) + b = min.copy(); + else { + if(b.z != max.z) + b.z++; + else { + b.z = min.z; + if(b.y != max.y) + b.y++; + else { + b.y = min.y; + b.x++; + } + } + } + return b; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } } diff --git a/codechicken/lib/vec/Rotation.java b/codechicken/lib/vec/Rotation.java index 86a6c81..e3ee9d5 100644 --- a/codechicken/lib/vec/Rotation.java +++ b/codechicken/lib/vec/Rotation.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import org.lwjgl.opengl.GL11; @@ -123,7 +124,7 @@ public class Rotation extends Transformation throw new IllegalArgumentException("Faces "+s1+" and "+s2+" are opposites"); return rotSideMap[s1*6+s2]; } - + /** * @param player The placing player, used for obtaining the look vector * @param side The side of the block being placed on @@ -138,7 +139,7 @@ public class Rotation extends Transformation { Vector3 axis = Rotation.axes[rotateSide(side^1, r)]; double d = look.scalarProject(axis); - if(max > d) + if(max > d)//TODO wrong way round { max = d; maxr = r; @@ -154,6 +155,25 @@ public class Rotation extends Transformation { return quarterRotations[(r+sideRotOffsets[s])%4].with(sideRotations[s]); } + + /** + * @param entity The placing entity, used for obtaining the look vector + * @return The side towards which the entity is most directly looking. + */ + public static int getSideFromLookAngle(EntityLivingBase entity) + { + Vector3 look = new Vector3(entity.getLook(1)); + double max = 0; + int maxs = 0; + for(int s = 0; s < 6; s++) { + double d = look.scalarProject(axes[s]); + if(d > max) { + max = d; + maxs = s; + } + } + return maxs; + } public double angle; public Vector3 axis;