Java Code Examples for net.minecraft.entity.EntityLivingBase#getLook()

The following examples show how to use net.minecraft.entity.EntityLivingBase#getLook() . 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: ItemFirestarter.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public RayTraceResult rayTrace(EntityLivingBase player, double blockReachDistance, float partialTicks)
{
	Vec3d vec3d = player.getPositionEyes(partialTicks);
	Vec3d vec3d1 = player.getLook(partialTicks);
	Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * blockReachDistance, vec3d1.yCoord * blockReachDistance, vec3d1.zCoord * blockReachDistance);
	return player.world.rayTraceBlocks(vec3d, vec3d2, false, false, true);
}
 
Example 2
Source File: Rotation.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param entity The placing entity, used for obtaining the look vector
 * @return The side towards which the entity is most directly looking.
 */
public static int getSideFromLookAngle(EntityLivingBase entity) {
    Vector3 look = new Vector3(entity.getLook(1));
    double max = 0;
    int maxs = 0;
    for (int s = 0; s < 6; s++) {
        double d = look.scalarProject(axes[s]);
        if (d > max) {
            max = d;
            maxs = s;
        }
    }
    return maxs;
}
 
Example 3
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static Pair<Vec3, Vec3> getStartAndEndLookVec(EntityLivingBase entity, float maxDistance){
    Vec3 entityVec;
    if(entity.worldObj.isRemote && entity instanceof EntityPlayer) {
        entityVec = Vec3.createVectorHelper(entity.posX, entity.posY + 1.6200000000000001D - entity.yOffset, entity.posZ);
    } else {
        entityVec = Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight() - entity.yOffset - (entity.isSneaking() ? 0.08 : 0), entity.posZ);
    }
    Vec3 entityLookVec = entity.getLook(1.0F);
    Vec3 maxDistVec = entityVec.addVector(entityLookVec.xCoord * maxDistance, entityLookVec.yCoord * maxDistance, entityLookVec.zCoord * maxDistance);
    return new ImmutablePair(entityVec, maxDistVec);
}
 
Example 4
Source File: ItemLegUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void playerJumps(LivingEvent.LivingJumpEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 0);
	if (CyberwareAPI.isCyberwareInstalled(e, test))
	{
		int numLegs = 0;
		if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(CyberwareContent.cyberlimbs, 1, 2)))
		{
			numLegs++;
		}
		if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(CyberwareContent.cyberlimbs, 1, 3)))
		{
			numLegs++;
		}
		ICyberwareUserData ware = CyberwareAPI.getCapability(e);
		if (ware.usePower(test, this.getPowerConsumption(test)))
		{
			if (e.isSneaking())
			{
				Vec3d vector = e.getLook(0.5F);
				double total = Math.abs(vector.zCoord + vector.xCoord);
				double jump = 0;
				if (jump >= 1)
				{
					jump = (jump + 2D) / 4D;
				}

				double y = vector.yCoord < total ? total : vector.yCoord;

				e.motionY += (numLegs * ((jump + 1) * y)) / 3F;
				e.motionZ += (jump + 1) * vector.zCoord * numLegs;
				e.motionX += (jump + 1) * vector.xCoord * numLegs;
			}
			else
			{
				e.motionY += numLegs * (0.2750000059604645D / 2D);
			}
		}
	}
}
 
Example 5
Source File: EntityLivingMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Object getMeta(EntityLivingBase target, Vec3 relativePos) {
	Map<String, Object> map = Maps.newHashMap();

	{
		Map<String, ItemStack> armor = Maps.newHashMap();
		armor.put("boots", target.getEquipmentInSlot(1));
		armor.put("leggings", target.getEquipmentInSlot(2));
		armor.put("chestplate", target.getEquipmentInSlot(3));
		armor.put("helmet", target.getEquipmentInSlot(4));
		map.put("armor", armor);
	}

	map.put("heldItem", target.getEquipmentInSlot(0));

	{
		Map<Object, String> potionEffects = Maps.newHashMap();
		@SuppressWarnings("unchecked")
		Collection<PotionEffect> effects = target.getActivePotionEffects();

		int count = 1;
		for (PotionEffect effect : effects) {
			potionEffects.put(count++, effect.getEffectName());
		}
		map.put("potionEffects", potionEffects);
	}

	map.put("health", target.getHealth());
	map.put("maxHealth", target.getMaxHealth());
	map.put("isAirborne", target.isAirBorne);
	map.put("isBurning", target.isBurning());
	map.put("isAlive", target.isEntityAlive());
	map.put("isInWater", target.isInWater());
	map.put("isOnLadder", target.isOnLadder());
	map.put("isSleeping", target.isPlayerSleeping());
	map.put("isRiding", target.isRiding());
	map.put("isSneaking", target.isSneaking());
	map.put("isSprinting", target.isSprinting());
	map.put("isWet", target.isWet());
	map.put("isChild", target.isChild());
	map.put("isDead", target.isDead);
	map.put("yaw", target.rotationYaw);
	map.put("pitch", target.rotationPitch);
	map.put("yawHead", target.rotationYawHead);

	{
		Vec3 posVec = Vec3.createVectorHelper(target.posX, target.posY + 1.62F, target.posZ);
		Vec3 lookVec = target.getLook(1.0f);
		Vec3 targetVec = posVec.addVector(lookVec.xCoord * 10f, lookVec.yCoord * 10f, lookVec.zCoord * 10f);

		MovingObjectPosition mop = target.worldObj.rayTraceBlocks(posVec, targetVec);

		if (mop != null) {
			Map<String, Object> hit = Maps.newHashMap();
			if (mop.typeOfHit == MovingObjectType.BLOCK) {
				hit.put("type", "block");
				Map<String, Object> lookingAt = Maps.newHashMap();
				if (relativePos != null) {
					lookingAt.put("x", mop.blockX - relativePos.xCoord);
					lookingAt.put("y", mop.blockY - relativePos.yCoord);
					lookingAt.put("z", mop.blockZ - relativePos.zCoord);
				} else {
					lookingAt.put("x", mop.blockX);
					lookingAt.put("y", mop.blockY);
					lookingAt.put("z", mop.blockZ);
				}
				hit.put("position", lookingAt);
			} else if (mop.typeOfHit == MovingObjectType.ENTITY) {
				hit.put("type", "entity");
				hit.put("id", mop.entityHit.getEntityId());
			}

			map.put("lookingAt", hit);
		}
	}

	map.put("potion_effects", getPotionEffects(target));

	return map;
}