public FXBeam( World par1World, Vector3 position, Vector3 target, float red, float green, float blue, int age, int energy) { super(par1World, position.x, position.y, position.z, 0.0D, 0.0D, 0.0D); this.setRGB(red, green, blue); this.setSize(0.02F, 0.02F); this.noClip = true; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.target = target; float xd = (float) (this.posX - this.target.x); float yd = (float) (this.posY - this.target.y); float zd = (float) (this.posZ - this.target.z); this.length = (float) new Vector3(this).distanceTo(this.target); double var7 = MathHelper.sqrt_double(xd * xd + zd * zd); this.rotYaw = ((float) (Math.atan2(xd, zd) * 180.0D / Math.PI)); this.rotPitch = ((float) (Math.atan2(yd, var7) * 180.0D / Math.PI)); this.prevYaw = this.rotYaw; this.prevPitch = this.rotPitch; this.particleMaxAge = age; this.energy = energy; TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_grey.png"); /** Sets the particle age based on distance. */ EntityLivingBase renderentity = Minecraft.getMinecraft().renderViewEntity; int visibleDistance = 300; if (!Minecraft.getMinecraft().gameSettings.fancyGraphics) { visibleDistance = 100; } if (renderentity.getDistance(this.posX, this.posY, this.posZ) > visibleDistance) { this.particleMaxAge = 0; } // this.pulse = (energy == 0); // if (TEXTURE != null) { // System.out.println("BeamFX created. Texture: " + TEXTURE); // } }
public FXBeam( World par1World, Vector3 position, float yaw, float pitch, float red, float green, float blue, int age, int energy) { super(par1World, position.x, position.y, position.z, 0.0D, 0.0D, 0.0D); a = true; this.setRGB(red, green, blue); this.setSize(0.02F, 0.02F); this.noClip = true; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.length = 200; this.rotYaw = yaw; this.rotPitch = pitch; this.prevYaw = this.rotYaw; this.prevPitch = this.rotPitch; this.particleMaxAge = age; this.energy = energy; if (red == 1 && green == 0 && blue == 0) { TEXTURE = new ResourceLocation("warpdrive", "textures/blocks/energy_grey.png"); } /** Sets the particle age based on distance. */ EntityLivingBase renderentity = Minecraft.getMinecraft().renderViewEntity; int visibleDistance = 300; if (!Minecraft.getMinecraft().gameSettings.fancyGraphics) { visibleDistance = 100; } if (renderentity.getDistance(this.posX, this.posY, this.posZ) > visibleDistance) { this.particleMaxAge = 0; } }
protected void swingThrower() { EntityLivingBase thrower = getThrower(); if (thrower != null && !thrower.onGround && isInGround()) { if (thrower.worldObj.isRemote) { // Determine the swing variables on first swing tick: float x = dataWatcher.getWatchableObjectFloat(HIT_POS_X); float y = dataWatcher.getWatchableObjectFloat(HIT_POS_Y); float z = dataWatcher.getWatchableObjectFloat(HIT_POS_Z); if (swingTicks == 0 && swingVec == null && thrower.motionY < 0) { swingVec = Vec3.createVectorHelper( (x - thrower.posX), y - (thrower.posY + thrower.getEyeHeight()), (z - thrower.posZ)) .normalize(); dy = (thrower.getDistance(x, y, z) / 7.0D); // lower divisor gives bigger change in y // calculate horizontal distance to find initial swing tick position // as distance approaches zero, swing ticks should approach ticks required / 2 // as distance approaches maxDistance, swing ticks should approach zero // this makes sure player's arc is even around pivot point double d = Math.min(thrower.getDistance(x, thrower.posY, z), getMaxDistance()); swingTicks = MathHelper.floor_double(((getMaxDistance() - d) / getMaxDistance()) * 8); } if (swingVec != null) { double sin = Math.sin(10.0D * swingTicks * Math.PI / 180.0D); double f = 0.8D; // arbitrary horizontal motion factor thrower.motionX = (sin * swingVec.xCoord * f); thrower.motionZ = (sin * swingVec.zCoord * f); // y motion needs to oscillate twice as quickly, so it goes up on the other side of the // swing thrower.motionY = dy * -Math.sin(20.0D * swingTicks * Math.PI / 180.0D); // check for horizontal collisions that should stop swinging motion MovingObjectPosition mop = TargetUtils.checkForImpact(worldObj, thrower, this, -(thrower.width / 4.0F), false); if (mop != null && mop.typeOfHit != MovingObjectType.MISS) { thrower.motionX = -thrower.motionX * 0.15D; thrower.motionY = -thrower.motionY * 0.15D; thrower.motionZ = -thrower.motionZ * 0.15D; swingVec = null; } ++swingTicks; // increment at end if (thrower.fallDistance > 0 && thrower.motionY < 0) { // 0.466885F seems to be roughly the amount added each tick while swinging; round for a // little extra server-side padding PacketDispatcher.sendToServer(new FallDistancePacket(thrower, -0.467F)); thrower.fallDistance -= 0.467F; } } else if (swingTicks > 0) { // still let player hang there after colliding, but move towards center if (thrower.getDistanceSq(x, thrower.posY, z) > 1.0D) { double dx = x - thrower.posX; double dz = z - thrower.posZ; thrower.motionX = 0.15D * dx; thrower.motionZ = 0.15D * dz; } if (thrower.posY < (y - (getMaxDistance() / 2.0D))) { thrower.motionY = 0; } ++swingTicks; // increment at end PacketDispatcher.sendToServer(new FallDistancePacket(thrower, 0.0F)); thrower.fallDistance = 0.0F; } } } }