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

The following examples show how to use net.minecraft.util.math.Vec3d#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: DiscreteMovementCommandsImplementation.java    From malmo with MIT License 6 votes vote down vote up
private RayTraceResult getObjectMouseOver(DiscreteMovementCommand command)
{
    RayTraceResult mop = null;
    if (command.equals(DiscreteMovementCommand.USE))
        mop = Minecraft.getMinecraft().objectMouseOver;
    else if (command.equals(DiscreteMovementCommand.JUMPUSE))
    {
        long partialTicks = 0;  //Minecraft.timer.renderPartialTicks
        Entity viewer = Minecraft.getMinecraft().player;
        double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
        Vec3d eyePos = viewer.getPositionEyes(partialTicks);
        Vec3d lookVec = viewer.getLook(partialTicks);
        int yOffset = 1;    // For the jump
        Vec3d searchVec = eyePos.addVector(lookVec.xCoord * blockReach, yOffset + lookVec.yCoord * blockReach, lookVec.zCoord * blockReach);
        mop = Minecraft.getMinecraft().world.rayTraceBlocks(eyePos, searchVec, false, false, false);
    }
    return mop;
}
 
Example 2
Source File: SoundPhysics.java    From Sound-Physics with GNU General Public License v3.0 5 votes vote down vote up
private static Vec3d offsetSoundByName(Vec3d soundPos, Vec3d playerPos, String name, String soundCategory)
{
	double offsetX = 0.0;
	double offsetY = 0.0;
	double offsetZ = 0.0;
	
	double offsetTowardsPlayer = 0.0;
	
	Vec3d toPlayerVector = playerPos.subtract(soundPos).normalize();
	
	//names
	if (name.matches(".*step.*"))
	{
		offsetY = 0.1;
	}
	
	//categories
	if (soundCategory.matches("block") || soundCategory.matches("record"))
	{
		offsetTowardsPlayer = 0.89;
	}
	
	if (soundPos.yCoord % 1.0 < 0.001 && soundPos.yCoord > 0.01)
	{
		offsetY = 0.1;
	}
	
	offsetX += toPlayerVector.xCoord * offsetTowardsPlayer;
	offsetY += toPlayerVector.yCoord * offsetTowardsPlayer;
	offsetZ += toPlayerVector.zCoord * offsetTowardsPlayer;
	
	//soundPos.xCoord += offsetX;
	//soundPos.yCoord += offsetY;
	//soundPos.zCoord += offsetZ;
	soundPos = soundPos.addVector(offsetX, offsetY, offsetZ);
	
	//logDetailed("Offset sound by " + offsetX + ", " + offsetY + ", " + offsetZ);
	
	return soundPos;
}
 
Example 3
Source File: HandMethods.java    From pycode-minecraft with MIT License 5 votes vote down vote up
public void sidle(float distance) {
    Vec3d pos = this.hand.getPositionVector();
    float rotation = this.hand.rotationYaw - 90;
    float f1 = -MathHelper.sin(rotation * 0.017453292F);
    float f2 = MathHelper.cos(rotation * 0.017453292F);
    pos = pos.addVector(distance * f1, 0, distance * f2);
    this.hand.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
}
 
Example 4
Source File: HandEntity.java    From pycode-minecraft with MIT License 5 votes vote down vote up
public void moveForward(float distance) {
    Vec3d pos = this.getPositionVector();
    float f1 = -MathHelper.sin(this.rotationYaw * 0.017453292F);
    float f2 = MathHelper.cos(this.rotationYaw * 0.017453292F);
    pos = pos.addVector(distance * f1, 0, distance * f2);
    this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
}
 
Example 5
Source File: DrinkWaterHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public RayTraceResult rayTrace(EntityPlayer 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 6
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 7
Source File: DirectionalityRenderer.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
private void build(TIntObjectHashMap<BakedRenderer> bakedRenderers, ImmutableList<NetworkRail<MCPos>> edge){

        for(int edgeIndex = 1; edgeIndex < edge.size() - 1; edgeIndex++) {
            NetworkRail<MCPos> prevRail = edge.get(edgeIndex - 1);
            MCNetworkRail curRail = (MCNetworkRail)edge.get(edgeIndex);
            NetworkRail<MCPos> nextRail = edge.get(edgeIndex + 1);

            EnumHeading prevHeading = curRail.getPos().getRelativeHeading(prevRail.getPos());
            EnumHeading nextHeading = nextRail.getPos().getRelativeHeading(curRail.getPos());
            if(prevHeading == null || nextHeading == null || prevHeading != nextHeading || curRail.getPos().getDimID() != nextRail.getPos().getDimID() || curRail.getPos().getDimID() != prevRail.getPos().getDimID()) continue;

            BakedRenderer bakedRenderer = bakedRenderers.get(curRail.getPos().getDimID());
            if(bakedRenderer == null) {
                bakedRenderer = new BakedRenderer();
                bakedRenderers.put(curRail.getPos().getDimID(), bakedRenderer);
            }

            MCPos pos = curRail.getPos();
            EnumFacing facing = HeadingUtils.toFacing(nextHeading).getOpposite();
            EnumFacing rotatedFacing = facing.rotateY();
            EnumFacing rotatedFacing2 = facing.rotateYCCW();
            int yOffset = AbstractRailRenderer.getRailHeightOffset(curRail, facing);

            Vec3d posVec = new Vec3d(pos.getX() + 0.5, pos.getY() + (yOffset != 0 ? 0.6001 : 0.1001), pos.getZ() + 0.5);

            double arrowSize = 0.1;
            double spacing = 0.1;

            for(int i = -2; i < -1; i++) {
                Vec3d shiftedPosVec = posVec.addVector(facing.getFrontOffsetX() * spacing * i, spacing * i * yOffset + 0.001, facing.getFrontOffsetZ() * spacing * i);
                Vec3d vecBack = shiftedPosVec.addVector(facing.getFrontOffsetX() * arrowSize, arrowSize * yOffset, facing.getFrontOffsetZ() * arrowSize);
                Vec3d c1 = vecBack.addVector(rotatedFacing.getFrontOffsetX() * arrowSize, 0, rotatedFacing.getFrontOffsetZ() * arrowSize);
                Vec3d c2 = vecBack.addVector(rotatedFacing2.getFrontOffsetX() * arrowSize, 0, rotatedFacing2.getFrontOffsetZ() * arrowSize);

                bakedRenderer.add(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z);
                bakedRenderer.add(c1.x, c1.y, c1.z);
                //buffer.pos(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z).color(r, g, b, 1).endVertex();
                bakedRenderer.add(c2.x, c2.y, c2.z);
            }
        }
    }