Java Code Examples for net.minecraft.util.MathHelper#wrapAngleTo180_float()

The following examples show how to use net.minecraft.util.MathHelper#wrapAngleTo180_float() . These examples are extracted from open source projects. 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
public void onBlockPlacedOn(TileStickyJar tile, EntityLivingBase player) {
    if (tile.placedOn != ForgeDirection.UP && tile.placedOn != ForgeDirection.DOWN) {

        float pitch = player.rotationPitch;

        float yaw = MathHelper.wrapAngleTo180_float(player.rotationYaw);

        switch (tile.placedOn) {
            case WEST:
                yaw -= 90;
                break;
            case NORTH:
                yaw = (180 - Math.abs(yaw)) * (yaw < 0 ? 1 : -1);
                break;
            case EAST:
                yaw += 90;
                break;
        }

        if (Math.abs(yaw) < Math.abs(pitch)) {
            tile.facing = pitch < 0 ? ForgeDirection.SOUTH.ordinal() : ForgeDirection.NORTH.ordinal();
        } else {
            tile.facing = yaw < 0 ? ForgeDirection.EAST.ordinal() : ForgeDirection.WEST.ordinal();
        }
    }
}
 
Example 2
Source Project: mobycraft   File: EntityChaosMonkey.java    License: Apache License 2.0 5 votes vote down vote up
protected void updateAITasks() {
	super.updateAITasks();
	{
		if (this.spawnPosition != null
				&& (!this.worldObj.isAirBlock(this.spawnPosition) || this.spawnPosition
						.getY() < 1)) {
			this.spawnPosition = null;
		}

		if (this.spawnPosition == null
				|| this.rand.nextInt(30) == 0
				|| this.spawnPosition.distanceSq(
						(double) ((int) this.posX),
						(double) ((int) this.posY),
						(double) ((int) this.posZ)) < 4.0D) {
			this.spawnPosition = new BlockPos((int) this.posX
					+ this.rand.nextInt(7) - this.rand.nextInt(7),
					(int) this.posY + this.rand.nextInt(6) - 2,
					(int) this.posZ + this.rand.nextInt(7)
							- this.rand.nextInt(7));
		}

		double d0 = (double) this.spawnPosition.getX() + 0.5D - this.posX;
		double d1 = (double) this.spawnPosition.getY() + 0.1D - this.posY;
		double d2 = (double) this.spawnPosition.getZ() + 0.5D - this.posZ;
		this.motionX += (Math.signum(d0) * 0.5D - this.motionX) * 0.10000000149011612D;
		this.motionY += (Math.signum(d1) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
		this.motionZ += (Math.signum(d2) * 0.5D - this.motionZ) * 0.10000000149011612D;
		float f = (float) (MathHelper.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) - 90.0F;
		float f1 = MathHelper.wrapAngleTo180_float(f - this.rotationYaw);
		this.moveForward = 0.5F;
		this.rotationYaw += f1;
	}
}
 
Example 3
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
    int metadata = world.getBlockMetadata(x, y, z);

    ForgeDirection side = ForgeDirection.getOrientation(metadata);

    float yaw = MathHelper.wrapAngleTo180_float(entity.rotationYaw);
    float pitch = entity.rotationPitch;

    boolean flipped;
    if(side == ForgeDirection.UP || side == ForgeDirection.DOWN) {
        yaw += 180;
        flipped = yaw > 315 || yaw < 45 || (yaw < 225 && yaw > 135);
    } else {
        switch (side.getOpposite()) {
            case WEST:
                yaw -= 90;
                break;
            case NORTH:
                yaw = (180 - Math.abs(yaw)) * (yaw < 0 ? 1 : -1);
                break;
            case EAST:
                yaw += 90;
                break;
        }
        flipped = Math.abs(yaw) < Math.abs(pitch);
    }

    metadata |= flipped ? 8 : 0;
    world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
 
Example 4
public void tick() {
    if (Minecraft.getMinecraft().theWorld == null) return;

    for (Map.Entry<EntityPlayer, CustomDragon> entry : dragonHashMap.entrySet()) {
        EntityPlayer player = entry.getKey();
        CustomDragon customDragon = entry.getValue();
        EntityDragon entityDragon = customDragon.dragon;
        AnimationState animationState = customDragon.animationState;
        if (entityDragon != null) {
            entityDragon.setWorld(player.getEntityWorld());
            double v = animationState.next.distanceSqTo(new AnimationPoint(player.posX, player.posY, player.posZ));
            if (v > 7 * 7) animationState.switchToNext(player, true);

            entityDragon.lastTickPosX = entityDragon.posX;
            entityDragon.lastTickPosY = entityDragon.posY;
            entityDragon.lastTickPosZ = entityDragon.posZ;
            entityDragon.prevRotationYawHead = entityDragon.rotationYawHead;

            AnimationPoint current = animationState.getCurrent(player);
            entityDragon.posX = current.x / scale;
            entityDragon.posY = current.y / scale;
            entityDragon.posZ = current.z / scale;

            double dx = animationState.next.x - animationState.last.x;
            double dz = animationState.next.z - animationState.last.z;

            double angrad = Math.atan2(dx, -dz);
            double angle = MathHelper.wrapAngleTo180_float((float) Math.toDegrees(angrad));

            if (animationState.nextFrameisNewPoint(player)) {
                double dx1 = animationState.nextNext.x - animationState.next.x;
                double dz1 = animationState.nextNext.z - animationState.next.z;
                double angrad1 = Math.atan2(dx1, -dz1);
                double angle1 = MathHelper.wrapAngleTo180_float((float) Math.toDegrees(angrad1));
                //Average yaw
                angle = ((float) angle + (float) angle1) / 2;
                entityDragon.rotationYawHead = (float) angle1;
            }

            entityDragon.prevRotationYaw = entityDragon.rotationYaw;
            entityDragon.rotationYaw = (float) angle;
            entityDragon.onLivingUpdate();
        }
    }
}