Java Code Examples for net.minecraft.util.Vec3#addVector()

The following examples show how to use net.minecraft.util.Vec3#addVector() . 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: ReachDisplay.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@InvokeEvent
public void attacc(PlayerAttackEntityEvent entityEvent) {
    if (!Settings.SHOW_HIT_DISTANCES) return;
    if (!(entityEvent.getEntity() instanceof EntityLivingBase)) return;
    if (((EntityLivingBase) entityEvent.getEntity()).hurtTime > 0) return;
    if (locked) return;

    locked = true;
    EntityPlayerSP entity = Minecraft.getMinecraft().thePlayer;
    double d0 = 6;
    Vec3 vec3 = entity.getPositionEyes(0.0F);
    Vec3 vec31 = entity.getLook(0.0F);
    Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
    Entity entity1 = entityEvent.getEntity();
    float f1 = .1F;
    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f1, f1, f1);
    MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
    if (movingobjectposition == null) return;
    Vec3 vec33 = movingobjectposition.hitVec;
    hits.add(new Hit(vec33, dis));

}
 
Example 2
Source File: General.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) {
	float var4 = 1.0F;
	float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
	float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
	double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * var4;
	double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * var4 + 1.62D - par2EntityPlayer.yOffset;
	double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * var4;
	// TODO- 1.7.10 fix?
	Vec3 var13 = Vec3.createVectorHelper(var7, var9, var11);
	float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI);
	float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI);
	float var16 = -MathHelper.cos(-var5 * 0.017453292F);
	float var17 = MathHelper.sin(-var5 * 0.017453292F);
	float var18 = var15 * var16;
	float var20 = var14 * var16;
	double var21 = 5.0D;

	if (par2EntityPlayer instanceof EntityPlayerMP) {
		var21 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
	}

	Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
	return par1World.rayTraceBlocks(var13, var23, par3);
}
 
Example 3
Source File: General.java    From Chisel with GNU General Public License v2.0 6 votes vote down vote up
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
{
    float var4 = 1.0F;
    float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
    float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
    double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * var4;
    double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * var4 + 1.62D - par2EntityPlayer.yOffset;
    double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * var4;
    //TODO- 1.7.10 fix?
    Vec3 var13 = Vec3.createVectorHelper(var7, var9, var11);
    float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI);
    float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI);
    float var16 = -MathHelper.cos(-var5 * 0.017453292F);
    float var17 = MathHelper.sin(-var5 * 0.017453292F);
    float var18 = var15 * var16;
    float var20 = var14 * var16;
    double var21 = 5.0D;

    if(par2EntityPlayer instanceof EntityPlayerMP)
    {
        var21 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
    }

    Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
    return par1World.rayTraceBlocks(var13, var23, par3);
}
 
Example 4
Source File: StaticTrailAnimation.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Vec3> render(EntityPlayer player, double x, double y, double z) {
    ArrayList<Vec3> vec3s;
    float rotationYaw = player.rotationYawHead;
    rotationYaw -= 90;
    Vec3 base = new Vec3(x + MathHelper.cos((float) Math.toRadians(rotationYaw)), y + 1.8D, z + MathHelper.sin((float) Math.toRadians(rotationYaw)));
    ArrayList<Vec3> result = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Vec3 vec3 = base.addVector(0, -.4 * i, 0);
        result.add(vec3);
    }
    vec3s = result;
    return vec3s;
}
 
Example 5
Source File: EndPort.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith) {
    Minecraft mc = Wrapper.INSTANCE.mc();
    Entity pointedEntity = null;
    MovingObjectPosition rayTrace = null;

    if (mc.renderViewEntity != null) {
        if (mc.theWorld != null) {
            Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks);
            Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks);
            Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance);
            double boxExpand = 1.0F;
            List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand));
            double mincalc = Double.MAX_VALUE;
            for (int i = 0; i < entities.size(); i++) {
                Entity entity = entities.get(i);
                if (!canBeCollidedWith || entity.canBeCollidedWith()) {
                    double borderSize = entity.getCollisionBorderSize();
                    AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize);
                    MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec);
                    if (calculateInterceptPos != null) {
                        double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec);
                        if (mincalc > calcInterceptPosDist) {
                            mincalc = calcInterceptPosDist;
                            pointedEntity = entity;
                        }
                    }
                }
            }
            if (pointedEntity != null) {
                return pointedEntity;
            }
        }
    }

    return null;
}
 
Example 6
Source File: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith) {
    Minecraft mc = Wrapper.INSTANCE.mc();
    Entity pointedEntity = null;
    MovingObjectPosition rayTrace = null;

    if (mc.renderViewEntity != null) {
        if (mc.theWorld != null) {
            Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks);
            Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks);
            Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance);
            double boxExpand = 1.0F;
            @SuppressWarnings("unchecked")
            List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand));
            double mincalc = Double.MAX_VALUE;
            for (Entity entity : entities) {
                if (!canBeCollidedWith || entity.canBeCollidedWith()) {
                    double borderSize = entity.getCollisionBorderSize();
                    AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize);
                    MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec);
                    if (calculateInterceptPos != null) {
                        double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec);
                        if (mincalc > calcInterceptPosDist) {
                            mincalc = calcInterceptPosDist;
                            pointedEntity = entity;
                        }
                    }
                }
            }
            if (pointedEntity != null) {
                return pointedEntity;
            }
        }
    }

    return null;
}
 
Example 7
Source File: ClientProxy.java    From SimplyJetpacks with MIT License 5 votes vote down vote up
@Override
public void showJetpackParticles(World world, EntityLivingBase wearer, ParticleType particle) {
    if (mc.gameSettings.particleSetting == 0 || mc.gameSettings.particleSetting == 1 && mc.theWorld.getTotalWorldTime() % 4L == 0) {
        Vec3 userPos = Vec3.createVectorHelper(wearer.posX, wearer.posY, wearer.posZ);
        
        if (!wearer.equals(mc.thePlayer)) {
            userPos = userPos.addVector(0, 1.6D, 0);
        }
        
        Random rand = MathHelper.RANDOM;
        
        Vec3 vLeft = Vec3.createVectorHelper(-0.28D, -0.95D, -0.38D);
        vLeft.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        Vec3 vRight = Vec3.createVectorHelper(0.28D, -0.95D, -0.38D);
        vRight.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        Vec3 vCenter = Vec3.createVectorHelper((rand.nextFloat() - 0.5F) * 0.25F, -0.95D, -0.38D);
        vCenter.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        vLeft = vLeft.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        vRight = vRight.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        vCenter = vCenter.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        
        Vec3 v = userPos.addVector(vLeft.xCoord, vLeft.yCoord, vLeft.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
        
        v = userPos.addVector(vRight.xCoord, vRight.yCoord, vRight.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
        
        v = userPos.addVector(vCenter.xCoord, vCenter.yCoord, vCenter.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
    }
}
 
Example 8
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MovingObjectPosition retraceBlock(World world, EntityPlayer player, BlockPos pos) {
    IBlockState b = world.getBlockState(pos);
    Vec3 headVec = getCorrectedHeadVec(player);
    Vec3 lookVec = player.getLook(1.0F);
    double reach = getBlockReachDistance(player);
    Vec3 endVec = headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
    return b.getBlock().collisionRayTrace(world, pos, headVec, endVec);
}
 
Example 9
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 10
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 11
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 12
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;
}
 
Example 13
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static MovingObjectPosition retrace(EntityPlayer player, double reach) {
    Vec3 headVec = getCorrectedHeadVec(player);
    Vec3 lookVec = player.getLook(1);
    Vec3 endVec = headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
    return player.worldObj.rayTraceBlocks(headVec, endVec, true, false, true);
}
 
Example 14
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Vec3 getEndVec(EntityPlayer player) {
    Vec3 headVec = getCorrectedHeadVec(player);
    Vec3 lookVec = player.getLook(1.0F);
    double reach = getBlockReachDistance(player);
    return headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
}