public Vec3d getPlayerLook(EntityPlayer player, ItemStack weapon) { Vec3d dir = player.getLookVec(); Vec3d rot = getBeamRotation(weapon, player); dir.rotateYaw((float) rot.x); dir.rotatePitch((float) rot.y); //dir.rotateAroundZ((float)rot.z); return dir; }
public Vec3d getPosition(int i, EnumFacing facing) { if (i < positionsCount) { EnumFacing back = facing.getOpposite(); Vec3d pos = new Vec3d(TileEntityMachineFusionReactorController.positions[i * 2], 0, TileEntityMachineFusionReactorController.positions[(i * 2) + 1]); if (back == EnumFacing.NORTH) { pos = pos.rotateYaw((float) Math.PI); } else if (back == EnumFacing.WEST) { pos = pos.rotateYaw((float) (Math.PI + Math.PI / 2)); } else if (back == EnumFacing.EAST) { pos = pos.rotatePitch((float) (Math.PI / 2)); } else if (back == EnumFacing.UP) { pos = pos.rotatePitch((float) (Math.PI / 2)); } else if (back == EnumFacing.DOWN) { pos = pos.rotatePitch((float) (Math.PI + Math.PI / 2)); } return pos; } return null; }
/** * Find the point [x,y,z] that corresponds to where the arrow has struck the face of the target * @param arrow * @param targetAABB * @return */ private static Vec3d getArrowIntersectionWithTarget(EntityArrow arrow, AxisAlignedBB targetAABB) { // create a vector that points in the same direction as the arrow. // Start with a vector pointing south - this corresponds to 0 degrees yaw and 0 degrees pitch // Then rotate about the x-axis to pitch up or down, then rotate about the y axis to yaw Vec3d arrowDirection = new Vec3d(0.0, 0.0, 10.0); float rotationPitchRadians = (float)Math.toRadians(arrow.rotationPitch); float rotationYawRadians = (float)Math.toRadians(arrow.rotationYaw); arrowDirection = arrowDirection.rotatePitch(-rotationPitchRadians); arrowDirection = arrowDirection.rotateYaw(+rotationYawRadians); Vec3d arrowRayOrigin = arrow.getPositionVector(); Vec3d arrowRayEndpoint = arrowRayOrigin.add(arrowDirection); RayTraceResult hitLocation = targetAABB.calculateIntercept(arrowRayOrigin, arrowRayEndpoint); if (hitLocation == null) return null; if (hitLocation.typeOfHit != RayTraceResult.Type.BLOCK) return null; return hitLocation.hitVec; }
/** * Spawn particle after biting an entity * * @param entityId Id of the entity */ private void spawnBiteParticle(int entityId) { Entity entity = player.world.getEntityByID(entityId); if (entity != null) { UtilLib.spawnParticles(player.world, EnumParticleTypes.CRIT_MAGIC, entity.posX, entity.posY, entity.posZ, player.posX - entity.posX, player.posY - entity.posY, player.posZ - entity.posZ, 10, 1); } for (int j = 0; j < 16; ++j) { Vec3d vec3 = new Vec3d((player.getRNG().nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); vec3 = vec3.rotatePitch(-player.rotationPitch * (float) Math.PI / 180F); vec3 = vec3.rotateYaw(-player.rotationYaw * (float) Math.PI / 180F); double d0 = (double) (-player.getRNG().nextFloat()) * 0.6D - 0.3D; Vec3d vec31 = new Vec3d(((double) player.getRNG().nextFloat() - 0.5D) * 0.3D, d0, 0.6D); vec31 = vec31.rotatePitch(-player.rotationPitch * (float) Math.PI / 180.0F); vec31 = vec31.rotateYaw(-player.rotationYaw * (float) Math.PI / 180.0F); vec31 = vec31.addVector(player.posX, player.posY + (double) player.getEyeHeight(), player.posZ); player.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec31.x, vec31.y, vec31.z, vec3.x, vec3.y + 0.05D, vec3.z, Item.getIdFromItem(Items.APPLE)); } //Play bite sounds. Using this method since it is the only client side method. And this is called on every relevant client anyway player.world.playSound(player.posX, player.posY, player.posZ, ModSounds.player_bite, SoundCategory.PLAYERS, 1.0F, 1.0F, false); }
randomPos = randomPos.rotateYaw((float) (-message.rotationYaw * 0.017453292F)); final double d0 = -RAND.nextDouble() * 0.6D - 0.3D; Vec3d randomOffset = new Vec3d((RAND.nextDouble() - 0.5D) * 0.3D, d0, 0.6D); randomOffset = randomOffset.rotatePitch((float) (-message.rotationPitch * 0.017453292F)); randomOffset = randomOffset.rotateYaw((float) (-message.rotationYaw * 0.017453292F)); randomOffset = randomOffset.add(message.posX, message.posY + message.eyeHeight, message.posZ); if (localStack.getHasSubtypes())
/** * Returns an approximate absolute (world) position of the held item. * This assumes a ModelBiped like model and a normal item. * * @param entity Assumes a ModelBiped like creature * @param mainHand If main hand position * @return Absolute position in the world */ public static @Nonnull Vec3d getItemPosition(EntityLivingBase entity, boolean mainHand) { boolean left = (mainHand ? entity.getPrimaryHand() : entity.getPrimaryHand().opposite()) == EnumHandSide.LEFT; boolean firstPerson = entity instanceof EntityPlayer && ((EntityPlayer) entity).isUser() && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0; Vec3d dir = firstPerson ? entity.getForward() : Vec3d.fromPitchYawVector(new Vec2f(entity.rotationPitch, entity.renderYawOffset)); dir = dir.rotateYaw((float) (Math.PI / 5f) * (left ? 1f : -1f)).scale(0.75f); return dir.addVector(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ); }
Vec3d dir = norm.rotatePitch(pitchOff).rotateYaw(yawOff).normalize(); float pitch = rand.nextFloat(ANGLE_OFFSET_RADS/2, 3*ANGLE_OFFSET_RADS/2) * (rand.nextBoolean() ? 1 : -1); float yaw = rand.nextFloat(ANGLE_OFFSET_RADS/2, 3*ANGLE_OFFSET_RADS/2) * (rand.nextBoolean() ? 1 : -1); Vec3d newTo = bolt.getData().subtract(from.getData()).rotatePitch(pitch).rotateYaw(yaw).normalize().scale(scale).add(bolt.getData()); LightningGenerator.generateOffshoot(rand, bolt, newTo, scale, numBranchesLeft-1);
Vec3d vec3d3 = (new Vec3d(vec3d1.x - vec3d.x, 0.0D, vec3d1.z - vec3d.z)).normalize().rotateYaw(((float)Math.PI / 2F)); double d1 = vec3d2.dotProduct(vec3d3); this.Eye.rotationPointX = MathHelper.sqrt((float)Math.abs(d1)) * 2.0F * (float)Math.signum(d1);
float yaw = (float) (2 * Math.PI * v); Vec3d to = dir.rotatePitch(pitch).rotateYaw(yaw).normalize().scale(rand.nextDouble(maxPotency * 5) < potency ? range : 1.0 / 2.0).add(getPositionVector());
do Vec3d offset = new Vec3d(RandUtil.nextDouble(30, 64), 0, 0).rotateYaw(RandUtil.nextFloat((float) Math.PI * 2)); pos.add(offset.x, offset.y, offset.z); pos.setY(event.player.world.getChunk(pos).getHeight(pos) + 1);