diff --git a/common/mekanism/api/Pos3D.java b/common/mekanism/api/Pos3D.java new file mode 100644 index 000000000..c98d5d50b --- /dev/null +++ b/common/mekanism/api/Pos3D.java @@ -0,0 +1,115 @@ +package mekanism.api; + +import net.minecraft.entity.Entity; +import net.minecraft.util.MathHelper; + +public class Pos3D +{ + public double xPos; + public double yPos; + public double zPos; + + public Pos3D() + { + this(0, 0, 0); + } + + public Pos3D(double x, double y, double z) + { + xPos = x; + yPos = y; + zPos = z; + } + + public Pos3D(Entity entity) + { + this(entity.posX, entity.posY, entity.posZ); + } + + public Pos3D diff(Pos3D pos) + { + return new Pos3D(xPos-pos.xPos, yPos-pos.yPos, zPos-pos.zPos); + } + + public static Pos3D fromMotion(Entity entity) + { + return new Pos3D(entity.motionX, entity.motionY, entity.motionZ); + } + + public Pos3D translate(double x, double y, double z) + { + xPos += x; + yPos += y; + zPos += z; + + return this; + } + + public Pos3D translate(Pos3D pos) + { + return translate(pos.xPos, pos.yPos, pos.zPos); + } + + public double distance(Pos3D pos) + { + double subX = xPos - pos.xPos; + double subY = yPos - pos.yPos; + double subZ = zPos - pos.zPos; + return MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ); + } + + public Pos3D rotateYaw(double yaw) + { + double yawRadians = Math.toRadians(yaw); + + double x = xPos; + double z = zPos; + + if(yaw != 0) + { + xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians); + zPos = x * Math.sin(yawRadians) + z * Math.cos(yawRadians); + } + + return this; + } + + public Pos3D scale(double x, double y, double z) + { + xPos *= x; + yPos *= y; + zPos *= z; + + return this; + } + + public Pos3D scale(double scale) + { + return scale(scale, scale, scale); + } + + @Override + public Pos3D clone() + { + return new Pos3D(xPos, yPos, zPos); + } + + @Override + public boolean equals(Object obj) + { + return obj instanceof Pos3D && + ((Pos3D)obj).xPos == xPos && + ((Pos3D)obj).yPos == yPos && + ((Pos3D)obj).zPos == zPos; + } + + @Override + public int hashCode() + { + int code = 1; + code = 31 * code + new Double(xPos).hashCode(); + code = 31 * code + new Double(yPos).hashCode(); + code = 31 * code + new Double(zPos).hashCode(); + return code; + } +} diff --git a/common/mekanism/client/render/RenderTickHandler.java b/common/mekanism/client/render/RenderTickHandler.java index b0742f7d6..83b6b34ac 100644 --- a/common/mekanism/client/render/RenderTickHandler.java +++ b/common/mekanism/client/render/RenderTickHandler.java @@ -5,8 +5,9 @@ import java.util.HashSet; import java.util.Random; import java.util.Set; -import mekanism.api.EnumColor; import mekanism.api.Coord4D; +import mekanism.api.EnumColor; +import mekanism.api.Pos3D; import mekanism.common.Mekanism; import mekanism.common.item.ItemJetpack; import mekanism.common.item.ItemScubaTank; @@ -22,7 +23,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; import cpw.mods.fml.relauncher.Side; @@ -114,54 +114,54 @@ public class RenderTickHandler implements ITickHandler continue; } - Vector3 playerPos = new Vector3(p); + Pos3D playerPos = new Pos3D(p); if(p != mc.thePlayer) { - playerPos.translate(new Vector3(0, 1.7, 0)); + playerPos.translate(0, 1.7, 0); } float random = (rand.nextFloat()-0.5F)*0.1F; - Vector3 vLeft = new Vector3(); - vLeft.z -= 0.54; - vLeft.x -= 0.43; - vLeft.rotate(p.renderYawOffset); - vLeft.y -= 0.55; + Pos3D vLeft = new Pos3D(); + vLeft.zPos -= 0.54; + vLeft.xPos -= 0.43; + vLeft.rotateYaw(p.renderYawOffset); + vLeft.yPos -= 0.55; - Vector3 vRight = new Vector3(); - vRight.z -= 0.54; - vRight.x += 0.43; - vRight.rotate(p.renderYawOffset); - vRight.y -= 0.55; + Pos3D vRight = new Pos3D(); + vRight.xPos += 0.43; + vRight.yPos -= 0.55; + vRight.zPos -= 0.54; + vRight.rotateYaw(p.renderYawOffset); - Vector3 vCenter = new Vector3(); - vCenter.z -= 0.30; - vCenter.x = (rand.nextFloat()-0.5F)*0.4F; - vCenter.rotate(p.renderYawOffset); - vCenter.y -= 0.86; + Pos3D vCenter = new Pos3D(); + vCenter.xPos = (rand.nextFloat()-0.5F)*0.4F; + vCenter.yPos -= 0.86; + vCenter.zPos -= 0.30; + vCenter.rotateYaw(p.renderYawOffset); - Vector3 rLeft = vLeft.clone().scale(random); - Vector3 rRight = vRight.clone().scale(random); + Pos3D rLeft = vLeft.clone().scale(random); + Pos3D rRight = vRight.clone().scale(random); - Vector3 mLeft = Vector3.translate(vLeft.clone().scale(0.2), new Vector3(p.motionX, p.motionY, p.motionZ)); - Vector3 mRight = Vector3.translate(vRight.clone().scale(0.2), new Vector3(p.motionX, p.motionY, p.motionZ)); - Vector3 mCenter = Vector3.translate(vCenter.clone().scale(0.2), new Vector3(p.motionX, p.motionY, p.motionZ)); + Pos3D mLeft = vLeft.clone().scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ)); + Pos3D mRight = vRight.clone().scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ)); + Pos3D mCenter = vCenter.clone().scale(0.2).translate(new Pos3D(p.motionX, p.motionY, p.motionZ)); mLeft.translate(rLeft); mRight.translate(rRight); - Vector3 v = new Vector3(playerPos).translate(vLeft); - spawnAndSetParticle("flame", world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z); - spawnAndSetParticle("smoke", world, v.x, v.y, v.z, mLeft.x, mLeft.y, mLeft.z); + Pos3D v = playerPos.clone().translate(vLeft); + spawnAndSetParticle("flame", world, v.xPos, v.yPos, v.zPos, mLeft.xPos, mLeft.yPos, mLeft.zPos); + spawnAndSetParticle("smoke", world, v.xPos, v.yPos, v.zPos, mLeft.xPos, mLeft.yPos, mLeft.zPos); - v = new Vector3(playerPos).translate(vRight); - spawnAndSetParticle("flame", world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z); - spawnAndSetParticle("smoke", world, v.x, v.y, v.z, mRight.x, mRight.y, mRight.z); + v = playerPos.clone().translate(vRight); + spawnAndSetParticle("flame", world, v.xPos, v.yPos, v.zPos, mRight.xPos, mRight.yPos, mRight.zPos); + spawnAndSetParticle("smoke", world, v.xPos, v.yPos, v.zPos, mRight.xPos, mRight.yPos, mRight.zPos); - v = new Vector3(playerPos).translate(vCenter); - spawnAndSetParticle("flame", world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z); - spawnAndSetParticle("smoke", world, v.x, v.y, v.z, mCenter.x, mCenter.y, mCenter.z); + v = playerPos.clone().translate(vCenter); + spawnAndSetParticle("flame", world, v.xPos, v.yPos, v.zPos, mCenter.xPos, mCenter.yPos, mCenter.zPos); + spawnAndSetParticle("smoke", world, v.xPos, v.yPos, v.zPos, mCenter.xPos, mCenter.yPos, mCenter.zPos); } } } diff --git a/common/mekanism/common/item/ItemBalloon.java b/common/mekanism/common/item/ItemBalloon.java index ab9837e9e..ecec2e6cb 100644 --- a/common/mekanism/common/item/ItemBalloon.java +++ b/common/mekanism/common/item/ItemBalloon.java @@ -4,12 +4,12 @@ import java.util.List; import mekanism.api.Coord4D; import mekanism.api.EnumColor; +import mekanism.api.Pos3D; import mekanism.common.EntityBalloon; import mekanism.common.util.MekanismUtils; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -46,13 +46,13 @@ public class ItemBalloon extends ItemMekanism { if(!world.isRemote) { - Vector3 vec = new Vector3(); - vec.z += 0.3; - vec.x -= 0.4; - vec.rotate(entityplayer.renderYawOffset); - vec.translate(new Vector3(entityplayer)); + Pos3D pos = new Pos3D(); + pos.zPos += 0.3; + pos.xPos -= 0.4; + pos.rotateYaw(entityplayer.renderYawOffset); + pos.translate(new Pos3D(entityplayer)); - world.spawnEntityInWorld(new EntityBalloon(world, vec.x-0.5, vec.y-0.25, vec.z-0.5, getColor(itemstack))); + world.spawnEntityInWorld(new EntityBalloon(world, pos.xPos-0.5, pos.yPos-0.25, pos.zPos-0.5, getColor(itemstack))); } itemstack.stackSize--;