public static float getEyeOffset( final EntityPlayer player ) { assert player.world.isRemote : "Valid only on client"; return (float) ( player.posY + player.getEyeHeight() - player.getDefaultEyeHeight() ); }
/** * Shifts the render for a bauble correctly to the head, including sneaking rotation. * Use for renders under {@link RenderType#HEAD}. */ public static void translateToHeadLevel(EntityPlayer player) { GlStateManager.translate(0, -player.getDefaultEyeHeight(), 0); if (player.isSneaking()) GlStateManager.translate(0.25F * MathHelper.sin(player.rotationPitch * (float) Math.PI / 180), 0.25F * MathHelper.cos(player.rotationPitch * (float) Math.PI / 180), 0F); }
/** * Gets the view point of a player * * @param player player with head * * @return view point of player */ private Vec3d getCorrectedHeadVec( final EntityPlayer player ) { double x = player.posX; double y = player.posY; double z = player.posZ; if( player.world.isRemote ) { // compatibility with eye height changing mods y += player.getEyeHeight() - player.getDefaultEyeHeight(); } else { y += player.getEyeHeight(); if( player instanceof EntityPlayerMP && player.isSneaking() ) { y -= 0.08; } } return new Vec3d( x, y, z ); }
/** * Adjust the players size and eye height to fit to the bat model * * @param player * @param bat */ private void setPlayerBat(EntityPlayer player, boolean bat) { if (bat) updatePlayerBatSize(player); if (bat) player.setPosition(player.posX, player.posY + (PLAYER_HEIGHT - BAT_HEIGHT), player.posZ); player.eyeHeight = (bat ? BAT_EYE_HEIGHT : player.getDefaultEyeHeight()); }
double posZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks; GlStateManager.translate(posX - renderPosX, posY - renderPosY + player.getDefaultEyeHeight(), posZ - renderPosZ);
/** * Shifts the render for a bauble correctly to the head, including sneaking rotation. * Use for renders under {@link RenderType#HEAD}. */ public static void translateToHeadLevel(EntityPlayer player) { GlStateManager.translate(0, -player.getDefaultEyeHeight(), 0); if (player.isSneaking()) GlStateManager.translate(0.25F * MathHelper.sin(player.rotationPitch * (float) Math.PI / 180), 0.25F * MathHelper.cos(player.rotationPitch * (float) Math.PI / 180), 0F); }
/** * Returns a vec representing where the player is looking, capped at maxDistance away. */ public static Pair<Vec3d, Vec3d> getLookVec(EntityPlayer player, double maxDistance) { // Thank you ForgeEssentials Vec3d look = player.getLook(1.0F); Vec3d playerPos = new Vec3d(player.posX, player.posY + (player.getEyeHeight() - player.getDefaultEyeHeight()), player.posZ); Vec3d src = playerPos.add(0, player.getEyeHeight(), 0); Vec3d dest = src.add(look.x * maxDistance, look.y * maxDistance, look.z * maxDistance); return ImmutablePair.of(src, dest); }
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){ ItemStack stack = player.getHeldItem(hand); if(!world.isRemote){ RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100); if(pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)){ int side = pos.sideHit.ordinal(); if(side != -1){ double x = pos.hitVec.x-(side == 4 ? 0.5 : 0)+(side == 5 ? 0.5 : 0); double y = pos.hitVec.y-(side == 0 ? 2.0 : 0)+(side == 1 ? 0.5 : 0); double z = pos.hitVec.z-(side == 2 ? 0.5 : 0)+(side == 3 ? 0.5 : 0); int baseUse = 200; int use = baseUse+(int)(baseUse*pos.hitVec.distanceTo(new Vec3d(player.posX, player.posY+(player.getEyeHeight()-player.getDefaultEyeHeight()), player.posZ))); if(this.getEnergyStored(stack) >= use){ ((EntityPlayerMP)player).connection.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch); player.dismountRidingEntity(); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F); if(!player.capabilities.isCreativeMode){ this.extractEnergyInternal(stack, use, false); player.getCooldownTracker().setCooldown(this, 50); } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } } } player.swingArm(hand); return ActionResult.newResult(EnumActionResult.FAIL, stack); }