Java Code Examples for net.minecraft.entity.Entity#getEyeHeight()

The following examples show how to use net.minecraft.entity.Entity#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: RotationUtils.java    From LiquidBounce with GNU General Public License v3.0 8 votes vote down vote up
/**
 * Face target with bow
 *
 * @param target your enemy
 * @param silent client side rotations
 * @param predict predict new enemy position
 * @param predictSize predict size of predict
 */
public static void faceBow(final Entity target, final boolean silent, final boolean predict, final float predictSize) {
    final EntityPlayerSP player = mc.thePlayer;

    final double posX = target.posX + (predict ? (target.posX - target.prevPosX) * predictSize : 0) - (player.posX + (predict ? (player.posX - player.prevPosX) : 0));
    final double posY = target.getEntityBoundingBox().minY + (predict ? (target.getEntityBoundingBox().minY - target.prevPosY) * predictSize : 0) + target.getEyeHeight() - 0.15 - (player.getEntityBoundingBox().minY + (predict ? (player.posY - player.prevPosY) : 0)) - player.getEyeHeight();
    final double posZ = target.posZ + (predict ? (target.posZ - target.prevPosZ) * predictSize : 0) - (player.posZ + (predict ? (player.posZ - player.prevPosZ) : 0));
    final double posSqrt = Math.sqrt(posX * posX + posZ * posZ);

    float velocity = LiquidBounce.moduleManager.getModule(FastBow.class).getState() ? 1F : player.getItemInUseDuration() / 20F;
    velocity = (velocity * velocity + velocity * 2) / 3;

    if(velocity > 1) velocity = 1;

    final Rotation rotation = new Rotation(
            (float) (Math.atan2(posZ, posX) * 180 / Math.PI) - 90,
            (float) -Math.toDegrees(Math.atan((velocity * velocity - Math.sqrt(velocity * velocity * velocity * velocity - 0.006F * (0.006F * (posSqrt * posSqrt) + 2 * posY * (velocity * velocity)))) / (0.006F * posSqrt)))
    );

    if(silent)
        setTargetRotation(rotation);
    else
        limitAngleChange(new Rotation(player.rotationYaw, player.rotationPitch), rotation,10 +
                new Random().nextInt(6)).toPlayer(mc.thePlayer);
}
 
Example 2
Source File: SwitchHeldItemAndRotationPacket.java    From Cyberware with MIT License 6 votes vote down vote up
public static void faceEntity(Entity player, Entity entityIn)
{
	double d0 = entityIn.posX - player.posX;
	double d2 = entityIn.posZ - player.posZ;
	double d1;

	if (entityIn instanceof EntityLivingBase)
	{
		EntityLivingBase entitylivingbase = (EntityLivingBase)entityIn;
		d1 = entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() - (player.posY + (double)player.getEyeHeight());
	}
	else
	{
		d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (player.posY + (double)player.getEyeHeight());
	}

	double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
	float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
	float f1 = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
	player.rotationPitch = f1;
	player.rotationYaw = f;
}
 
Example 3
Source File: WorldUtils.java    From WearableBackpacks with MIT License 6 votes vote down vote up
/** Spawns an ItemStack as if it was dropped from an entity on death. */
public static EntityItem dropStackFromEntity(Entity entity, ItemStack stack, float speed) {
	EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer)entity : null);
	EntityItem item;
	if (player == null) {
		double y = entity.posY + entity.getEyeHeight() - 0.3;
		item = spawnItem(entity.world, entity.posX, y, entity.posZ, stack);
		if (item == null) return null;
		item.setPickupDelay(40);
		float f1 = RandomUtils.getFloat(0.5F);
		float f2 = RandomUtils.getFloat((float)Math.PI * 2.0F);
		item.motionX = -Math.sin(f2) * f1;
		item.motionY = 0.2;
		item.motionZ = Math.cos(f2) * f1;
		return item;
	} else item = player.dropItem(stack, true, false);
	if (item != null) {
		item.motionX *= speed / 4;
		item.motionZ *= speed / 4;
	}
	return item;
}
 
Example 4
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public boolean isInsideOfMaterial(Material material, Entity entity)
{
    double d = entity.posY + (double) entity.getEyeHeight();
    int i = MathHelper.floor_double(entity.posX);
    int j = MathHelper.floor_float(MathHelper.floor_double(d));
    int k = MathHelper.floor_double(entity.posZ);
    int l = entity.worldObj.getBlockId(i, j, k);
    if (l != 0 && Block.blocksList[l].blockMaterial == material)
    {
        float f = BlockFluid.getFluidHeightPercent(entity.worldObj.getBlockMetadata(i, j, k)) - 0.1111111F;
        float f1 = (float) (j + 1) - f;
        return d < (double) f1;
    }
    else
    {
        return false;
    }
}
 
Example 5
Source File: AimAssist.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private float[] getAngles(Entity entity) {
    float xDiff = (float) (entity.posX - Wrapper.INSTANCE.player().posX);
    float yDiff = (float) (entity.boundingBox.minY + entity.getEyeHeight() - Wrapper.INSTANCE.player().boundingBox.maxY);
    float zDiff = (float) (entity.posZ - Wrapper.INSTANCE.player().posZ);
    float yaw = (float) (Math.atan2(zDiff, xDiff) * 180.0 / 3.141592653589793 - 90.0);
    float pitch = (float) (-Math.toDegrees(Math.atan(yDiff / Math.sqrt(zDiff * zDiff + xDiff * xDiff))));
    return new float[]{yaw, pitch};
}
 
Example 6
Source File: AimBot.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static void faceEntity(Entity e) {
    double x = e.posX - Wrapper.INSTANCE.player().posX;
    double y = e.posY - Wrapper.INSTANCE.player().posY;
    double z = e.posZ - Wrapper.INSTANCE.player().posZ;
    double d1 = Wrapper.INSTANCE.player().posY + Wrapper.INSTANCE.player().getEyeHeight() - (e.posY + e.getEyeHeight());
    double d3 = MathHelper.sqrt_double((x * x + z * z));
    float f = (float) (Math.atan2(z, x) * 180.0 / 3.141592653589793) - 90.0f;
    float f1 = (float) (-Math.atan2(d1, d3) * 180.0 / 3.141592653589793);
    Wrapper.INSTANCE.player().setPositionAndRotation(Wrapper.INSTANCE.player().posX, Wrapper.INSTANCE.player().posY, Wrapper.INSTANCE.player().posZ, f, -f1);
}
 
Example 7
Source File: SoundPhysics.java    From Sound-Physics with GNU General Public License v3.0 5 votes vote down vote up
public static double calculateEntitySoundOffset(Entity entity, SoundEvent sound)
{
	if (!sound.getSoundName().getResourcePath().matches(".*step.*"))
	{
		//log("Offset entity say sound by " + entity.getEyeHeight());
		return entity.getEyeHeight();
	}
	else
	{
		return 0.0;
	}
	//return 0.0;
}
 
Example 8
Source File: ItemBasicLaserGun.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public RayTraceResult rayTraceEntity(World world, Entity entity) {

		Vec3d vec3d = new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
		Vec3d vec3d1 = entity.getLook(0);
		Vec3d vec3d2 = vec3d.addVector(vec3d1.x * reachDistance, vec3d1.y * reachDistance, vec3d1.z * reachDistance);


		List<Entity> list = world.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().grow(vec3d1.x * reachDistance, vec3d1.y * reachDistance, vec3d1.z * reachDistance).expand(1.0D, 1.0D, 1.0D), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
				{
			public boolean apply(@Nullable Entity p_apply_1_)
			{
				return p_apply_1_ != null && p_apply_1_.canBeCollidedWith();
			}
				}));

		for (int j = 0; j < list.size(); ++j)
		{
			Entity entity1 = (Entity)list.get(j);
			AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow((double)entity1.getCollisionBorderSize());
			RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(vec3d, vec3d2);

			if (axisalignedbb.contains(vec3d))
			{
			}
			else if (raytraceresult != null)
			{
				raytraceresult.entityHit = entity1;
				return raytraceresult;
			}
		}

		return null;
	}
 
Example 9
Source File: EntityEnderminy.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
protected boolean teleportToEntity(Entity p_70816_1_) {
  Vec3d vec3 = new Vec3d(posX - p_70816_1_.posX, getEntityBoundingBox().minY + height / 2.0F - p_70816_1_.posY
      + p_70816_1_.getEyeHeight(), posZ - p_70816_1_.posZ);
  vec3 = vec3.normalize();
  double d0 = 16.0D;
  double d1 = posX + (rand.nextDouble() - 0.5D) * 8.0D - vec3.x * d0;
  double d2 = posY + (rand.nextInt(16) - 8) - vec3.y * d0;
  double d3 = posZ + (rand.nextDouble() - 0.5D) * 8.0D - vec3.z * d0;
  return teleportTo(d1, d2, d3);
}
 
Example 10
Source File: TeleportHelper.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static boolean teleportToEntity(EntityLivingBase entity, Entity toEntity) {
  Vec3d vec3 = new Vec3d(entity.posX - toEntity.posX,
      entity.getEntityBoundingBox().minY + entity.height / 2.0F - toEntity.posY + toEntity.getEyeHeight(), entity.posZ - toEntity.posZ);
  vec3 = vec3.normalize();
  double d0 = 16.0D;
  double d1 = entity.posX + (rand.nextDouble() - 0.5D) * 8.0D - vec3.x * d0;
  double d2 = entity.posY + (rand.nextInt(16) - 8) - vec3.y * d0;
  double d3 = entity.posZ + (rand.nextDouble() - 0.5D) * 8.0D - vec3.z * d0;
  return teleportTo(entity, d1, d2, d3, false);
}
 
Example 11
Source File: BlockQuickSand.java    From Artifacts with MIT License 5 votes vote down vote up
public static boolean headInQuicksand(World world, int x, int y, int z, Entity entity)
{
	x = MathHelper.floor_double(entity.posX);
	int headY = MathHelper.floor_double(entity.posY + entity.getEyeHeight());    	
	z = MathHelper.floor_double(entity.posZ);

	if(world.getBlock(x, headY, z) != BlockQuickSand.instance) {
		return false;
	}
	
	return entity.posY + entity.getEyeHeight() < y + getQuicksandBlockLevel(world, x, y, z);
}
 
Example 12
Source File: MixinEntityRenderer.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "orientCamera", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Vec3;distanceTo(Lnet/minecraft/util/Vec3;)D"), cancellable = true)
private void cameraClip(float partialTicks, CallbackInfo callbackInfo) {
    if (LiquidBounce.moduleManager.getModule(CameraClip.class).getState()) {
        callbackInfo.cancel();

        Entity entity = this.mc.getRenderViewEntity();
        float f = entity.getEyeHeight();

        if(entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
            f = (float) ((double) f + 1D);
            GlStateManager.translate(0F, 0.3F, 0.0F);

            if(!this.mc.gameSettings.debugCamEnable) {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = this.mc.theWorld.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(this.mc.theWorld, blockpos, iblockstate, entity);

                GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
                GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
            }
        }else if(this.mc.gameSettings.thirdPersonView > 0) {
            double d3 = (double) (this.thirdPersonDistanceTemp + (this.thirdPersonDistance - this.thirdPersonDistanceTemp) * partialTicks);

            if(this.mc.gameSettings.debugCamEnable) {
                GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
            }else{
                float f1 = entity.rotationYaw;
                float f2 = entity.rotationPitch;

                if(this.mc.gameSettings.thirdPersonView == 2)
                    f2 += 180.0F;

                if(this.mc.gameSettings.thirdPersonView == 2)
                    GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);

                GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
                GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
                GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
                GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
                GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
            }
        }else
            GlStateManager.translate(0.0F, 0.0F, -0.1F);

        if(!this.mc.gameSettings.debugCamEnable) {
            float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
            float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
            float roll = 0.0F;
            if(entity instanceof EntityAnimal) {
                EntityAnimal entityanimal = (EntityAnimal) entity;
                yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
            }

            Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.mc.theWorld, entity, partialTicks);
            net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup((EntityRenderer) (Object) this, entity, block, partialTicks, yaw, pitch, roll);
            net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
            GlStateManager.rotate(event.roll, 0.0F, 0.0F, 1.0F);
            GlStateManager.rotate(event.pitch, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(event.yaw, 0.0F, 1.0F, 0.0F);
        }

        GlStateManager.translate(0.0F, -f, 0.0F);
        double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks;
        double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks + (double) f;
        double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks;
        this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
    }
}
 
Example 13
Source File: EntityUtils.java    From ForgeHax with MIT License 4 votes vote down vote up
/**
 * Get entities eye position
 */
public static Vec3d getEyePos(Entity entity) {
  return new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
}
 
Example 14
Source File: FxLaser.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void renderParticle(BufferBuilder worldRendererIn, Entity entityIn,
		float partialTicks, float rotationX, float rotationZ,
		float rotationYZ, float rotationXY, float rotationXZ) {
	//worldRendererIn.finishDrawing();
	
	float x = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTicks - interpPosX);
	float y = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTicks - interpPosY);
	float z = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTicks - interpPosZ);
	
	int i = this.getBrightnessForRender(0);
	int j = i >> 16 & 65535;
	int k = i & 65535;
	
	double radius = .3f;
	double fwdOffset = 0.075f;
	double entityOffX = entityFrom.posX - MathHelper.cos((float) (entityFrom.rotationYaw * Math.PI/180f))*radius + fwdOffset*MathHelper.sin((float) (entityFrom.rotationYaw * Math.PI/180f));
	double entityOffY = entityFrom.posY + (entityFrom.getEntityId() == entityIn.getEntityId() && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0 ? entityIn.getEyeHeight() - 0.12f : 1.15f);
	double entityOffZ = entityFrom.posZ - MathHelper.sin((float) (entityFrom.rotationYaw * Math.PI/180f))*radius - fwdOffset*MathHelper.cos((float) (entityFrom.rotationYaw * Math.PI/180f));
	
	
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE, 0, 0);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
	
	BufferBuilder buffer = Tessellator.getInstance().getBuffer();
	buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
	GL11.glLineWidth(5);
	GlStateManager.color(0.8f, 0.2f, 0.2f, .4f);
	
	buffer.pos(entityOffX - entityIn.posX, entityOffY - entityIn.posY, entityOffZ - entityIn.posZ).endVertex();
	buffer.pos(x, y, z).endVertex();
	
	
	Tessellator.getInstance().draw();
	
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_LIGHTING);
	OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 0, 0);
	GlStateManager.color(1, 1, 1, 1);
	GL11.glLineWidth(1);
}
 
Example 15
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Vec3d getEyesVec(Entity entity)
{
    return new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
}
 
Example 16
Source File: RenderWirelessBolt.java    From WirelessRedstone with MIT License 4 votes vote down vote up
private static Vector3 getRelativeViewVector(Vector3 pos)
{
    Entity renderentity = Minecraft.getMinecraft().renderViewEntity;
    return new Vector3((float)renderentity.posX - pos.x, (float)renderentity.posY + renderentity.getEyeHeight() - pos.y, (float)renderentity.posZ - pos.z);
}