Java Code Examples for net.minecraft.entity.player.EntityPlayer.getEyeHeight()

The following are Jave code examples for showing how to use getEyeHeight() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BaseClient   File: EntityEnderman.java   View Source Code Vote up 7 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.armorInventory[3];

    if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
    {
        return false;
    }
    else
    {
        Vec3 vec3 = player.getLook(1.0F).normalize();
        Vec3 vec31 = new Vec3(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec31.lengthVector();
        vec31 = vec31.normalize();
        double d1 = vec3.dotProduct(vec31);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 2
Project: CustomWorldGen   File: Item.java   View Source Code Vote up 6 votes
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 = 5.0D;
    if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
    {
        d3 = ((net.minecraft.entity.player.EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance();
    }
    Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
    return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
 
Example 3
Project: Infernum   File: SpellFireBreath.java   View Source Code Vote up 6 votes
@Override
public void onCastTick(World world, EntityPlayer player, ItemStack stack) {
	if (!world.isRemote) {
		
		if (player.getItemInUseCount() % 2 == 0 && consumePower(player)) {
			Vec3d lookVec = player.getLookVec();
			double x = player.posX + lookVec.xCoord;
			double y = player.posY + lookVec.yCoord + player.getEyeHeight();
			double z = player.posZ + lookVec.zCoord;
			EntityFireBreath fireBreath = new EntityFireBreath(world, player, 5);
			fireBreath.setPosition(x, y, z);
			fireBreath.setAim(player, player.rotationPitch, player.rotationYaw, 1F, 0.1F);
			world.spawnEntity(fireBreath);
		}
	}
}
 
Example 4
Project: DecompiledMinecraft   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.armorInventory[3];

    if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
    {
        return false;
    }
    else
    {
        Vec3 vec3 = player.getLook(1.0F).normalize();
        Vec3 vec31 = new Vec3(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec31.lengthVector();
        vec31 = vec31.normalize();
        double d1 = vec3.dotProduct(vec31);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 5
Project: DecompiledMinecraft   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.armorInventory[3];

    if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
    {
        return false;
    }
    else
    {
        Vec3 vec3 = player.getLook(1.0F).normalize();
        Vec3 vec31 = new Vec3(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec31.lengthVector();
        vec31 = vec31.normalize();
        double d1 = vec3.dotProduct(vec31);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 6
Project: minecraft-quiverbow   File: AI_Targeting.java   View Source Code Vote up 6 votes
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World world, EntityPlayer player, double targetingDistance)
{
	float f = 1.0F;
	float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
	float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
	
	double playerX = player.prevPosX + (player.posX - player.prevPosX) * f;
	double playerY = player.prevPosY + (player.posY - player.prevPosY) * f + (world.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight()); // isRemote check to revert changes to ray trace position due to adding the eye height clientside and player yOffset differences
	double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * f;
	
	Vec3 vecPlayer = Vec3.createVectorHelper(playerX, playerY, playerZ);
	
	float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
	float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
	float f5 = -MathHelper.cos(-f1 * 0.017453292F);
	float f6 = MathHelper.sin(-f1 * 0.017453292F);
	float f7 = f4 * f5;
	float f8 = f3 * f5;
	
	double maxDistance = targetingDistance;
	
	Vec3 vecTarget = vecPlayer.addVector(f7 * maxDistance, f6 * maxDistance, f8 * maxDistance);
	
	return world.func_147447_a(vecPlayer, vecTarget, false, false, true);	// false, true, false
}
 
Example 7
Project: Backmemed   File: Item.java   View Source Code Vote up 6 votes
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 = 5.0D;
    Vec3d vec3d1 = vec3d.addVector((double)f6 * 5.0D, (double)f5 * 5.0D, (double)f7 * 5.0D);
    return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
 
Example 8
Project: BaseClient   File: Item.java   View Source Code Vote up 6 votes
protected MovingObjectPosition getMovingObjectPositionFromPlayer(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;
    Vec3 vec3 = new Vec3(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 = 5.0D;
    Vec3 vec31 = vec3.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
    return worldIn.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
}
 
Example 9
Project: BaseClient   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.armorInventory[3];

    if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
    {
        return false;
    }
    else
    {
        Vec3 vec3 = player.getLook(1.0F).normalize();
        Vec3 vec31 = new Vec3(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec31.lengthVector();
        vec31 = vec31.normalize();
        double d1 = vec3.dotProduct(vec31);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 10
Project: Backmemed   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = (ItemStack)player.inventory.armorInventory.get(3);

    if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
    {
        return false;
    }
    else
    {
        Vec3d vec3d = player.getLook(1.0F).normalize();
        Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec3d1.lengthVector();
        vec3d1 = vec3d1.normalize();
        double d1 = vec3d.dotProduct(vec3d1);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 11
Project: CustomWorldGen   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Checks to see if this enderman should be attacking this player
 */
private boolean shouldAttackPlayer(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.armorInventory[3];

    if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
    {
        return false;
    }
    else
    {
        Vec3d vec3d = player.getLook(1.0F).normalize();
        Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
        double d0 = vec3d1.lengthVector();
        vec3d1 = vec3d1.normalize();
        double d1 = vec3d.dotProduct(vec3d1);
        return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
    }
}
 
Example 12
Project: pnc-repressurized   File: RenderTarget.java   View Source Code Vote up 5 votes
private boolean isPlayerLookingAtTarget() {
    // code used from the Enderman player looking code.
    EntityPlayer player = FMLClientHandler.instance().getClient().player;
    World world = FMLClientHandler.instance().getClient().world;
    Vec3d vec3 = player.getLook(1.0F).normalize();
    Vec3d vec31 = new Vec3d(entity.posX - player.posX, entity.getEntityBoundingBox().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;
}
 
Example 13
Project: ExPetrum   File: PiercingDash.java   View Source Code Vote up 5 votes
@Override
public void onExecutionStart(EntityPlayer player)
{
	ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
	EnumWeaponWeight weight = EnumWeaponWeight.getWeaponWeight(is);
	player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 1F);
	Vec3d look = player.getLookVec().scale(6);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	for (EntityLivingBase target : targets)
	{
		Vec3d targetPos = target.getPositionVector();
		target.knockBack(player, 3, pos.x - targetPos.x, pos.z - targetPos.z);
		double distance = Math.max(0.3, targetPos.distanceTo(pos));
		target.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) (player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue() * (1 - (distance / 6))));
		player.world.playSound(player, target.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1, 2F);
		if (!player.world.isRemote && weight == EnumWeaponWeight.HEAVY && player.world.rand.nextDouble() <= 0.25)
		{
			target.addPotionEffect(new PotionEffect(ExPPotions.stunned, 100, 0, false, false));
		}
	}
	
	player.motionX += look.x / 5;
	player.motionZ += look.z / 5;
	for (int i = 0; i < 50; ++i)
	{
		double randomMagnitude = player.world.rand.nextDouble();
		Vec3d at = new Vec3d(pos.x + look.x * randomMagnitude, pos.y + player.getEyeHeight() - 0.25 + look.y * randomMagnitude, pos.z + look.z * randomMagnitude);
		player.world.spawnParticle(EnumParticleTypes.CRIT, at.x, at.y, at.z, 0, 0, 0);
	}
}
 
Example 14
Project: Whoosh   File: TeleportUtil.java   View Source Code Vote up 5 votes
public static int getFluidCostBlink(World world, EntityPlayer player, int distance) {

        Vec3d eye = new Vec3d(player.posX, player.posY + player.getEyeHeight(), + player.posZ);
        Vec3d look = player.getLookVec();
        Vec3d end = eye.add(new Vec3d(look.x * distance, look.y * distance, look.z * distance));

        RayTraceResult res = world.rayTraceBlocks(eye, end, false, true, false);
        if(res == null) {
           return 0;
        }
        else {
            return ItemTransporter.teleportFluidBlinkCost;
        }
    }
 
Example 15
Project: EndermanEvolution   File: EntityEvolvedEnderman.java   View Source Code Vote up 5 votes
private boolean shouldAttackPlayer(EntityPlayer player) {
	ItemStack itemstack = player.inventory.armorInventory.get(3);

	if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN) || itemstack.getItem() instanceof ItemSkullBase) {
		return false;
	}
	else {
		Vec3d vec3d = player.getLook(1.0F).normalize();
		Vec3d vec3d1 = new Vec3d(posX - player.posX, getEntityBoundingBox().minY + getEyeHeight() - (player.posY + player.getEyeHeight()), posZ - player.posZ);
		double d0 = vec3d1.lengthVector();
		vec3d1 = vec3d1.normalize();
		double d1 = vec3d.dotProduct(vec3d1);
		return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
	}
}
 
Example 16
Project: CustomWorldGen   File: ItemRenderer.java   View Source Code Vote up 4 votes
/**
 * Renders the overlays.
 */
public void renderOverlays(float partialTicks)
{
    GlStateManager.disableAlpha();

    if (this.mc.thePlayer.isEntityInsideOpaqueBlock())
    {
        IBlockState iblockstate = this.mc.theWorld.getBlockState(new BlockPos(this.mc.thePlayer));
        BlockPos overlayPos = new BlockPos(this.mc.thePlayer);
        EntityPlayer entityplayer = this.mc.thePlayer;

        for (int i = 0; i < 8; ++i)
        {
            double d0 = entityplayer.posX + (double)(((float)((i >> 0) % 2) - 0.5F) * entityplayer.width * 0.8F);
            double d1 = entityplayer.posY + (double)(((float)((i >> 1) % 2) - 0.5F) * 0.1F);
            double d2 = entityplayer.posZ + (double)(((float)((i >> 2) % 2) - 0.5F) * entityplayer.width * 0.8F);
            BlockPos blockpos = new BlockPos(d0, d1 + (double)entityplayer.getEyeHeight(), d2);
            IBlockState iblockstate1 = this.mc.theWorld.getBlockState(blockpos);

            if (iblockstate1.getBlock().isVisuallyOpaque())
            {
                iblockstate = iblockstate1;
                overlayPos = blockpos;
            }
        }

        if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE)
        {
            if (!net.minecraftforge.event.ForgeEventFactory.renderBlockOverlay(mc.thePlayer, partialTicks, net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType.BLOCK, iblockstate, overlayPos))
            this.renderBlockInHand(partialTicks, this.mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(iblockstate));
        }
    }

    if (!this.mc.thePlayer.isSpectator())
    {
        if (this.mc.thePlayer.isInsideOfMaterial(Material.WATER))
        {
            if (!net.minecraftforge.event.ForgeEventFactory.renderWaterOverlay(mc.thePlayer, partialTicks))
            this.renderWaterOverlayTexture(partialTicks);
        }

        if (this.mc.thePlayer.isBurning())
        {
            if (!net.minecraftforge.event.ForgeEventFactory.renderFireOverlay(mc.thePlayer, partialTicks))
            this.renderFireInFirstPerson(partialTicks);
        }
    }

    GlStateManager.enableAlpha();
}
 
Example 17
Project: harshencastle   File: MessagePacketRingUpdate.java   View Source Code Vote up 4 votes
@Override
public void onReceived(MessagePacketRingUpdate message, EntityPlayer player) {
	if(message.ringType < 2)
	{
		ArrayList<Item> ringTypeItem = new ArrayList<Item>();
		ringTypeItem.add(HarshenItems.TELERING);
		ringTypeItem.add(HarshenItems.MINERING);
		if(HarshenUtils.containsItem(player,ringTypeItem.get(message.ringType)))
		{
			World world = player.world;
			Vec3d vec = new Vec3d(player.posX + (player.getLookVec().x * 4f),
					player.posY + (player.getLookVec().y * 4f), player.posZ + (player.getLookVec().z* 4f));
			BlockPos blockpos = message.ringType == 0? HarshenUtils.getTopBlock(world, vec) : HarshenUtils.getBottomBlockAir(world, vec);
			Vec3d vecPos = new Vec3d(blockpos).addVector(0.5, 0, 0.5);
			if(blockpos.getY() != -1 && player.getFoodStats().getFoodLevel() > 0)
			{
				((EntityPlayerMP)player).velocityChanged = true;
				((EntityPlayerMP)player).fallDistance = 0;
				HarshenNetwork.sendToPlayer(player, new MessagePacketPlayerTeleportEffects(vecPos));
				((EntityPlayerMP)player).setPositionAndUpdate(vecPos.x, vecPos.y, vecPos.z);
				world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
                player.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
                player.addExhaustion(0.5F);
                HarshenUtils.damageFirstOccuringItem(player, ringTypeItem.get(message.ringType));
			}
		}			
	}
	else if(message.ringType == 2 && HarshenUtils.containsItem(player, HarshenItems.COMBAT_PENDANT))
	{
		EntityLivingBase entityToAttack = HarshenUtils.getFirstEntityInDirection(player.world, player.getPositionVector(), player.getLookVec().normalize(), 5, EntityLivingBase.class);
		if(entityToAttack == null)
		{
			List<EntityLivingBase> list = player.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(player.posX - 4d, player.posY - 4d, player.posZ - 4d, player.posX + 4d, player.posY + 4d, player.posZ + 4d));
			if(!list.isEmpty())
				entityToAttack = list.get(0);
		}
		if(!player.equals(entityToAttack) && (entityToAttack != null || (entityToAttack instanceof EntityPlayerMP && player.canAttackPlayer((EntityPlayerMP)entityToAttack)
				&& HarshenUtils.toArray(GameType.SURVIVAL, GameType.ADVENTURE).contains(((EntityPlayerMP)entityToAttack).interactionManager.getGameType()))))
		{
			Vec3d position = entityToAttack.getPositionVector();
			Vec3d playerPosNoY = position.addVector(movePos(), 0, movePos());
			Vec3d pos = new Vec3d(playerPosNoY.x, HarshenUtils.getTopBlock(player.world, new BlockPos(playerPosNoY)).getY(), playerPosNoY.z);
			double d0 = position.x - pos.x;
            double d1 = position.y - (pos.y + (double)player.getEyeHeight() - entityToAttack.height / 2f + 0.1f);
            double d2 = position.z - pos.z;
            double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
            float yaw = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
            float pitch = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
			((EntityPlayerMP)player).velocityChanged = true;
			((EntityPlayerMP)player).connection.setPlayerLocation(pos.x, pos.y, pos.z, yaw, pitch);
		}
	}
}
 
Example 18
Project: ForgeHax   File: ProjectileUtils.java   View Source Code Vote up 4 votes
/**
 * Will simulate a shot made from an angle to see if it hits our target
 */
public static boolean projectileTrajectoryHitsEntity(Entity target, Vec3d shootPos, Vec3d targetPos, ProjectileTraceResult result) {
    // gg fps
    EntityPlayer localPlayer = MC.player;
    Vec3d selfPos = localPlayer.getPositionVector();
    ItemStack heldItem = localPlayer.getHeldItemMainhand();
    // work backwards
    // this is actually just a coincidence that the
    // sequence and min value are same
    // im just abusing it so that I can get it to work with other projectile items
    double min = getMinForce(heldItem);
    double max = getMaxForce(heldItem);
    for(double force = max; force >= min; force -= min) {
        Angle angle = getShootAngle(heldItem, shootPos, targetPos, force);

        if(angle == null)
            continue;

        Angle initAngle = new Angle(-angle.getPitch(), angle.getYaw() + 90.D, 0.D);

        double fixX = Math.cos(initAngle.getYaw(true) - Math.PI / 2.0) * 0.16;
        double fixY = ProjectileUtils.PROJECTILE_SHOOTPOS_OFFSET;
        double fixZ = Math.sin(initAngle.getYaw(true) - Math.PI / 2.0) * 0.16;
        Vec3d initPos = new Vec3d(-fixX, localPlayer.getEyeHeight() - fixY, -fixZ);

        Vec3d acceleration = ProjectileUtils.getGravity(heldItem);
        Vec3d airResistance = ProjectileUtils.getAirResistance(heldItem);
        // convert polar coords to cartesian coords
        Vec3d velocity = initAngle.getCartesianCoords().normalize().scale(force);

        Vec3d startPos = initPos;
        Vec3d endPos = startPos;
        for (int i = 0; i < 100; i++) {
            // add velocity
            startPos = startPos.add(velocity);
            // add air resistance
            velocity = VectorUtils.multiplyBy(velocity, airResistance);
            // add gravity (acceleration)
            velocity = velocity.add(acceleration);

            Vec3d wrlStart = selfPos.add(startPos), wrlEnd = selfPos.add(endPos);

            RayTraceResult tr = getWorld().rayTraceBlocks(wrlStart, wrlEnd);
            // if we have hit a block
            if (tr != null &&
                    !getWorld().getBlockState(tr.getBlockPos()).getBlock().isPassable(getWorld(), tr.getBlockPos())) {
                break;
            }

            // if we have hit our target
            tr = target.getEntityBoundingBox().calculateIntercept(wrlStart, wrlEnd);
            if (tr != null) {
                if(result != null) {
                    result.maxForce = force;
                    result.shootAngle = angle;
                }
                return true;
            }
            endPos = startPos;
        }
    }
    return false;
}
 
Example 19
Project: Backmemed   File: ItemRenderer.java   View Source Code Vote up 4 votes
/**
 * Renders the overlays.
 */
public void renderOverlays(float partialTicks)
{
    GlStateManager.disableAlpha();

    if (this.mc.player.isEntityInsideOpaqueBlock())
    {
        IBlockState iblockstate = this.mc.world.getBlockState(new BlockPos(this.mc.player));
        BlockPos blockpos = new BlockPos(this.mc.player);
        EntityPlayer entityplayer = this.mc.player;

        for (int i = 0; i < 8; ++i)
        {
            double d0 = entityplayer.posX + (double)(((float)((i >> 0) % 2) - 0.5F) * entityplayer.width * 0.8F);
            double d1 = entityplayer.posY + (double)(((float)((i >> 1) % 2) - 0.5F) * 0.1F);
            double d2 = entityplayer.posZ + (double)(((float)((i >> 2) % 2) - 0.5F) * entityplayer.width * 0.8F);
            BlockPos blockpos1 = new BlockPos(d0, d1 + (double)entityplayer.getEyeHeight(), d2);
            IBlockState iblockstate1 = this.mc.world.getBlockState(blockpos1);

            if (iblockstate1.func_191058_s())
            {
                iblockstate = iblockstate1;
                blockpos = blockpos1;
            }
        }

        if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE)
        {
            Object object = Reflector.getFieldValue(Reflector.RenderBlockOverlayEvent_OverlayType_BLOCK);

            if (!Reflector.callBoolean(Reflector.ForgeEventFactory_renderBlockOverlay, new Object[] {this.mc.player, Float.valueOf(partialTicks), object, iblockstate, blockpos}))
            {
                this.renderBlockInHand(partialTicks, this.mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(iblockstate));
            }
        }
    }

    if (!this.mc.player.isSpectator())
    {
        if (this.mc.player.isInsideOfMaterial(Material.WATER) && !Reflector.callBoolean(Reflector.ForgeEventFactory_renderWaterOverlay, new Object[] {this.mc.player, Float.valueOf(partialTicks)}))
        {
            this.renderWaterOverlayTexture(partialTicks);
        }

        if (this.mc.player.isBurning() && !Reflector.callBoolean(Reflector.ForgeEventFactory_renderFireOverlay, new Object[] {this.mc.player, Float.valueOf(partialTicks)}))
        {
            this.renderFireInFirstPerson(partialTicks);
        }
    }

    GlStateManager.enableAlpha();
}
 
Example 20
Project: SimpleTractor   File: ItemTractor.java   View Source Code Vote up 4 votes
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * 1.0F;
    float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * 1.0F;
    double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * 1.0D;
    double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * 1.0D + (double)playerIn.getEyeHeight();
    double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * 1.0D;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
    float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
    float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    float f6 = MathHelper.sin(-f1 * 0.017453292F);
    float f7 = f4 * f5;
    float f8 = f3 * f5;
    Vec3d vec3d1 = vec3d.addVector((double)f7 * 5.0D, (double)f6 * 5.0D, (double)f8 * 5.0D);
    RayTraceResult raytraceresult = worldIn.rayTraceBlocks(vec3d, vec3d1, false);

    if (raytraceresult == null)
    {
        return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        Vec3d vec3d2 = playerIn.getLook(1.0F);
        boolean flag = false;
        List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().addCoord(vec3d2.xCoord * 5.0D, vec3d2.yCoord * 5.0D, vec3d2.zCoord * 5.0D).expandXyz(1.0D));

        for (int i = 0; i < list.size(); ++i)
        {
            Entity entity = list.get(i);

            if (entity.canBeCollidedWith())
            {
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz((double)entity.getCollisionBorderSize());

                if (axisalignedbb.isVecInside(vec3d))
                {
                    flag = true;
                }
            }
        }

        if (flag)
        {
            return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
        }
        else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
        {
            return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
        }
        else
        {
            EntityTractor entityTractor = new EntityTractor(worldIn, raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
            entityTractor.rotationYaw = playerIn.rotationYaw;

            if (!worldIn.getCollisionBoxes(entityTractor, entityTractor.getEntityBoundingBox().expandXyz(-0.1D)).isEmpty())
            {
                return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
            }
            else
            {
                if (!worldIn.isRemote)
                {
                    worldIn.spawnEntity(entityTractor);
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --itemStackIn.stackSize;
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
            }
        }
    }
}