Java Code Examples for net.minecraft.util.MovingObjectPosition.MovingObjectType#ENTITY

The following examples show how to use net.minecraft.util.MovingObjectPosition.MovingObjectType#ENTITY . 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: 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;
}
 
Example 2
Source File: ItemThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    float f = 1.0F;
    float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
    float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
    double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
    double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
    double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
    Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
    float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
    float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
    float f5 = -MathHelper.cos(-f1 * 0.01745329F);
    float f6 = MathHelper.sin(-f1 * 0.01745329F);
    float f7 = f4 * f5;
    float f8 = f6;
    float f9 = f3 * f5;
    double d3 = 5000D;
    Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
    MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    if (movingobjectposition == null) {
        return itemstack;
    }
    if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        int i = movingobjectposition.blockX;
        int j = movingobjectposition.blockY;
        int k = movingobjectposition.blockZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
    } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
        Entity entityhit = movingobjectposition.entityHit;
        double x = entityhit.posX;
        double y = entityhit.posY;
        double z = entityhit.posZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
    }
    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example 3
Source File: ItemMaterials.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (stack != null && stack.getItemDamage() == 6) {
        player.swingItem();
        float f = 1.0F;
        float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
        float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
        double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
        double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
        double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
        Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
        float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
        float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
        float f5 = -MathHelper.cos(-f1 * 0.01745329F);
        float f6 = MathHelper.sin(-f1 * 0.01745329F);
        float f7 = f4 * f5;
        float f8 = f6;
        float f9 = f3 * f5;
        double d3 = 5000D;
        Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
        MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
        if (movingobjectposition == null) {
            return stack;
        }
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
        } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
            Entity entityhit = movingobjectposition.entityHit;
            double x = entityhit.posX;
            double y = entityhit.posY;
            double z = entityhit.posZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
        }
        if (player.capabilities.isCreativeMode) {
            return stack;
        } else {
            player.inventory.consumeInventoryItem(this);
            return stack;
        }
    }
    return stack;
}