A few necessary library additions

This commit is contained in:
aidancbrady 2016-01-04 00:33:00 -05:00
parent 11574e9454
commit 08eb8be841
4 changed files with 238 additions and 19 deletions

View file

@ -1,7 +1,7 @@
package mekanism.api; package mekanism.api;
import java.util.ArrayList; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -15,9 +15,8 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf; import java.util.ArrayList;
/** /**
* Coord4D - an integer-based way to keep track of and perform operations on blocks in a Minecraft-based environment. This also takes * Coord4D - an integer-based way to keep track of and perform operations on blocks in a Minecraft-based environment. This also takes
@ -179,6 +178,18 @@ public class Coord4D
return this; return this;
} }
/**
* Translates this Coord4D by the defined Coord4D's coordinates, regardless of dimension.
* @param coord - coordinates to translate by
* @return translated Coord4D
*/
public Coord4D translate(Coord4D coord)
{
translate(coord.xCoord, coord.yCoord, coord.zCoord);
return this;
}
/** /**
* Creates and returns a new Coord4D translated to the defined offsets of the side. * Creates and returns a new Coord4D translated to the defined offsets of the side.
* @param side - side to translate this Coord4D to * @param side - side to translate this Coord4D to

View file

@ -1,9 +1,11 @@
package mekanism.api; package mekanism.api;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -30,6 +32,13 @@ public class Pos3D
zPos = vec.zCoord; zPos = vec.zCoord;
} }
public Pos3D(MovingObjectPosition mop)
{
xPos = mop.blockX;
yPos = mop.blockY;
zPos = mop.blockZ;
}
public Pos3D(double x, double y, double z) public Pos3D(double x, double y, double z)
{ {
xPos = x; xPos = x;
@ -62,6 +71,30 @@ public class Pos3D
this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
} }
/**
* Returns a new Pos3D from a tag compound.
* @param tag - tag compound to read from
* @return the Pos3D from the tag compound
*/
public static Pos3D read(NBTTagCompound tag)
{
return new Pos3D(tag.getDouble("x"), tag.getDouble("y"), tag.getDouble("z"));
}
/**
* Writes this Pos3D's data to an NBTTagCompound.
* @param nbtTags - tag compound to write to
* @return the tag compound with this Pos3D's data
*/
public NBTTagCompound write(NBTTagCompound nbtTags)
{
nbtTags.setDouble("x", xPos);
nbtTags.setDouble("y", yPos);
nbtTags.setDouble("z", zPos);
return nbtTags;
}
/** /**
* Creates and returns a Pos3D with values representing the difference between this and the Pos3D in the parameters. * Creates and returns a Pos3D with values representing the difference between this and the Pos3D in the parameters.
* @param pos - Pos3D to subtract * @param pos - Pos3D to subtract
@ -75,13 +108,23 @@ public class Pos3D
/** /**
* Creates a new Pos3D from the motion of an entity. * Creates a new Pos3D from the motion of an entity.
* @param entity * @param entity
* @return * @return Pos3D representing the motion of the given entity
*/ */
public static Pos3D fromMotion(Entity entity) public static Pos3D fromMotion(Entity entity)
{ {
return new Pos3D(entity.motionX, entity.motionY, entity.motionZ); return new Pos3D(entity.motionX, entity.motionY, entity.motionZ);
} }
/**
* Creates a new Coord4D representing this Pos3D in the provided dimension.
* @param dimensionId - the dimension this Pos3D is in
* @return Coord4D representing this Pos3D
*/
public Coord4D getCoord(int dimensionId)
{
return new Coord4D((int)xPos, (int)yPos, (int)zPos, dimensionId);
}
/** /**
* Centres a block-derived Pos3D * Centres a block-derived Pos3D
*/ */
@ -187,17 +230,23 @@ public class Pos3D
} }
public Pos3D rotate(double yaw, double pitch) public Pos3D rotate(double yaw, double pitch)
{
return rotate(yaw, pitch, 0);
}
public Pos3D rotate(double yaw, double pitch, double roll)
{ {
double yawRadians = Math.toRadians(yaw); double yawRadians = Math.toRadians(yaw);
double pitchRadians = Math.toRadians(pitch); double pitchRadians = Math.toRadians(pitch);
double rollRadians = Math.toRadians(roll);
double x = xPos; double x = xPos;
double y = yPos; double y = yPos;
double z = zPos; double z = zPos;
xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians); xPos = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
yPos = y * Math.cos(pitchRadians) - z * Math.sin(pitchRadians); zPos = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
zPos = (z * Math.cos(yawRadians) + x * Math.sin(yawRadians)) * (z * Math.cos(pitchRadians) + y * Math.sin(pitchRadians)); yPos = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
return this; return this;
} }
@ -237,6 +286,133 @@ public class Pos3D
return scale(scale, scale, scale); return scale(scale, scale, scale);
} }
public Pos3D rotate(float angle, Pos3D axis)
{
return translateMatrix(getRotationMatrix(angle, axis), this);
}
public double[] getRotationMatrix(float angle)
{
double[] matrix = new double[16];
Pos3D axis = clone().normalize();
double x = axis.xPos;
double y = axis.yPos;
double z = axis.zPos;
angle *= 0.0174532925D;
float cos = (float)Math.cos(angle);
float ocos = 1.0F - cos;
float sin = (float)Math.sin(angle);
matrix[0] = (x * x * ocos + cos);
matrix[1] = (y * x * ocos + z * sin);
matrix[2] = (x * z * ocos - y * sin);
matrix[4] = (x * y * ocos - z * sin);
matrix[5] = (y * y * ocos + cos);
matrix[6] = (y * z * ocos + x * sin);
matrix[8] = (x * z * ocos + y * sin);
matrix[9] = (y * z * ocos - x * sin);
matrix[10] = (z * z * ocos + cos);
matrix[15] = 1.0F;
return matrix;
}
public static Pos3D translateMatrix(double[] matrix, Pos3D translation)
{
double x = translation.xPos * matrix[0] + translation.yPos * matrix[1] + translation.zPos * matrix[2] + matrix[3];
double y = translation.xPos * matrix[4] + translation.yPos * matrix[5] + translation.zPos * matrix[6] + matrix[7];
double z = translation.xPos * matrix[8] + translation.yPos * matrix[9] + translation.zPos * matrix[10] + matrix[11];
translation.xPos = x;
translation.yPos = y;
translation.zPos = z;
return translation;
}
public static double[] getRotationMatrix(float angle, Pos3D axis)
{
return axis.getRotationMatrix(angle);
}
public double anglePreNorm(Pos3D pos2)
{
return Math.acos(dotProduct(pos2));
}
public static double anglePreNorm(Pos3D pos1, Pos3D pos2)
{
return Math.acos(pos1.clone().dotProduct(pos2));
}
public double dotProduct(Pos3D pos)
{
return xPos * pos.xPos + yPos * pos.yPos + zPos * pos.zPos;
}
public Pos3D crossProduct(Pos3D compare)
{
return clone().toCrossProduct(compare);
}
public Pos3D toCrossProduct(Pos3D compare)
{
double newX = yPos * compare.zPos - zPos * compare.yPos;
double newY = zPos * compare.xPos - xPos * compare.zPos;
double newZ = xPos * compare.yPos - yPos * compare.xPos;
xPos = newX;
yPos = newY;
zPos = newZ;
return this;
}
public Pos3D xCrossProduct()
{
return new Pos3D(0.0D, zPos, -yPos);
}
public Pos3D zCrossProduct()
{
return new Pos3D(-yPos, xPos, 0.0D);
}
public Pos3D getPerpendicular()
{
if(zPos == 0)
{
return zCrossProduct();
}
return xCrossProduct();
}
public Pos3D floor()
{
return new Pos3D(Math.floor(xPos), Math.floor(yPos), Math.floor(zPos));
}
public double getMagnitude()
{
return Math.sqrt(xPos * xPos + yPos * yPos + zPos * zPos);
}
public Pos3D normalize()
{
double d = getMagnitude();
if (d != 0)
{
this.scale(1 / d);
}
return this;
}
public static AxisAlignedBB getAABB(Pos3D pos1, Pos3D pos2) public static AxisAlignedBB getAABB(Pos3D pos1, Pos3D pos2)
{ {
return AxisAlignedBB.getBoundingBox( return AxisAlignedBB.getBoundingBox(

View file

@ -13,9 +13,17 @@ public class ContainerNull extends Container
{ {
tileEntity = tile; tileEntity = tile;
if(tileEntity != null)
{
tileEntity.open(player); tileEntity.open(player);
tileEntity.openInventory(); tileEntity.openInventory();
} }
}
public ContainerNull(TileEntityContainerBlock tile)
{
tileEntity = tile;
}
public ContainerNull() {} public ContainerNull() {}

View file

@ -0,0 +1,24 @@
package mekanism.common.inventory.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class SlotSpecific extends Slot
{
private Class<? extends Item> itemClass;
public SlotSpecific(IInventory inventory, int index, int x, int y, Class<? extends Item> c)
{
super(inventory, index, x, y);
itemClass = c;
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return itemClass.equals(itemstack.getItem().getClass()) || itemClass.isInstance(itemstack.getItem());
}
}