// Build table that maps vertex indices to // vertex positions for "even vertices" in // Loop subdivision scheme. // protected Hashtable<Integer, Vec3> evenLoopVerts() { Hashtable<Integer, Vec3> evenVerts = new Hashtable<Integer, Vec3>(); for (int i = 0; i < V.size(); i++) { Vector<Vec3> adjVerts = new Vector<Vec3>(); Vert v = V.get(i); Vec3 vCoord = (Vec3) v.coord.clone(); // grow a list of adjacent verts, use the // number of adjacent verts to calculate B // then scale and combine adjacent verts Edge e = E.get(v.e); Edge nextEdge = e; do { nextEdge = E.get(nextEdge.next); adjVerts.add((Vec3) V.get(nextEdge.v).coord.clone()); nextEdge = E.get(E.get(nextEdge.next).sym); } while (nextEdge.i != e.i); float n = adjVerts.size(); float B; if (n > 3) B = 3.0f / (8 * n); else B = 3.0f / 16.0f; // scale vCoord and the adjacent verts // and combine them vCoord = vCoord.scale(1 - n * B); for (int j = 0; j < adjVerts.size(); j++) vCoord = Vec3.add(vCoord, adjVerts.get(j).scale(B)); // vCoord is now our new even loop vert Vec3 evenVerts.put(v.i, vCoord); } return evenVerts; }
protected MovingObjectPosition getMovingObjectPositionFromPlayer( World par1World, EntityPlayer par2EntityPlayer, boolean par3) { float var4 = 1.0F; float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double) var4; double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double) var4 + 1.62D - (double) par2EntityPlayer.yOffset; double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double) var4; Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI); float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI); float var16 = -MathHelper.cos(-var5 * 0.017453292F); float var17 = MathHelper.sin(-var5 * 0.017453292F); float var18 = var15 * var16; float var20 = var14 * var16; double var21 = 5.0D; Vec3 var23 = var13.addVector((double) var18 * var21, (double) var17 * var21, (double) var20 * var21); return par1World.rayTraceBlocks_do_do(var13, var23, par3, !par3); }
/** * Can add to the passed in vector for a movement vector to be applied to the entity. Args: x, y, * z, entity, vec3d */ public void velocityToAddToEntity( World par1World, int par2, int par3, int par4, Entity par5Entity, Vec3 par6Vec3) { Vec3 var7 = this.getFlowVector(par1World, par2, par3, par4); par6Vec3.xCoord += var7.xCoord; par6Vec3.yCoord += var7.yCoord; par6Vec3.zCoord += var7.zCoord; }
/** * finds a random target within par1(x,z) and par2 (y) blocks in the reverse direction of the * point par3 */ public static Vec3 findRandomTargetBlockAwayFrom( EntityCreature par0EntityCreature, int par1, int par2, Vec3 par3Vec3) { staticVector.xCoord = par0EntityCreature.posX - par3Vec3.xCoord; staticVector.yCoord = par0EntityCreature.posY - par3Vec3.yCoord; staticVector.zCoord = par0EntityCreature.posZ - par3Vec3.zCoord; return findRandomTargetBlock(par0EntityCreature, par1, par2, staticVector); }
/** * finds a random target within par1(x,z) and par2 (y) blocks in the direction of the point par3 */ public static Vec3 findRandomTargetBlockTowards( EntityCreature par0EntityCreature, int par1, int par2, Vec3 par3Vec3) { staticVector.xCoord = par3Vec3.xCoord - par0EntityCreature.posX; staticVector.yCoord = par3Vec3.yCoord - par0EntityCreature.posY; staticVector.zCoord = par3Vec3.zCoord - par0EntityCreature.posZ; return findRandomTargetBlock(par0EntityCreature, par1, par2, staticVector); }
public static float[] toFloatArray(Vec3 vec) { float[] f = new float[3]; f[0] = vec.getX(); f[1] = vec.getY(); f[2] = vec.getZ(); return f; }
public Vec3 multiply3x3(final Vec3 vec) { final float x = vec.getX(); final float y = vec.getY(); final float z = vec.getZ(); return new Vec3( x * this.data[M00] + y * this.data[M01] + z * this.data[M02], x * this.data[M10] + y * this.data[M11] + z * this.data[M12], x * this.data[M20] + y * this.data[M21] + z * this.data[M22]); }
public Vec3 multiply(final Vec3 vec) { final float x = vec.getX(); final float y = vec.getY(); final float z = vec.getZ(); final float rcpw = 1.0f / (x * this.data[M30] + y * this.data[M31] + z * this.data[M32] + this.data[M33]); return new Vec3( (x * this.data[M00] + y * this.data[M01] + z * this.data[M02] + this.data[M03]) * rcpw, (x * this.data[M10] + y * this.data[M11] + z * this.data[M12] + this.data[M13]) * rcpw, (x * this.data[M20] + y * this.data[M21] + z * this.data[M22] + this.data[M23]) * rcpw); }
public Vec3 func_72345_a(double p_72345_1_, double p_72345_3_, double p_72345_5_) { Vec3 vec3; if (field_72347_d >= field_72350_c.size()) { vec3 = new Vec3(p_72345_1_, p_72345_3_, p_72345_5_); field_72350_c.add(vec3); } else { vec3 = (Vec3) field_72350_c.get(field_72347_d); vec3.func_72439_b(p_72345_1_, p_72345_3_, p_72345_5_); } field_72347_d++; return vec3; }
/** Execute a one shot task or start executing a continuous task */ public void startExecuting() { this.insidePosX = -1; if (this.entityObj.getDistanceSq( (double) this.doorInfo.getInsidePosX(), (double) this.doorInfo.posY, (double) this.doorInfo.getInsidePosZ()) > 256.0D) { Vec3 var1 = RandomPositionGenerator.func_75464_a( this.entityObj, 14, 3, Vec3.func_72437_a() .func_72345_a( (double) this.doorInfo.getInsidePosX() + 0.5D, (double) this.doorInfo.getInsidePosY(), (double) this.doorInfo.getInsidePosZ() + 0.5D)); if (var1 != null) { this.entityObj.getNavigator().tryMoveToXYZ(var1.xCoord, var1.yCoord, var1.zCoord, 0.3F); } } else { this.entityObj .getNavigator() .tryMoveToXYZ( (double) this.doorInfo.getInsidePosX() + 0.5D, (double) this.doorInfo.getInsidePosY(), (double) this.doorInfo.getInsidePosZ() + 0.5D, 0.3F); } }
@SideOnly(Side.CLIENT) /** Return Vec3D with biome specific fog color */ public Vec3 getFogColor(float par1, float par2) { return Vec3.getVec3Pool() .getVecFromPool(0.20000000298023224D, 0.029999999329447746D, 0.029999999329447746D); }
private void pathFollow() { Vec3 var1 = this.getEntityPosition(); int var2 = this.currentPath.getCurrentPathLength(); for (int var3 = this.currentPath.getCurrentPathIndex(); var3 < this.currentPath.getCurrentPathLength(); ++var3) { if (this.currentPath.getPathPointFromIndex(var3).yCoord != (int) var1.yCoord) { var2 = var3; break; } } float var8 = this.theEntity.width * this.theEntity.width; int var4; for (var4 = this.currentPath.getCurrentPathIndex(); var4 < var2; ++var4) { if (var1.squareDistanceTo(this.currentPath.getVectorFromIndex(this.theEntity, var4)) < (double) var8) { this.currentPath.setCurrentPathIndex(var4 + 1); } } var4 = MathHelper.func_76123_f(this.theEntity.width); int var5 = (int) this.theEntity.height + 1; int var6 = var4; for (int var7 = var2 - 1; var7 >= this.currentPath.getCurrentPathIndex(); --var7) { if (this.isDirectPathBetweenPoints( var1, this.currentPath.getVectorFromIndex(this.theEntity, var7), var4, var5, var6)) { this.currentPath.setCurrentPathIndex(var7); break; } } if (this.totalTicks - this.ticksAtLastPos > 100) { if (var1.squareDistanceTo(this.lastPosCheck) < 2.25D) { this.clearPathEntity(); } this.ticksAtLastPos = this.totalTicks; this.lastPosCheck.xCoord = var1.xCoord; this.lastPosCheck.yCoord = var1.yCoord; this.lastPosCheck.zCoord = var1.zCoord; } }
public MovingObjectPosition(int par1, int par2, int par3, int par4, Vec3 par5Vec3) { typeOfHit = EnumMovingObjectType.TILE; blockX = par1; blockY = par2; blockZ = par3; sideHit = par4; hitVec = Vec3.func_72437_a().func_72345_a(par5Vec3.xCoord, par5Vec3.yCoord, par5Vec3.zCoord); }
@Override public WireframeMesh getWireframeMesh() { if (cachedWire != null) return cachedWire; // This is a dirty hack. // TODO: Remove it! Vec3 vert[] = new Vec3[0]; int[] from = new int[0]; int[] to = new int[0]; if (charges.size() <= 0) { cachedWire = new NullObject().getWireframeMesh(); return cachedWire; } for (Charge c : charges) { double rad = c.w; Sphere s = new Sphere(rad, rad, rad); WireframeMesh wfm = s.getWireframeMesh(); Vec3[] vert2 = new Vec3[vert.length + wfm.vert.length]; int i; for (i = 0; i < vert.length; i++) vert2[i] = vert[i]; for (Vec3 v : wfm.vert) vert2[i++] = v.plus(new Vec3(c.x, c.y, c.z)); int[] from2 = new int[from.length + wfm.from.length]; for (i = 0; i < from.length; i++) from2[i] = from[i]; for (int foreign = 0; foreign < wfm.from.length; foreign++) from2[i++] = wfm.from[foreign] + vert.length; from = from2; int[] to2 = new int[to.length + wfm.to.length]; for (i = 0; i < to.length; i++) to2[i] = to[i]; for (int foreign = 0; foreign < wfm.to.length; foreign++) to2[i++] = wfm.to[foreign] + vert.length; to = to2; vert = vert2; } return (cachedWire = new WireframeMesh(vert, from, to)); }
public void setNormals() { // first get normals for all faces int numFaces = F.size(); for (Face f : F) { Edge e = E.get(f.e); Vec3 v1 = V.get(e.v).coord; e = E.get(e.next); Vec3 v2 = V.get(e.v).coord; e = E.get(e.next); Vec3 v3 = V.get(e.v).coord; // set the normal for this face Vec3 U = Vec3.sub(v2, v1); Vec3 V = Vec3.sub(v3, v1); float nx = U.y * V.z - U.z * V.y; float ny = U.z * V.x - U.x * V.z; float nz = U.x * V.y - U.y * V.x; f.norm = new Vec3(nx, ny, nz); f.norm.normalize(); } // next set normals for all vertices for (Vert v : V) { Vector<Vec3> norms = new Vector<Vec3>(); Edge e = E.get(v.e); Edge eNext = e; // E.get(E.get(e.sym).next); do { // get eNext's Face's norm and store it for combining later norms.add(F.get(eNext.f).norm); eNext = E.get(E.get(eNext.sym).next); } while (e.i != eNext.i); // combine scaled norms here and set v.norm float scale = 1.0f / norms.size(); Vec3 vNorm = new Vec3(0, 0, 0); for (int i = 0; i < norms.size(); i++) vNorm = Vec3.add(vNorm, norms.get(i)); // .scale(scale)); v.norm = vNorm; v.norm.normalize(); } }
public void processKeyboard() { if (isKeyDown(GLFW_KEY_W)) position = position.add(getLookVector()); if (isKeyDown(GLFW_KEY_S)) position = position.add(getLookVector().negate()); if (isKeyDown(GLFW_KEY_A)) position = position.add(getLookVector().cross(new Vec3(0, 1, 0))); if (isKeyDown(GLFW_KEY_D)) position = position.add(getLookVector().cross(new Vec3(0, 1, 0).negate())); if (isKeyDown(GLFW_KEY_LEFT_SHIFT)) position.y += speed; if (isKeyDown(GLFW_KEY_SPACE)) position.y -= speed; }
// get the color value at the given point public Vec3 getColor(Vec3 p, Vec3 n, Vec3 d, Vec3 difCol, Vec3 spCol, int exp) { Vec3 color = new Vec3(0, 0, 0); Vec3 l = getDir().negate(); Ray newRay = new Ray(p, l); HitRecord srec = new HitRecord(); if (Data.getSettings().isA()) { if (Data.hasIntersection(newRay, 0.001, Double.POSITIVE_INFINITY, srec)) { // System.out.println("In shadow"); return color; } else { l = l.normalize(); if (Data.getSettings().isD()) { double nDotl = n.dotProduct(l); color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl))); } if (Data.getSettings().isS()) { Vec3 h = l.subVec(d).normalize(); double nDotH = n.dotProduct(h); color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp))); } } } else { l = l.normalize(); if (Data.getSettings().isD()) { double nDotl = n.dotProduct(l); color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl))); } if (Data.getSettings().isS()) { Vec3 h = l.subVec(d).normalize(); double nDotH = n.dotProduct(h); color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp))); } } return color; }
public void func_70071_h_() { if (!field_70170_p.field_72995_K && (field_70235_a != null && field_70235_a.field_70128_L || !field_70170_p.func_72899_e( (int) field_70165_t, (int) field_70163_u, (int) field_70161_v))) { func_70106_y(); return; } super.func_70071_h_(); func_70015_d(1); if (field_70238_i) { int i = field_70170_p.func_72798_a(field_70231_e, field_70228_f, field_70229_g); if (i == field_70237_h) { field_70236_j++; if (field_70236_j == 600) { func_70106_y(); } return; } field_70238_i = false; field_70159_w *= field_70146_Z.nextFloat() * 0.2F; field_70181_x *= field_70146_Z.nextFloat() * 0.2F; field_70179_y *= field_70146_Z.nextFloat() * 0.2F; field_70236_j = 0; field_70234_an = 0; } else { field_70234_an++; } Vec3 vec3 = Vec3.func_72437_a().func_72345_a(field_70165_t, field_70163_u, field_70161_v); Vec3 vec3_1 = Vec3.func_72437_a() .func_72345_a( field_70165_t + field_70159_w, field_70163_u + field_70181_x, field_70161_v + field_70179_y); MovingObjectPosition movingobjectposition = field_70170_p.func_72933_a(vec3, vec3_1); vec3 = Vec3.func_72437_a().func_72345_a(field_70165_t, field_70163_u, field_70161_v); vec3_1 = Vec3.func_72437_a() .func_72345_a( field_70165_t + field_70159_w, field_70163_u + field_70181_x, field_70161_v + field_70179_y); if (movingobjectposition != null) { vec3_1 = Vec3.func_72437_a() .func_72345_a( movingobjectposition.field_72307_f.field_72450_a, movingobjectposition.field_72307_f.field_72448_b, movingobjectposition.field_72307_f.field_72449_c); } Entity entity = null; List list = field_70170_p.func_72839_b( this, field_70121_D .func_72321_a(field_70159_w, field_70181_x, field_70179_y) .func_72314_b(1.0D, 1.0D, 1.0D)); double d = 0.0D; Iterator iterator = list.iterator(); do { if (!iterator.hasNext()) { break; } Entity entity1 = (Entity) iterator.next(); if (entity1.func_70067_L() && (!entity1.func_70028_i(field_70235_a) || field_70234_an >= 25)) { float f2 = 0.3F; AxisAlignedBB axisalignedbb = entity1.field_70121_D.func_72314_b(f2, f2, f2); MovingObjectPosition movingobjectposition1 = axisalignedbb.func_72327_a(vec3, vec3_1); if (movingobjectposition1 != null) { double d1 = vec3.func_72438_d(movingobjectposition1.field_72307_f); if (d1 < d || d == 0.0D) { entity = entity1; d = d1; } } } } while (true); if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { func_70227_a(movingobjectposition); } field_70165_t += field_70159_w; field_70163_u += field_70181_x; field_70161_v += field_70179_y; float f = MathHelper.func_76133_a(field_70159_w * field_70159_w + field_70179_y * field_70179_y); field_70177_z = (float) ((Math.atan2(field_70159_w, field_70179_y) * 180D) / 3.1415927410125732D); for (field_70125_A = (float) ((Math.atan2(field_70181_x, f) * 180D) / 3.1415927410125732D); field_70125_A - field_70127_C < -180F; field_70127_C -= 360F) {} for (; field_70125_A - field_70127_C >= 180F; field_70127_C += 360F) {} for (; field_70177_z - field_70126_B < -180F; field_70126_B -= 360F) {} for (; field_70177_z - field_70126_B >= 180F; field_70126_B += 360F) {} field_70125_A = field_70127_C + (field_70125_A - field_70127_C) * 0.2F; field_70177_z = field_70126_B + (field_70177_z - field_70126_B) * 0.2F; float f1 = 0.95F; if (func_70090_H()) { for (int j = 0; j < 4; j++) { float f3 = 0.25F; field_70170_p.func_72869_a( "bubble", field_70165_t - field_70159_w * (double) f3, field_70163_u - field_70181_x * (double) f3, field_70161_v - field_70179_y * (double) f3, field_70159_w, field_70181_x, field_70179_y); } f1 = 0.8F; } field_70159_w += field_70232_b; field_70181_x += field_70233_c; field_70179_y += field_70230_d; field_70159_w *= f1; field_70181_x *= f1; field_70179_y *= f1; field_70170_p.func_72869_a( "smoke", field_70165_t, field_70163_u + 0.5D, field_70161_v, 0.0D, 0.0D, 0.0D); func_70107_b(field_70165_t, field_70163_u, field_70161_v); }
/** Returns a vector indicating the direction and intensity of fluid flow. */ private Vec3 getFlowVector(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { Vec3 var5 = Vec3.getVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D); int var6 = this.getEffectiveFlowDecay(par1IBlockAccess, par2, par3, par4); for (int var7 = 0; var7 < 4; ++var7) { int var8 = par2; int var10 = par4; if (var7 == 0) { var8 = par2 - 1; } if (var7 == 1) { var10 = par4 - 1; } if (var7 == 2) { ++var8; } if (var7 == 3) { ++var10; } int var11 = this.getEffectiveFlowDecay(par1IBlockAccess, var8, par3, var10); int var12; if (var11 < 0) { if (!par1IBlockAccess.getBlockMaterial(var8, par3, var10).blocksMovement()) { var11 = this.getEffectiveFlowDecay(par1IBlockAccess, var8, par3 - 1, var10); if (var11 >= 0) { var12 = var11 - (var6 - 8); var5 = var5.addVector( (double) ((var8 - par2) * var12), (double) ((par3 - par3) * var12), (double) ((var10 - par4) * var12)); } } } else if (var11 >= 0) { var12 = var11 - var6; var5 = var5.addVector( (double) ((var8 - par2) * var12), (double) ((par3 - par3) * var12), (double) ((var10 - par4) * var12)); } } if (par1IBlockAccess.getBlockMetadata(par2, par3, par4) >= 8) { boolean var13 = false; if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3, par4 - 1, 2)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3, par4 + 1, 3)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2 - 1, par3, par4, 4)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2 + 1, par3, par4, 5)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3 + 1, par4 - 1, 2)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3 + 1, par4 + 1, 3)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2 - 1, par3 + 1, par4, 4)) { var13 = true; } if (var13 || this.isBlockSolid(par1IBlockAccess, par2 + 1, par3 + 1, par4, 5)) { var13 = true; } if (var13) { var5 = var5.normalize().addVector(0.0D, -6.0D, 0.0D); } } var5 = var5.normalize(); return var5; }
private Vec3 getEntityPosition() { return Vec3.func_72437_a() .func_72345_a(this.theEntity.posX, (double) this.getPathableYPos(), this.theEntity.posZ); }
/** Called to update the entity's position/logic. */ @Override public void onUpdate() { super.onUpdate(); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) ((Math.atan2(this.motionX, this.motionZ) * 180D) / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) ((Math.atan2(this.motionY, f) * 180D) / Math.PI); } int i = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); if (i > 0) { Block.blocksList[i].setBlockBoundsBasedOnState( this.worldObj, this.xTile, this.yTile, this.zTile); AxisAlignedBB axisalignedbb = Block.blocksList[i].getCollisionBoundingBoxFromPool( this.worldObj, this.xTile, this.yTile, this.zTile); if (axisalignedbb != null && axisalignedbb.isVecInside( Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ))) { this.inGround = true; } } if (this.arrowShake > 0) { this.arrowShake--; } if (this.inGround) { int j = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); if (j != this.inTile || k != this.inData) { this.inGround = false; this.motionX *= this.rand.nextFloat() * 0.2F; this.motionY *= this.rand.nextFloat() * 0.2F; this.motionZ *= this.rand.nextFloat() * 0.2F; this.ticksInGround = 0; this.ticksInAir = 0; return; } this.ticksInGround++; if (this.ticksInGround == 1200) { setDead(); } return; } this.ticksInAir++; Vec3 vec3 = Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ); Vec3 vec3_1 = Vec3.func_72437_a() .func_72345_a( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks_do_do(vec3, vec3_1, false, true); vec3 = Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ); vec3_1 = Vec3.func_72437_a() .func_72345_a( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec3_1 = Vec3.func_72437_a() .func_72345_a( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; Iterator iterator = list.iterator(); do { if (!iterator.hasNext()) { break; } Entity entity1 = (Entity) iterator.next(); if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) { float f5 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f5, f5, f5); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec3_1); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d || d == 0.0D) { entity = entity1; d = d1; } } } } while (true); if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { float f1 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); int i1 = MathHelper.func_76143_f(f1 * this.damage); if (func_70241_g()) { i1 += this.rand.nextInt(i1 / 2 + 2); } DamageSource damagesource = null; if (this.shootingEntity == null) { damagesource = DamageSource.causeArrowDamage(this, this); } else { damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity); } if (isBurning()) { movingobjectposition.entityHit.setFire(5); } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) { if (movingobjectposition.entityHit instanceof EntityLiving) { ((EntityLiving) movingobjectposition.entityHit).arrowHitTempCounter++; if (this.knockbackStrength > 0) { float f7 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); if (f7 > 0.0F) { movingobjectposition.entityHit.addVelocity( (this.motionX * this.knockbackStrength * 0.60000002384185791D) / f7, 0.10000000000000001D, (this.motionZ * this.knockbackStrength * 0.60000002384185791D) / f7); } } } this.worldObj.playSoundAtEntity( this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); setDead(); } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180F; this.prevRotationYaw += 180F; this.ticksInAir = 0; } } else { this.xTile = movingobjectposition.blockX; this.yTile = movingobjectposition.blockY; this.zTile = movingobjectposition.blockZ; this.inTile = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); this.motionX = (float) (movingobjectposition.hitVec.xCoord - this.posX); this.motionY = (float) (movingobjectposition.hitVec.yCoord - this.posY); this.motionZ = (float) (movingobjectposition.hitVec.zCoord - this.posZ); float f2 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= (this.motionX / f2) * 0.05000000074505806D; this.posY -= (this.motionY / f2) * 0.05000000074505806D; this.posZ -= (this.motionZ / f2) * 0.05000000074505806D; this.worldObj.playSoundAtEntity( this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); this.inGround = true; this.arrowShake = 7; func_70243_d(false); } } if (func_70241_g()) { for (int l = 0; l < 4; l++) { this.worldObj.spawnParticle( "crit", this.posX + (this.motionX * l) / 4D, this.posY + (this.motionY * l) / 4D, this.posZ + (this.motionZ * l) / 4D, -this.motionX, -this.motionY + 0.20000000000000001D, -this.motionZ); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f3 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) ((Math.atan2(this.motionX, this.motionZ) * 180D) / Math.PI); for (this.rotationPitch = (float) ((Math.atan2(this.motionY, f3) * 180D) / Math.PI); this.rotationPitch - this.prevRotationPitch < -180F; this.prevRotationPitch -= 360F) {} for (; this.rotationPitch - this.prevRotationPitch >= 180F; this.prevRotationPitch += 360F) {} for (; this.rotationYaw - this.prevRotationYaw < -180F; this.prevRotationYaw -= 360F) {} for (; this.rotationYaw - this.prevRotationYaw >= 180F; this.prevRotationYaw += 360F) {} this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f4 = 0.99F; float f6 = 0.05F; if (isInWater()) { for (int j1 = 0; j1 < 4; j1++) { float f8 = 0.25F; this.worldObj.spawnParticle( "bubble", this.posX - this.motionX * f8, this.posY - this.motionY * f8, this.posZ - this.motionZ * f8, this.motionX, this.motionY, this.motionZ); } f4 = 0.8F; } this.motionX *= f4; this.motionY *= f4; this.motionZ *= f4; this.motionY -= f6; setPosition(this.posX, this.posY, this.posZ); func_70017_D(); }
@Override public void onUpdate() { super.onUpdate(); if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); prevRotationPitch = rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D); } if (arrowShake > 0) { arrowShake--; } if (inGround) { int i = worldObj.getBlockId(xTile, yTile, zTile); int j = worldObj.getBlockMetadata(xTile, yTile, zTile); if (i != inTile || j != inData) { inGround = false; motionX *= rand.nextFloat() * 0.2F; motionY *= rand.nextFloat() * 0.2F; motionZ *= rand.nextFloat() * 0.2F; ticksInGround = 0; ticksFlying = 0; } else { ticksInGround++; tickInGround(); if (ticksInGround == ttlInGround) { setDead(); } return; } } else { ticksFlying++; } tickFlying(); Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ); Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1); vec3d = Vec3.createVectorHelper(posX, posY, posZ); vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); if (movingobjectposition != null) { vec3d1 = Vec3.createVectorHelper( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity( this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; for (int k = 0; k < list.size(); k++) { Entity entity2 = (Entity) list.get(k); if (!canBeShot(entity2)) { continue; } float f3 = hitBox; AxisAlignedBB axisalignedbb = entity2.boundingBox.expand(f3, f3, f3); MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } double d1 = vec3d.distanceTo(movingobjectposition1.hitVec); if (d1 < d || d == 0.0D) { entity = entity2; d = d1; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && (entity != shooter || ticksFlying > 2) && (onHit())) { Entity entity1 = movingobjectposition.entityHit; if (entity1 != null) { if (!worldObj.isRemote) { if (onHitTarget(entity1) && hasTorchAttachment == false) { if ((entity1 instanceof EntityLiving) && !(entity1 instanceof EntityPlayer)) { ++((EntityLiving) entity1).arrowHitTempCounter; } entity1.attackEntityFrom( DamageSource.causePlayerDamage((EntityPlayer) shooter), this.arrowCritical ? dmg * 2 : dmg); setDead(); } } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; inTile = worldObj.getBlockId(xTile, yTile, zTile); inData = worldObj.getBlockMetadata(xTile, yTile, zTile); Block block = Block.blocksList[inTile]; if (block != null && !(block instanceof BlockFlower)) { if (onHitBlock(movingobjectposition)) { motionX = (float) (movingobjectposition.hitVec.xCoord - posX); motionY = (float) (movingobjectposition.hitVec.yCoord - posY); motionZ = (float) (movingobjectposition.hitVec.zCoord - posZ); float f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= (motionX / (double) f2) * 0.05000000074505806D; posY -= (motionY / (double) f2) * 0.05000000074505806D; posZ -= (motionZ / (double) f2) * 0.05000000074505806D; inGround = true; arrowShake = 7; this.arrowCritical = false; } } } } if (movingobjectposition != null && !worldObj.isRemote) { Entity entity1 = movingobjectposition.entityHit; if (entity1 != null && entity1 instanceof EntityLiving && entity1 != shooter) { if (hasExplosiveAttachment && ((EntityLiving) entity1).arrowHitTempCounter < 10) { this.worldObj.createExplosion( this, (int) Math.floor(((EntityLiving) entity1).posX), (int) ((EntityLiving) entity1).posY, (int) Math.floor(((EntityLiving) entity1).posZ), 1); } if (hasIceAttachment) { ((EntityLiving) entity1) .addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 280, 3)); } if (hasPoisonAttachment) { ((EntityLiving) entity1).addPotionEffect(new PotionEffect(Potion.poison.id, 280, 3)); } if (hasLightningAttachment) { this.worldObj.addWeatherEffect( new EntityLightningBolt(this.worldObj, entity1.posX, entity1.posY, entity1.posZ)); this.setDead(); } } } FMLLog.info("" + this.inGround); posX += motionX; posZ += motionZ; posY += motionY; handleMotionUpdate(); float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); for (rotationPitch = (float) ((Math.atan2(motionY, f1) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) {} for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {} for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {} for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {} rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; setPosition(posX, posY, posZ); }
public class PathNavigate { private EntityLiving theEntity; private World worldObj; /** The PathEntity being followed. */ private PathEntity currentPath; private float speed; /** * The number of blocks (extra) +/- in each axis that get pulled out as cache for the pathfinder's * search space */ private float pathSearchRange; private boolean noSunPathfind = false; /** Time, in number of ticks, following the current path */ private int totalTicks; /** The time when the last position check was done (to detect successful movement) */ private int ticksAtLastPos; /** * Coordinates of the entity's position last time a check was done (part of monitoring getting * 'stuck') */ private Vec3 lastPosCheck = Vec3.createVectorHelper(0.0D, 0.0D, 0.0D); /** Specifically, if a wooden door block is even considered to be passable by the pathfinder */ private boolean canPassOpenWoodenDoors = true; /** If door blocks are considered passable even when closed */ private boolean canPassClosedWoodenDoors = false; /** If water blocks are avoided (at least by the pathfinder) */ private boolean avoidsWater = false; /** * If the entity can swim. Swimming AI enables this and the pathfinder will also cause the entity * to swim straight upwards when underwater */ private boolean canSwim = false; public PathNavigate(EntityLiving par1EntityLiving, World par2World, float par3) { this.theEntity = par1EntityLiving; this.worldObj = par2World; this.pathSearchRange = par3; } public void setAvoidsWater(boolean par1) { this.avoidsWater = par1; } public boolean getAvoidsWater() { return this.avoidsWater; } public void setBreakDoors(boolean par1) { this.canPassClosedWoodenDoors = par1; } /** Sets if the entity can enter open doors */ public void setEnterDoors(boolean par1) { this.canPassOpenWoodenDoors = par1; } /** Returns true if the entity can break doors, false otherwise */ public boolean getCanBreakDoors() { return this.canPassClosedWoodenDoors; } /** Sets if the path should avoid sunlight */ public void setAvoidSun(boolean par1) { this.noSunPathfind = par1; } /** Sets the speed */ public void setSpeed(float par1) { this.speed = par1; } /** Sets if the entity can swim */ public void setCanSwim(boolean par1) { this.canSwim = par1; } /** Returns the path to the given coordinates */ public PathEntity getPathToXYZ(double par1, double par3, double par5) { return !this.canNavigate() ? null : this.worldObj.getEntityPathToXYZ( this.theEntity, MathHelper.floor_double(par1), (int) par3, MathHelper.floor_double(par5), this.pathSearchRange, this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim); } /** Try to find and set a path to XYZ. Returns true if successful. */ public boolean tryMoveToXYZ(double par1, double par3, double par5, float par7) { PathEntity var8 = this.getPathToXYZ( (double) MathHelper.floor_double(par1), (double) ((int) par3), (double) MathHelper.floor_double(par5)); return this.setPath(var8, par7); } /** Returns the path to the given EntityLiving */ public PathEntity getPathToEntityLiving(EntityLiving par1EntityLiving) { return !this.canNavigate() ? null : this.worldObj.getPathEntityToEntity( this.theEntity, par1EntityLiving, this.pathSearchRange, this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim); } /** Try to find and set a path to EntityLiving. Returns true if successful. */ public boolean tryMoveToEntityLiving(EntityLiving par1EntityLiving, float par2) { PathEntity var3 = this.getPathToEntityLiving(par1EntityLiving); return var3 != null ? this.setPath(var3, par2) : false; } /** * sets the active path data if path is 100% unique compared to old path, checks to adjust path * for sun avoiding ents and stores end coords */ public boolean setPath(PathEntity par1PathEntity, float par2) { if (par1PathEntity == null) { this.currentPath = null; return false; } else { if (!par1PathEntity.isSamePath(this.currentPath)) { this.currentPath = par1PathEntity; } if (this.noSunPathfind) { this.removeSunnyPath(); } if (this.currentPath.getCurrentPathLength() == 0) { return false; } else { this.speed = par2; Vec3 var3 = this.getEntityPosition(); this.ticksAtLastPos = this.totalTicks; this.lastPosCheck.xCoord = var3.xCoord; this.lastPosCheck.yCoord = var3.yCoord; this.lastPosCheck.zCoord = var3.zCoord; return true; } } } /** gets the actively used PathEntity */ public PathEntity getPath() { return this.currentPath; } public void onUpdateNavigation() { ++this.totalTicks; if (!this.noPath()) { if (this.canNavigate()) { this.pathFollow(); } if (!this.noPath()) { Vec3 var1 = this.currentPath.getPosition(this.theEntity); if (var1 != null) { this.theEntity .getMoveHelper() .setMoveTo(var1.xCoord, var1.yCoord, var1.zCoord, this.speed); } } } } private void pathFollow() { Vec3 var1 = this.getEntityPosition(); int var2 = this.currentPath.getCurrentPathLength(); for (int var3 = this.currentPath.getCurrentPathIndex(); var3 < this.currentPath.getCurrentPathLength(); ++var3) { if (this.currentPath.getPathPointFromIndex(var3).yCoord != (int) var1.yCoord) { var2 = var3; break; } } float var8 = this.theEntity.width * this.theEntity.width; int var4; for (var4 = this.currentPath.getCurrentPathIndex(); var4 < var2; ++var4) { if (var1.squareDistanceTo(this.currentPath.getVectorFromIndex(this.theEntity, var4)) < (double) var8) { this.currentPath.setCurrentPathIndex(var4 + 1); } } var4 = MathHelper.func_76123_f(this.theEntity.width); int var5 = (int) this.theEntity.height + 1; int var6 = var4; for (int var7 = var2 - 1; var7 >= this.currentPath.getCurrentPathIndex(); --var7) { if (this.isDirectPathBetweenPoints( var1, this.currentPath.getVectorFromIndex(this.theEntity, var7), var4, var5, var6)) { this.currentPath.setCurrentPathIndex(var7); break; } } if (this.totalTicks - this.ticksAtLastPos > 100) { if (var1.squareDistanceTo(this.lastPosCheck) < 2.25D) { this.clearPathEntity(); } this.ticksAtLastPos = this.totalTicks; this.lastPosCheck.xCoord = var1.xCoord; this.lastPosCheck.yCoord = var1.yCoord; this.lastPosCheck.zCoord = var1.zCoord; } } /** If null path or reached the end */ public boolean noPath() { return this.currentPath == null || this.currentPath.isFinished(); } /** sets active PathEntity to null */ public void clearPathEntity() { this.currentPath = null; } private Vec3 getEntityPosition() { return Vec3.func_72437_a() .func_72345_a(this.theEntity.posX, (double) this.getPathableYPos(), this.theEntity.posZ); } /** Gets the safe pathing Y position for the entity depending on if it can path swim or not */ private int getPathableYPos() { if (this.theEntity.isInWater() && this.canSwim) { int var1 = (int) this.theEntity.boundingBox.minY; int var2 = this.worldObj.getBlockId( MathHelper.floor_double(this.theEntity.posX), var1, MathHelper.floor_double(this.theEntity.posZ)); int var3 = 0; do { if (var2 != Block.waterMoving.blockID && var2 != Block.waterStill.blockID) { return var1; } ++var1; var2 = this.worldObj.getBlockId( MathHelper.floor_double(this.theEntity.posX), var1, MathHelper.floor_double(this.theEntity.posZ)); ++var3; } while (var3 <= 16); return (int) this.theEntity.boundingBox.minY; } else { return (int) (this.theEntity.boundingBox.minY + 0.5D); } } /** If on ground or swimming and can swim */ private boolean canNavigate() { return this.theEntity.onGround || this.canSwim && this.isInFluid(); } /** Returns true if the entity is in water or lava, false otherwise */ private boolean isInFluid() { return this.theEntity.isInWater() || this.theEntity.handleLavaMovement(); } /** Trims path data from the end to the first sun covered block */ private void removeSunnyPath() { if (!this.worldObj.canBlockSeeTheSky( MathHelper.floor_double(this.theEntity.posX), (int) (this.theEntity.boundingBox.minY + 0.5D), MathHelper.floor_double(this.theEntity.posZ))) { for (int var1 = 0; var1 < this.currentPath.getCurrentPathLength(); ++var1) { PathPoint var2 = this.currentPath.getPathPointFromIndex(var1); if (this.worldObj.canBlockSeeTheSky(var2.xCoord, var2.yCoord, var2.zCoord)) { this.currentPath.setCurrentPathLength(var1 - 1); return; } } } } /** * Returns true when an entity of specified size could safely walk in a straight line between the * two points. Args: pos1, pos2, entityXSize, entityYSize, entityZSize */ private boolean isDirectPathBetweenPoints( Vec3 par1Vec3, Vec3 par2Vec3, int par3, int par4, int par5) { int var6 = MathHelper.floor_double(par1Vec3.xCoord); int var7 = MathHelper.floor_double(par1Vec3.zCoord); double var8 = par2Vec3.xCoord - par1Vec3.xCoord; double var10 = par2Vec3.zCoord - par1Vec3.zCoord; double var12 = var8 * var8 + var10 * var10; if (var12 < 1.0E-8D) { return false; } else { double var14 = 1.0D / Math.sqrt(var12); var8 *= var14; var10 *= var14; par3 += 2; par5 += 2; if (!this.isSafeToStandAt( var6, (int) par1Vec3.yCoord, var7, par3, par4, par5, par1Vec3, var8, var10)) { return false; } else { par3 -= 2; par5 -= 2; double var16 = 1.0D / Math.abs(var8); double var18 = 1.0D / Math.abs(var10); double var20 = (double) (var6 * 1) - par1Vec3.xCoord; double var22 = (double) (var7 * 1) - par1Vec3.zCoord; if (var8 >= 0.0D) { ++var20; } if (var10 >= 0.0D) { ++var22; } var20 /= var8; var22 /= var10; int var24 = var8 < 0.0D ? -1 : 1; int var25 = var10 < 0.0D ? -1 : 1; int var26 = MathHelper.floor_double(par2Vec3.xCoord); int var27 = MathHelper.floor_double(par2Vec3.zCoord); int var28 = var26 - var6; int var29 = var27 - var7; do { if (var28 * var24 <= 0 && var29 * var25 <= 0) { return true; } if (var20 < var22) { var20 += var16; var6 += var24; var28 = var26 - var6; } else { var22 += var18; var7 += var25; var29 = var27 - var7; } } while (this.isSafeToStandAt( var6, (int) par1Vec3.yCoord, var7, par3, par4, par5, par1Vec3, var8, var10)); return false; } } } /** * Returns true when an entity could stand at a position, including solid blocks under the entire * entity. Args: xOffset, yOffset, zOffset, entityXSize, entityYSize, entityZSize, originPosition, * vecX, vecZ */ private boolean isSafeToStandAt( int par1, int par2, int par3, int par4, int par5, int par6, Vec3 par7Vec3, double par8, double par10) { int var12 = par1 - par4 / 2; int var13 = par3 - par6 / 2; if (!this.isPositionClear(var12, par2, var13, par4, par5, par6, par7Vec3, par8, par10)) { return false; } else { for (int var14 = var12; var14 < var12 + par4; ++var14) { for (int var15 = var13; var15 < var13 + par6; ++var15) { double var16 = (double) var14 + 0.5D - par7Vec3.xCoord; double var18 = (double) var15 + 0.5D - par7Vec3.zCoord; if (var16 * par8 + var18 * par10 >= 0.0D) { int var20 = this.worldObj.getBlockId(var14, par2 - 1, var15); if (var20 <= 0) { return false; } Material var21 = Block.blocksList[var20].blockMaterial; if (var21 == Material.water && !this.theEntity.isInWater()) { return false; } if (var21 == Material.lava) { return false; } } } } return true; } } /** * Returns true if an entity does not collide with any solid blocks at the position. Args: * xOffset, yOffset, zOffset, entityXSize, entityYSize, entityZSize, originPosition, vecX, vecZ */ private boolean isPositionClear( int par1, int par2, int par3, int par4, int par5, int par6, Vec3 par7Vec3, double par8, double par10) { for (int var12 = par1; var12 < par1 + par4; ++var12) { for (int var13 = par2; var13 < par2 + par5; ++var13) { for (int var14 = par3; var14 < par3 + par6; ++var14) { double var15 = (double) var12 + 0.5D - par7Vec3.xCoord; double var17 = (double) var14 + 0.5D - par7Vec3.zCoord; if (var15 * par8 + var17 * par10 >= 0.0D) { int var19 = this.worldObj.getBlockId(var12, var13, var14); if (var19 > 0 && !Block.blocksList[var19].getBlocksMovement(this.worldObj, var12, var13, var14)) { return false; } } } } } return true; } }
public void update(int anim, int time) { float dt = (float) viewer.getDelta() * 0.001F; float grav = AnimatedFloat.getValue(gravity, anim, time); float deaccel = AnimatedFloat.getValue(gravity2, anim, time); if (emitterType == 1 || emitterType == 2) { float rate = AnimatedFloat.getValue(emissionRate, anim, time); float life = AnimatedFloat.getValue(lifespan, anim, time); float toSpawn = 0.0F; if (life != 0.0F) toSpawn = (dt * rate) / life + spawnRemainder; else toSpawn = spawnRemainder; if (toSpawn < 1.0F) { spawnRemainder = toSpawn; if (spawnRemainder < 0.0F) spawnRemainder = 0.0F; } else { int spawnCount = (int) toSpawn; if (spawnCount + particles.size() > 1000) spawnCount = 1000 - particles.size(); spawnRemainder = toSpawn - (float) spawnCount; float w = AnimatedFloat.getValue(areaWidth, anim, time) * 0.5F; float l = AnimatedFloat.getValue(areaLength, anim, time) * 0.5F; float speed = AnimatedFloat.getValue(emissionSpeed, anim, time); float var = AnimatedFloat.getValue(speedVariation, anim, time); float spread = AnimatedFloat.getValue(verticalRange, anim, time); float spread2 = AnimatedFloat.getValue(horizontalRange, anim, time); boolean en = true; int thisAnim = anim; if (thisAnim >= enabled.length) thisAnim = 0; if (enabled.length > 0 && enabled[thisAnim].used) en = enabled[thisAnim].getValue(time) != 0; if (en) { for (int i = 0; i < spawnCount; i++) { Particle p; if (emitterType == 1) p = PlaneEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2); else p = SphereEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2); particles.add(p); } } } } float speed = 1.0F; Vec3 t1 = new Vec3(); Vec3 t2 = new Vec3(); Vec3 t3 = new Vec3(); Point4f d = new Point4f(); Point4f c[] = new Point4f[3]; for (int i = 0; i < 3; i++) c[i] = new Point4f(); for (int i = 0; i < particles.size(); ) { Particle p = (Particle) particles.get(i); p.speed.add( Vec3.sub(Vec3.scale(p.down, grav * dt, t1), Vec3.scale(p.dir, deaccel * dt, t2), t3)); if (slowdown > 0.0F) speed = (float) Math.exp(-1F * slowdown * p.life); p.pos.add(Vec3.scale(p.speed, speed * dt, t1)); p.life += dt; float lifePos = p.life / p.maxLife; float s1 = size.data[0].x; float s2 = 0.0F; float s3 = 0.0F; if (size.data.length > 1) s2 = size.data[1].x; else s2 = s1; if (size.data.length > 2) s3 = size.data[2].x; else s3 = s2; p.size = lifeInterp(lifePos, 0.5F, s1 * scale.x, s2 * scale.y, s3 * scale.z); int limit = Math.min(3, color.data.length); for (int j = 0; j < limit; j++) { Point3f t = color.data[j]; c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F); } if (limit < 3) { Point3f t = color.data[limit - 1]; for (int j = limit - 1; j < 3; j++) c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F); } lifeInterp(lifePos, 0.5F, c[0], c[1], c[2], d); p.color.set(d); if (lifePos >= 1.0F) particles.remove(i); else i++; } }
public void draw(GL2 gl) { if (particles.size() == 0) return; switch (blendMode) { case 0: // '\0' gl.glDisable(3042); gl.glDisable(3008); break; case 1: // '\001' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(768, 1); break; case 2: // '\002' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(770, 1); break; case 3: // '\003' gl.glDisable(3042); gl.glEnable(3008); break; case 4: // '\004' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(770, 1); break; } gl.glBindTexture(3553, model.mMaterials[texture].mTextureId); gl.glPushMatrix(); if (particleType == 0 || particleType == 2) { if ((flags & 0x1000) == 0) { Vec3 view = new Vec3(viewer.getCamera().getPosition()); view.normalize(); Vec3 right = Vec3.cross(view, new Vec3(0.0F, 0.0F, 1.0F)).normalize(); Vec3 up = Vec3.cross(right, view).normalize(); int tcStart = 0; if (flags == 0x40019) tcStart++; gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 cPos = new Vec3(); Vec3 ofs = new Vec3(); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile < texCoords.size()) { gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(right, up, ofs); cPos.set(p.pos); Vec3.sub(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[tcStart % 4].x, tc[tcStart % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.sub(right, up, ofs); Vec3.add(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 1) % 4].x, tc[(tcStart + 1) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(right, up, ofs); Vec3.add(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 2) % 4].x, tc[(tcStart + 2) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.sub(right, up, ofs); Vec3.sub(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 3) % 4].x, tc[(tcStart + 3) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); } } gl.glEnd(); } else { gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 ofs = new Vec3(); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile < texCoords.size()) { gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(p.pos, Vec3.scale(p.corners[0], p.size, ofs), pos); gl.glTexCoord2f(tc[0].x, tc[0].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[1], p.size, ofs), pos); gl.glTexCoord2f(tc[1].x, tc[1].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[2], p.size, ofs), pos); gl.glTexCoord2f(tc[2].x, tc[2].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[3], p.size, ofs), pos); gl.glTexCoord2f(tc[3].x, tc[3].y); gl.glVertex3f(pos.x, pos.y, pos.z); } } gl.glEnd(); } } else if (particleType == 1) { gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 ofs = new Vec3(); float f = 1.0F; Vec3 bv0 = new Vec3(-f, f, 0.0F); Vec3 bv1 = new Vec3(f, f, 0.0F); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile >= texCoords.size() - 1) break; gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(p.pos, Vec3.scale(bv0, p.size, ofs), pos); gl.glTexCoord2f(tc[0].x, tc[0].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(bv1, p.size, ofs), pos); gl.glTexCoord2f(tc[1].x, tc[1].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.origin, Vec3.scale(bv1, p.size, ofs), pos); gl.glTexCoord2f(tc[2].x, tc[2].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.origin, Vec3.scale(bv0, p.size, ofs), pos); gl.glTexCoord2f(tc[3].x, tc[3].y); gl.glVertex3f(pos.x, pos.y, pos.z); } gl.glEnd(); } gl.glPopMatrix(); }
/** * Reflektiert den Vektor an einer Oberfläche mit der Normalen normal. * * @param normal Reflektionsnormale (Einheitsvektor) * @return Reflektierter Vektor */ public final Vec3 reflect(final Vec3 /* normalized */ normal) { return sub(normal.scale(2 * dot(normal))); }
/** * Berechnet den Cosinus des Winkels, den die beiden Vektoren einschließen. * * @param a Zweiter Vektor * @return Cosinus des eingeschlossenen Winkels */ public final float angle(final Vec3 a) { return dot(a) / (norm() * a.norm()); }
public MovingObjectPosition calculateIntercept(Vec3 par1Vec3, Vec3 par2Vec3) { Vec3 var3 = par1Vec3.getIntermediateWithXValue(par2Vec3, this.minX); Vec3 var4 = par1Vec3.getIntermediateWithXValue(par2Vec3, this.maxX); Vec3 var5 = par1Vec3.getIntermediateWithYValue(par2Vec3, this.minY); Vec3 var6 = par1Vec3.getIntermediateWithYValue(par2Vec3, this.maxY); Vec3 var7 = par1Vec3.getIntermediateWithZValue(par2Vec3, this.minZ); Vec3 var8 = par1Vec3.getIntermediateWithZValue(par2Vec3, this.maxZ); if (!this.isVecInYZ(var3)) { var3 = null; } if (!this.isVecInYZ(var4)) { var4 = null; } if (!this.isVecInXZ(var5)) { var5 = null; } if (!this.isVecInXZ(var6)) { var6 = null; } if (!this.isVecInXY(var7)) { var7 = null; } if (!this.isVecInXY(var8)) { var8 = null; } Vec3 var9 = null; if (var3 != null && (var9 == null || par1Vec3.squareDistanceTo(var3) < par1Vec3.squareDistanceTo(var9))) { var9 = var3; } if (var4 != null && (var9 == null || par1Vec3.squareDistanceTo(var4) < par1Vec3.squareDistanceTo(var9))) { var9 = var4; } if (var5 != null && (var9 == null || par1Vec3.squareDistanceTo(var5) < par1Vec3.squareDistanceTo(var9))) { var9 = var5; } if (var6 != null && (var9 == null || par1Vec3.squareDistanceTo(var6) < par1Vec3.squareDistanceTo(var9))) { var9 = var6; } if (var7 != null && (var9 == null || par1Vec3.squareDistanceTo(var7) < par1Vec3.squareDistanceTo(var9))) { var9 = var7; } if (var8 != null && (var9 == null || par1Vec3.squareDistanceTo(var8) < par1Vec3.squareDistanceTo(var9))) { var9 = var8; } if (var9 == null) { return null; } else { byte var10 = -1; if (var9 == var3) { var10 = 4; } if (var9 == var4) { var10 = 5; } if (var9 == var5) { var10 = 0; } if (var9 == var6) { var10 = 1; } if (var9 == var7) { var10 = 2; } if (var9 == var8) { var10 = 3; } return new MovingObjectPosition(0, 0, 0, var10, var9); } }
/** Called to update the entity's position/logic. */ public void onUpdate() { if (!this.worldObj.isRemote && (this.shootingEntity != null && this.shootingEntity.isDead || !this.worldObj.blockExists((int) this.posX, (int) this.posY, (int) this.posZ))) { this.setDead(); } else { super.onUpdate(); this.setFire(1); if (this.inGround) { int var1 = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); if (var1 == this.inTile) { ++this.ticksAlive; if (this.ticksAlive == 600) { this.setDead(); } return; } this.inGround = false; this.motionX *= (double) (this.rand.nextFloat() * 0.2F); this.motionY *= (double) (this.rand.nextFloat() * 0.2F); this.motionZ *= (double) (this.rand.nextFloat() * 0.2F); this.ticksAlive = 0; this.ticksInAir = 0; } else { ++this.ticksInAir; } Vec3 var15 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); Vec3 var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition var3 = this.worldObj.rayTraceBlocks(var15, var2); var15 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (var3 != null) { var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool(var3.hitVec.xCoord, var3.hitVec.yCoord, var3.hitVec.zCoord); } Entity var4 = null; List var5 = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double var6 = 0.0D; for (int var8 = 0; var8 < var5.size(); ++var8) { Entity var9 = (Entity) var5.get(var8); if (var9.canBeCollidedWith() && (!var9.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25)) { float var10 = 0.3F; AxisAlignedBB var11 = var9.boundingBox.expand((double) var10, (double) var10, (double) var10); MovingObjectPosition var12 = var11.calculateIntercept(var15, var2); if (var12 != null) { double var13 = var15.distanceTo(var12.hitVec); if (var13 < var6 || var6 == 0.0D) { var4 = var9; var6 = var13; } } } } if (var4 != null) { var3 = new MovingObjectPosition(var4); } if (var3 != null) { this.onImpact(var3); } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float var16 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F; for (this.rotationPitch = (float) (Math.atan2((double) var16, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float var17 = this.getMotionFactor(); if (this.isInWater()) { for (int var19 = 0; var19 < 4; ++var19) { float var18 = 0.25F; this.worldObj.spawnParticle( "bubble", this.posX - this.motionX * (double) var18, this.posY - this.motionY * (double) var18, this.posZ - this.motionZ * (double) var18, this.motionX, this.motionY, this.motionZ); } var17 = 0.8F; } this.motionX += this.accelerationX; this.motionY += this.accelerationY; this.motionZ += this.accelerationZ; this.motionX *= (double) var17; this.motionY *= (double) var17; this.motionZ *= (double) var17; this.worldObj.spawnParticle( "smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); this.setPosition(this.posX, this.posY, this.posZ); } }
@Override public boolean equals(Object o) { if (o == null || !(o instanceof Vec3)) return false; Vec3 other = (Vec3) o; return super.equals(o) && z == other.getZ(); }