private void fire(ItemStack is, World world, EntityPlayer ep, Entity ent) { Vec3 look = ep.getLookVec(); double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, 2); if (!(ent instanceof EntityPlayer) && ReikaWorldHelper.lineOfSight(world, ep, ent)) { ItemStack fl = new ItemStack(Item.flint.itemID, 0, 0); EntityItem ei = new EntityItem( world, looks[0] / look.lengthVector(), looks[1] / look.lengthVector(), looks[2] / look.lengthVector(), fl); ei.delayBeforeCanPickup = 100; ei.motionX = look.xCoord / look.lengthVector(); ei.motionY = look.yCoord / look.lengthVector(); ei.motionZ = look.zCoord / look.lengthVector(); if (!world.isRemote) ei.velocityChanged = true; if (!world.isRemote) world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F); world.spawnEntityInWorld(ei); if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob ReikaParticleHelper.EXPLODE.spawnAt(world, ent.posX, ent.posY, ent.posZ); world.playSoundAtEntity(ent, "random.explode", 1, 1); } ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), this.getAttackDamage(is)); ReikaEntityHelper.knockbackEntity(ep, ent, 0.4); // ent.setRevengeTarget(ep); } }
@SubscribeEvent public void onEntityTick(MinecartUpdateEvent event) { EntityMinecart minecart = event.minecart; if (!canUpdateCart(minecart)) return; Vec3 cartPoint = new Vec3(minecart.posX, minecart.posY, minecart.posZ); List<BehaviourWrapper[]> wrappers = new ArrayList<>(); for (BlockPos pos : BlockPos.getAllInBox( new BlockPos(cartPoint).add(-2, -2, -2), new BlockPos(cartPoint).add(2, 2, 2))) { IBlockState state = minecart.worldObj.getBlockState(pos); wrappers.add(TrackPathProvider.INSTANCE.getTracksAsArray(minecart.worldObj, pos, state)); } double angDiff = Integer.MAX_VALUE; double posDiff = 2; BehaviourWrapper best = null; RayTraceTrackPath bestTrace = null; boolean reverse = false; for (BehaviourWrapper[] wrapperArray : wrappers) { for (BehaviourWrapper w : wrapperArray) { RayTraceTrackPath rayTrace = w.getPath().rayTrace(cartPoint.addVector(0, -0.5, 0), new Vec3(0, 1, 0)); if (rayTrace == null) continue; if (rayTrace.distance > posDiff) continue; boolean rev = false; Vec3 cartAngle = new Vec3(minecart.motionX, minecart.motionY, minecart.motionZ).normalize(); Vec3 pathAngle = w.getPath().direction(rayTrace.interp).normalize(); if (cartAngle.distanceTo(pathAngle) > cartAngle.distanceTo(pathAngle.subtractReverse(new Vec3(0, 0, 0)))) { pathAngle = pathAngle.subtractReverse(new Vec3(0, 0, 0)); rev = true; } double diff = cartAngle.distanceTo(pathAngle); if (diff > angDiff) continue; best = w; posDiff = rayTrace.distance; angDiff = rayTrace.distance; bestTrace = rayTrace; reverse = rev; } } if (best != null && bestTrace != null) { Vec3 pathDir = best.getPath().direction(bestTrace.interp).normalize(); if (reverse) pathDir = pathDir.subtractReverse(new Vec3(0, 0, 0)); Vec3 cartAngle = new Vec3(minecart.motionX, minecart.motionY, minecart.motionZ); double speed = cartAngle.lengthVector(); speed = Math.min(speed, 0.2); minecart.motionX = pathDir.xCoord * speed; minecart.motionY = pathDir.yCoord * speed; minecart.motionZ = pathDir.zCoord * speed; Vec3 pathPos = bestTrace.closestPoint; minecart.posX = pathPos.xCoord + minecart.motionX; minecart.posY = pathPos.yCoord + minecart.motionY; minecart.posZ = pathPos.zCoord + minecart.motionZ; } }
private void doBolt(EntityBallLightning other) { Vec3 vec = ReikaVectorHelper.getVec2Pt(posX, posY, posZ, other.posX, other.posY, other.posZ); // EntityGluon g = new EntityGluon(this, other); // worldObj.spawnEntityInWorld(g); targetColor = other.color; ReikaPacketHelper.sendDataPacket( ChromatiCraft.packetChannel, ChromaPackets.GLUON.ordinal(), new DimensionTarget(worldObj), this.getEntityId(), other.getEntityId()); double len = vec.lengthVector(); for (double i = 0; i < len; i += 0.0625) { double dx = posX - i * vec.xCoord / len; double dy = posY - i * vec.yCoord / len; double dz = posZ - i * vec.zCoord / len; if (worldObj.isRemote) this.gluonParticles(other, dx, dy, dz, (float) (i / len)); if (ChromaOptions.HOSTILEFOREST.getState()) { AxisAlignedBB box = AxisAlignedBB.getBoundingBox(dx, dy, dz, dx, dy, dz).expand(0.5, 0.5, 0.5); List<EntityLivingBase> elb = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, box); for (EntityLivingBase e : elb) { e.attackEntityFrom(DamageSource.generic, isPylonSpawn ? 4 : 1); } } } }
/** * Checks to see if this enderman should be attacking this player */ private boolean shouldAttackPlayer(EntityPlayer p_70821_1_) { Vec3 vec3 = p_70821_1_.getLook(1.0F).normalize(); Vec3 vec31 = new Vec3(this.posX - p_70821_1_.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - (p_70821_1_.posY + (double)p_70821_1_.getEyeHeight()), this.posZ - p_70821_1_.posZ); double d0 = vec31.lengthVector(); vec31 = vec31.normalize(); double d1 = vec3.dotProduct(vec31); return d1 > 1.0D - 0.025D / d0 ? p_70821_1_.canEntityBeSeen(this) : false; }
public static ForgeDirection getDirectionForLookVector(Vec3 lookVec) { double distance = lookVec.lengthVector(); if (lookVec.yCoord > distance * 0.9) { return ForgeDirection.UP; } if (lookVec.yCoord < distance * -0.9) { return ForgeDirection.DOWN; } return getCompassDirectionForLookVector(lookVec); }
@Override public MovingObjectPosition collisionRayTrace(Vec3 startVec, Vec3 endVec) { Block block = new Block(Material.rock); // It's possible for the startVec to be embedded in a lump (causing it // to hit the opposite side), so we must move it farther away Vec3 d = startVec.subtract(endVec); double scale = 5.2; // Diagonal of a 3³. (Was initially using incrScale = 2) // This isn't quite right; the dVector would properly be normalized here // & rescaled to the max diameter. But we can survive without it. // Unnormalized length of dVector is 6m in surviavl mode IIRC. This'll // be way longer than it needs to be. // Why is it + instead of -? Hmm. startVec = startVec.add(SpaceUtil.scale(d, scale)); MovingObjectPosition shortest = null; for (int i = 0; i < parts.size(); i++) { ClayLump lump = parts.get(i); lump.toRotatedBlockBounds(this, block); MovingObjectPosition mop = block.collisionRayTrace(worldObj, pos, startVec, endVec); if (mop != null) { mop.subHit = i; if (shortest == null) { shortest = mop; } else { Vec3 s = shortest.hitVec; Vec3 m = mop.hitVec; s = new Vec3(s.xCoord, s.yCoord, s.zCoord); m = new Vec3(m.xCoord, m.yCoord, m.zCoord); startVec = startVec.subtract(s).subtract(m); if (m.lengthVector() < s.lengthVector()) { shortest = mop; } } } } return shortest; // return super.collisionRayTrace(w, pos, startVec, endVec); }
private boolean isPlayerLookingAtTarget() { // code used from the Enderman player looking code. EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer; World world = FMLClientHandler.instance().getClient().theWorld; Vec3 vec3 = player.getLook(1.0F).normalize(); Vec3 vec31 = Vec3.createVectorHelper( entity.posX - player.posX, entity.boundingBox.minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ); double d0 = vec31.lengthVector(); vec31 = vec31.normalize(); double d1 = vec3.dotProduct(vec31); return d1 > 1.0D - 0.050D / d0; }
public void setTarget(int x, int y, int z) { checkOrigin(); // We target the middle of the block, at the very top. final Vec3 target = Vec3.createVectorHelper(x + 0.5, y + 1, z + 0.5); // Horizontal distance between the origin and target final double distHorizontal = KNOB_LOB_HORIZONTAL_MUL * Math.sqrt( Math.pow(target.xCoord - projectileOrigin.xCoord, 2) + Math.pow(target.zCoord - projectileOrigin.zCoord, 2)); // No vertical multiplier is applied for decline slopes. final double distVertical = Math.max((target.yCoord - projectileOrigin.yCoord) * KNOB_LOB_VERTICAL_MUL, 0); // Calculate the arc of the trajectory final float lobScale = (float) Math.min( KNOB_LOB_MAXIMUM_VALUE, Math.max(KNOB_LOB_MINIMUM_VALUE, KNOB_LOB_BONUS + distHorizontal + distVertical)); // Calculate the velocity of the projectile final Vec3 velocity = TileEntityCannonLogic.calculateTrajectory(projectileOrigin, target, lobScale); // m/s applied to item. final double speed = velocity.lengthVector(); targetSpeed.set(speed); // reverse the vector to angles for cannon model final Vec3 direction = velocity.normalize(); final double pitch = Math.asin(direction.yCoord); final double yaw = Math.atan2(direction.zCoord, direction.xCoord); // Set yaw and pitch targetYaw.set(Math.toDegrees(yaw) + YAW_OFFSET_DEGREES); targetPitch.set(Math.toDegrees(pitch)); currentYaw = targetYaw.get(); currentPitch = targetPitch.get(); // Sync targets sync(); }
@Override public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer ep) { if (is.getItemDamage() <= 0) { this.noCharge(); return is; } this.warnCharge(is); if (!ReikaPlayerAPI.playerHasOrIsCreative(ep, Block.gravel.blockID, -1)) { if (!world.isRemote) world.playAuxSFX(1001, (int) ep.posX, (int) ep.posY, (int) ep.posZ, 1); return is; } for (float i = 1; i <= 128; i += 0.5) { Vec3 look = ep.getLookVec(); double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, i); AxisAlignedBB fov = AxisAlignedBB.getBoundingBox( looks[0] - 0.5, looks[1] - 0.5, looks[2] - 0.5, looks[0] + 0.5, looks[1] + 0.5, looks[2] + 0.5); List infov = world.getEntitiesWithinAABB(EntityLivingBase.class, fov); for (int k = 0; k < infov.size(); k++) { EntityLivingBase ent = (EntityLivingBase) infov.get(k); if (!ep.equals(ent) && this.isEntityAttackable(ent) && ReikaWorldHelper.lineOfSight(world, ep, ent)) { double dist = ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ); double x = ep.posX + look.xCoord; double y = ep.posY + ep.getEyeHeight() + look.yCoord; double z = ep.posZ + look.zCoord; double dx = ent.posX - ep.posX; double dy = ent.posY - ep.posY; double dz = ent.posZ - ep.posZ; if (!world.isRemote) { ItemStack fl = new ItemStack(Item.flint); EntityItem ei = new EntityItem( world, look.xCoord / look.lengthVector() + ep.posX, look.yCoord / look.lengthVector() + ep.posY, look.zCoord / look.lengthVector() + ep.posZ, fl); ei.delayBeforeCanPickup = 100; ei.motionX = dx; ei.motionY = dy + 1; ei.motionZ = dz; // ReikaChatHelper.writeCoords(world, ei.posX, ei.posY, ei.posZ); ei.velocityChanged = true; world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F); ei.lifespan = 5; world.spawnEntityInWorld(ei); if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob // ReikaPacketHelper.sendUpdatePacket(RotaryCraft.packetChannel, // PacketRegistry.GRAVELGUN.getMinValue(), world, (int)ent.posX, (int)ent.posY, // (int)ent.posZ); // world.playSoundAtEntity(ep, "random.explode", 0.25F, 1F); } if (ent instanceof EntityDragon) { EntityDragon ed = (EntityDragon) ent; ed.attackEntityFromPart( ed.dragonPartBody, DamageSource.causePlayerDamage(ep), this.getAttackDamage(is)); } else { int dmg = this.getAttackDamage(is); if (ent instanceof EntityPlayer) { for (int n = 1; n < 5; n++) { ItemRegistry ir = ItemRegistry.getEntry(ent.getCurrentItemOrArmor(n)); if (ir != null) { if (ir.isBedrockArmor()) dmg *= 0.75; } } } ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), dmg); if (dmg >= 500) RotaryAchievements.MASSIVEHIT.triggerAchievement(ep); } if (ent instanceof EntityMob && (ent.isDead || ent.getHealth() <= 0) && ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ) >= 80) RotaryAchievements.GRAVELGUN.triggerAchievement(ep); } // ReikaWorldHelper.spawnParticleLine(world, x, y, z, ent.posX, ent.posY+ent.height/2, // ent.posZ, "crit", 0, 0, 0, 60); for (float t = 0; t < 2; t += 0.05F) world.spawnParticle("crit", x, y, z, dx / dist * t, dy / dist * t, dz / dist * t); } } if (infov.size() > 0 && !(infov.size() == 1 && infov.get(0) instanceof EntityPlayer)) { if (!ep.capabilities.isCreativeMode) ReikaInventoryHelper.findAndDecrStack( Block.gravel.blockID, -1, ep.inventory.mainInventory); return new ItemStack(is.itemID, is.stackSize, is.getItemDamage() - 1); } } return is; }