mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-11 15:57:42 +00:00
Added some more utility to Cuboid/Rotation
This commit is contained in:
1 parent
3c81313a8c
commit
ffc284349e
2 files changed
+65
-4
No files matched your search
@@ -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<BlockCoord>
|
||||
{
|
||||
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<BlockCoord> iterator() {
|
||||
return new Iterator<BlockCoord>() {
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user