Java Code Examples for net.minecraft.entity.player.EntityPlayer#getEyeHeight()
The following examples show how to use
net.minecraft.entity.player.EntityPlayer#getEyeHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiamondTofuToolHandler.java From TofuCraftReload with MIT License | 6 votes |
protected static RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) { float f = playerIn.rotationPitch; float f1 = playerIn.rotationYaw; double d0 = playerIn.posX; double d1 = playerIn.posY + (double) playerIn.getEyeHeight(); double d2 = playerIn.posZ; Vec3d vec3d = new Vec3d(d0, d1, d2); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = playerIn.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(); Vec3d vec3d1 = vec3d.addVector((double) f6 * d3, (double) f5 * d3, (double) f7 * d3); return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false); }
Example 2
Source File: ItemBasicLaserGun.java From AdvancedRocketry with MIT License | 6 votes |
@Override protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) { float f = playerIn.rotationPitch; float f1 = playerIn.rotationYaw; double d0 = playerIn.posX; double d1 = playerIn.posY + (double)playerIn.getEyeHeight(); double d2 = playerIn.posZ; Vec3d vec3d = new Vec3d(d0, d1, d2); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = reachDistance; Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3); return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false); }
Example 3
Source File: EntityEnderminy.java From EnderZoo with Creative Commons Zero v1.0 Universal | 6 votes |
/** * Checks to see if this enderman should be attacking this player */ private boolean shouldAttackPlayer(EntityPlayer player) { ItemStack itemstack = player.inventory.armorInventory.get(3); // 3: Helmet, 2: Chestpiece, 1: Legs, 0: Boots if(itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN)) { return false; } else { Vec3d relativePlayerEyePos = new Vec3d( posX - player.posX, getEntityBoundingBox().minY + height / 2.0F - (player.posY + player.getEyeHeight()), posZ - player.posZ); double distance = relativePlayerEyePos.lengthVector(); relativePlayerEyePos = relativePlayerEyePos.normalize(); //NB: inverse of normal enderman, attack when this guy looks at the player instead of the other //way around Vec3d lookVec = getLook(1.0F).normalize(); double dotTangent = -lookVec.dotProduct(relativePlayerEyePos); return dotTangent > 1.0D - 0.025D / distance; } }
Example 4
Source File: RulerRenderer.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public BlockPosAligner(BlockPosEU p1, BlockPosEU p2, EntityPlayer player) { this.playerPos = new double[] { player.posX, player.posY + player.getEyeHeight(), player.posZ }; this.points = new int[][] { { p1.getX(), p1.getY(), p1.getZ() }, { p2.getX(), p2.getY(), p2.getZ() } }; }
Example 5
Source File: RayTracer.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static Vec3 getCorrectedHeadVec(EntityPlayer player) { Vector3 v = Vector3.fromEntity(player); if (player.worldObj.isRemote) { v.y += player.getEyeHeight() - player.getDefaultEyeHeight();//compatibility with eye height changing mods } else { v.y += player.getEyeHeight(); if (player instanceof EntityPlayerMP && player.isSneaking()) v.y -= 0.08; } return v.vec3(); }
Example 6
Source File: MagnetModeHandler.java From NotEnoughItems with MIT License | 4 votes |
@SubscribeEvent @SideOnly (Side.CLIENT) public void clientTickEvent(TickEvent.ClientTickEvent event) { if (event.phase == Phase.END || Minecraft.getMinecraft().world == null) { return; } if (!NEIClientConfig.isMagnetModeEnabled()) { return; } EntityPlayer player = Minecraft.getMinecraft().player; Iterator<EntityItem> iterator = clientMagnetItems.iterator(); while (iterator.hasNext()) { EntityItem item = iterator.next(); if (item.cannotPickup()) { continue; } if (item.isDead) { iterator.remove(); } if (item.getEntityData().getBoolean("PreventRemoteMovement")) { continue; } if (!NEIClientUtils.canItemFitInInventory(player, item.getItem())) { continue; } double dx = player.posX - item.posX; double dy = player.posY + player.getEyeHeight() - item.posY; double dz = player.posZ - item.posZ; double absxz = Math.sqrt(dx * dx + dz * dz); double absy = Math.abs(dy); if (absxz > DISTANCE_XZ || absy > DISTANCE_Y) { continue; } if (absxz > 1) { dx /= absxz; dz /= absxz; } if (absy > 1) { dy /= absy; } double vx = item.motionX + SPEED_XZ * dx; double vy = item.motionY + SPEED_Y * dy; double vz = item.motionZ + SPEED_XZ * dz; double absvxz = Math.sqrt(vx * vx + vz * vz); double absvy = Math.abs(vy); double rationspeedxz = absvxz / MAX_SPEED_XZ; if (rationspeedxz > 1) { vx /= rationspeedxz; vz /= rationspeedxz; } double rationspeedy = absvy / MAX_SPEED_Y; if (rationspeedy > 1) { vy /= rationspeedy; } if (absvxz < 0.2 && absxz < 0.2) { item.setDead(); } item.setVelocity(vx, vy, vz); } }
Example 7
Source File: ItemStaffTeleport.java From mocreaturesdev with GNU General Public License v3.0 | 4 votes |
/** * Called whenever this item is equipped and the right mouse button is * pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer) { /*if(!MoCreatures.isServer()) { return par1ItemStack; }*/ if (entityplayer.ridingEntity != null || entityplayer.riddenByEntity != null) { return par1ItemStack; } double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight(); double coordZ = entityplayer.posZ; double coordX = entityplayer.posX; for (int x = 4; x < 128; x++) { double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x; double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); int iTarget = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)); if (iTarget != 0) { newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1); newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); if (MoCreatures.isServer()) { EntityPlayerMP thePlayer = (EntityPlayerMP) entityplayer; thePlayer.playerNetServerHandler.setPlayerLocation((double)newPosX, (double)newPosY, (double)newPosZ, entityplayer.rotationYaw, entityplayer.rotationPitch); MoCTools.playCustomSound(entityplayer, "appearmagic", entityplayer.worldObj); } MoCreatures.proxy.teleportFX(entityplayer); entityplayer.setItemInUse(par1ItemStack, 200); par1ItemStack.damageItem(1, entityplayer); return par1ItemStack; } } entityplayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); return par1ItemStack; }
Example 8
Source File: ItemBuilderHammer.java From mocreaturesdev with GNU General Public License v3.0 | 4 votes |
/** * Called whenever this item is equipped and the right mouse button is * pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer) { double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight(); double coordZ = entityplayer.posZ; double coordX = entityplayer.posX; int wallBlockID = 0; int newWallBlockID = 0; for (int x = 3; x < 128; x++) { double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x; double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)); if (newWallBlockID == 0) { wallBlockID = newWallBlockID; continue; } if (newWallBlockID != 0 && wallBlockID == 0) { newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1); newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0) { //System.out.println("busy spot!"); return par1ItemStack; } int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true); if (blockInfo[0] != 0) { if (MoCreatures.isServer()) { entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3); Block block = Block.blocksList[blockInfo[0]]; entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); } MoCreatures.proxy.hammerFX(entityplayer); entityplayer.setItemInUse(par1ItemStack, 200); } return par1ItemStack; } } return par1ItemStack; }
Example 9
Source File: ItemOgreHammer.java From mocreaturesdev with GNU General Public License v3.0 | 4 votes |
/** * Called whenever this item is equipped and the right mouse button is * pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer) { double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight(); double coordZ = entityplayer.posZ; double coordX = entityplayer.posX; int wallBlockID = 0; int newWallBlockID = 0; for (int x = 3; x < 128; x++) { double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x; double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x ); newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)); if (newWallBlockID == 0) { wallBlockID = newWallBlockID; continue; } if (newWallBlockID != 0 && wallBlockID == 0) { newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1); newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) ); if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0) { //System.out.println("busy spot!"); return par1ItemStack; } int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true); if (blockInfo[0] != 0) { if (MoCreatures.isServer()) { entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3); Block block = Block.blocksList[blockInfo[0]]; entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); } MoCreatures.proxy.hammerFX(entityplayer); entityplayer.setItemInUse(par1ItemStack, 200); } return par1ItemStack; } } return par1ItemStack; }