Java Code Examples for net.minecraft.util.EnumFacing#getHorizontalAngle()

The following examples show how to use net.minecraft.util.EnumFacing#getHorizontalAngle() . 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: ShipHelmTileEntityRenderer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void render(TileEntityShipHelm tileentity, double x, double y, double z,
    float partialTick, int destroyStage,
    float alpha) {
    if (tileentity instanceof TileEntityShipHelm) {
        IBlockState helmState = tileentity.getWorld().getBlockState(tileentity.getPos());

        if (helmState.getBlock() != ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipHelm) {
            return;
        }

        this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        GlStateManager.pushMatrix();
        GlStateManager.disableLighting();

        GL11.glTranslated(x, y, z);
        GlStateManager.disableAlpha();
        GlStateManager.disableBlend();

        double smoothCompassDif = (tileentity.compassAngle - tileentity.lastCompassAngle);
        if (smoothCompassDif < -180) {
            smoothCompassDif += 360;
        }
        if (smoothCompassDif > 180) {
            smoothCompassDif -= 360;
        }

        double smoothWheelDif = (tileentity.wheelRotation - tileentity.lastWheelRotation);
        if (smoothWheelDif < -180) {
            smoothWheelDif += 360;
        }
        if (smoothWheelDif > 180) {
            smoothWheelDif -= 360;
        }

        double smoothCompass =
            tileentity.lastCompassAngle + (smoothCompassDif) * partialTick + 180D;
        double smoothWheel = tileentity.lastWheelRotation + (smoothWheelDif) * partialTick;
        BlockPos originPos = tileentity.getPos();

        IBlockState wheelState = ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipWheel
            .getStateFromMeta(0);
        IBlockState compassState = ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipWheel
            .getStateFromMeta(1);
        IBlockState glassState = ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipWheel
            .getStateFromMeta(2);
        IBlockState helmStateToRender = ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipWheel
            .getStateFromMeta(3);
        // TODO: Better rendering cache
        int brightness = tileentity.getWorld().getCombinedLight(tileentity.getPos(), 0);

        double multiplier = 2.0D;
        GL11.glTranslated((1D - multiplier) / 2.0D, 0, (1D - multiplier) / 2.0D);
        GL11.glScaled(multiplier, multiplier, multiplier);
        EnumFacing enumfacing = helmState.getValue(BlockShipHelm.FACING);
        double wheelAndCompassStateRotation = enumfacing.getHorizontalAngle();

        GL11.glTranslated(0.5D, 0, 0.5D);
        GL11.glRotated(wheelAndCompassStateRotation, 0, 1, 0);
        GL11.glTranslated(-0.5D, 0, -0.5D);
        GibsModelRegistry.renderGibsModel("ship_helm_base", brightness);

        GL11.glPushMatrix();
        GL11.glTranslated(.5, .522, 0);
        GL11.glRotated(smoothWheel, 0, 0, 1);
        GL11.glTranslated(-.5, -.522, 0);
        GibsModelRegistry.renderGibsModel("ship_helm_wheel", brightness);
        GL11.glPopMatrix();

        GL11.glPushMatrix();
        GL11.glTranslated(0.5D, 0, 0.5D);
        GL11.glRotated(smoothCompass, 0, 1, 0);
        GL11.glTranslated(-0.5D, 0, -0.5D);
        GibsModelRegistry.renderGibsModel("ship_helm_dial", brightness);

        GL11.glPopMatrix();
        GlStateManager.enableAlpha();
        GlStateManager.enableBlend();
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GibsModelRegistry.renderGibsModel("ship_helm_dial_glass", brightness);
        GlStateManager.disableAlpha();
        GlStateManager.disableBlend();
        GL11.glPopMatrix();

        GlStateManager.enableLighting();
        GlStateManager.resetColor();
    }
}
 
Example 2
Source File: SpeedTelegraphTileEntityRenderer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void render(TileEntitySpeedTelegraph tileentity, double x, double y, double z,
    float partialTick, int destroyStage, float alpha) {
    IBlockState telegraphState = tileentity.getWorld().getBlockState(tileentity.getPos());

    if (telegraphState.getBlock()
        != ValkyrienSkiesControl.INSTANCE.vsControlBlocks.speedTelegraph) {
        return;
    }

    GlStateManager.resetColor();
    this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    GlStateManager.pushMatrix();
    GlStateManager.disableLighting();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder tessellatorBuffer = tessellator.getBuffer();

    double oldX = tessellatorBuffer.xOffset;
    double oldY = tessellatorBuffer.yOffset;
    double oldZ = tessellatorBuffer.zOffset;

    tessellatorBuffer.setTranslation(0, 0, 0);
    GL11.glTranslated(x, y, z);
    GlStateManager.disableAlpha();
    GlStateManager.disableBlend();

    BlockPos originPos = tileentity.getPos();

    int brightness = tileentity.getWorld().getCombinedLight(tileentity.getPos(), 0);

    double multiplier = 1.9D;

    GL11.glTranslated((1D - multiplier) / 2.0D, 0, (1D - multiplier) / 2.0D);
    GL11.glScaled(multiplier, multiplier, multiplier);
    EnumFacing enumfacing = telegraphState.getValue(BlockSpeedTelegraph.FACING);
    double wheelAndCompassStateRotation = enumfacing.getHorizontalAngle();

    GL11.glTranslated(0.5D, 0, 0.5D);
    GL11.glRotated(wheelAndCompassStateRotation, 0, 1, 0);
    GL11.glTranslated(-0.5D, 0, -0.5D);

    // FastBlockModelRenderer.renderBlockModel(tessellator, tileentity.getWorld(), helmStateToRender, brightness);

    GibsModelRegistry.renderGibsModel("chadburn_speed_telegraph_simplevoxel_geo", brightness);

    // FastBlockModelRenderer.renderBlockModel(tessellator, tileentity.getWorld(), dialState, brightness);

    GibsModelRegistry.renderGibsModel("chadburn_dial_simplevoxel_geo", brightness);

    GL11.glPushMatrix();

    GL11.glTranslated(0.497D, 0.857D, 0.5D);
    GL11.glRotated(tileentity.getHandleRenderRotation(partialTick), 0D, 0D, 1D);
    GL11.glTranslated(-0.497D, -0.857D, -0.5D);

    // FastBlockModelRenderer.renderBlockModel(tessellator, tileentity.getWorld(), rightHandleState, brightness);

    GibsModelRegistry.renderGibsModel("chadburn_handles_simplevoxel_geo", brightness);

    // FastBlockModelRenderer.renderBlockModel(tessellator, tileentity.getWorld(), leftHandleState, brightness);

    GL11.glPopMatrix();

    GlStateManager.enableAlpha();
    GlStateManager.enableBlend();
    // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // FastBlockModelRenderer.renderBlockModel(tessellator, tileentity.getWorld(), glassState, brightness);
    GibsModelRegistry.renderGibsModel("chadburn_glass_simplevoxel_geo", brightness);

    GlStateManager.disableAlpha();
    GlStateManager.disableBlend();

    GL11.glPopMatrix();
    tessellatorBuffer.setTranslation(oldX, oldY, oldZ);

    GlStateManager.enableLighting();
    GlStateManager.resetColor();
}
 
Example 3
Source File: BlockPassengerChair.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public static double getChairYaw(IBlockState state, BlockPos pos) {
    EnumFacing enumFace = state.getValue(BlockPassengerChair.FACING);
    return -enumFace.getHorizontalAngle() - 90;
}
 
Example 4
Source File: BlockCaptainsChair.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public static double getChairYaw(IBlockState state, BlockPos pos) {
    EnumFacing enumFace = state.getValue(BlockCaptainsChair.FACING);
    double chairYaw = -enumFace.getHorizontalAngle() - 90;
    return chairYaw;
}
 
Example 5
Source File: TileEntityShipHelm.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public void calculateCompassAngle() {
    lastCompassAngle = compassAngle;

    IBlockState helmState = getWorld().getBlockState(getPos());
    if (helmState.getBlock() != ValkyrienSkiesControl.INSTANCE.vsControlBlocks.shipHelm) {
        return;
    }
    EnumFacing enumfacing = helmState.getValue(BlockShipHelm.FACING);
    double wheelAndCompassStateRotation = enumfacing.getHorizontalAngle();

    BlockPos spawnPos = getWorld().getSpawnPoint();
    Vector compassPoint = new Vector(getPos().getX(), getPos().getY(), getPos().getZ());
    compassPoint.add(1D, 2D, 1D);

    Optional<PhysicsObject> physicsObject = ValkyrienUtils
        .getPhysicsObject(getWorld(), getPos());
    if (physicsObject.isPresent()) {
        physicsObject.get()
            .getShipTransformationManager()
            .getCurrentTickTransform()
            .transform(compassPoint,
                TransformType.SUBSPACE_TO_GLOBAL);
        // RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform,
        // compassPoint);
    }

    Vector compassDirection = new Vector(compassPoint);
    compassDirection.subtract(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());

    if (physicsObject.isPresent()) {
        physicsObject.get()
            .getShipTransformationManager()
            .getCurrentTickTransform()
            .rotate(compassDirection,
                TransformType.GLOBAL_TO_SUBSPACE);
        // RotationMatrices.doRotationOnly(wrapper.wrapping.coordTransform.wToLTransform,
        // compassDirection);
    }

    compassDirection.normalize();
    compassAngle = Math.toDegrees(Math.atan2(compassDirection.X, compassDirection.Z))
        - wheelAndCompassStateRotation;
    compassAngle = (compassAngle + 360D) % 360D;
}
 
Example 6
Source File: TileEntityPhysicsInfuserRenderer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void render(TileEntityPhysicsInfuser tileentity, double x, double y, double z,
    float partialTick,
    int destroyStage, float alpha) {

    this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    GlStateManager.pushMatrix();
    GlStateManager.disableLighting();

    GlStateManager.translate(x, y, z);
    GlStateManager.disableAlpha();
    GlStateManager.disableBlend();
    GlStateManager.pushMatrix();

    int brightness = tileentity.getWorld()
        .getCombinedLight(tileentity.getPos(), 0);

    GlStateManager.translate(.5, 0, .5);
    double keyframe = 1;

    IBlockState physicsInfuserState = ValkyrienSkiesMod.INSTANCE.physicsInfuser
        .getStateFromMeta(tileentity.getBlockMetadata());
    EnumFacing enumfacing = physicsInfuserState.getValue(BlockPhysicsInfuser.FACING);
    int coreBrightness =
        physicsInfuserState.getValue(BlockPhysicsInfuser.INFUSER_LIGHT_ON) ? 15728864
            : brightness;
    float physicsInfuserRotation = -enumfacing.getHorizontalAngle() + 180;
    GlStateManager.rotate(physicsInfuserRotation, 0, 1, 0);

    GlStateManager.translate(-.5, 0, -.5);

    // First translate the model one block to the right
    GlStateManager.translate(-1, 0, 0);
    GlStateManager.scale(2, 2, 2);
    GibsAnimationRegistry.getAnimation("physics_infuser_empty")
        .renderAnimation(keyframe, brightness);

    IAtomAnimation cores_animation = GibsAnimationRegistry
        .getAnimation("physics_infuser_cores");
    // Render only the cores that exist within the physics infuser's inventory.
    IItemHandler handler = tileentity
        .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

    for (TileEntityPhysicsInfuser.EnumInfuserCore infuserCore : TileEntityPhysicsInfuser.EnumInfuserCore
        .values()) {
        if (!handler.getStackInSlot(infuserCore.coreSlotIndex).isEmpty) {
            GlStateManager.pushMatrix();
            GlStateManager
                .translate(0, tileentity.getCoreVerticalOffset(infuserCore, partialTick), 0);
            cores_animation
                .renderAnimationNode(infuserCore.coreModelName, keyframe, coreBrightness);
            GlStateManager.popMatrix();
        }
    }

    GlStateManager.popMatrix();
    GlStateManager.popMatrix();
    GlStateManager.enableLighting();
    GlStateManager.resetColor();
}
 
Example 7
Source File: RenderEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void renderPortalPanelText(String text, EntityPlayer player, BlockPos pos, EnumFacing facing, float partialTicks)
{
    double x = pos.getX();
    double y = pos.getY();
    double z = pos.getZ();

    double dx = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double dy = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double dz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;

    float angleH = 0f;
    float angleV = 0f;
    double frontOffset = 0.32D;

    if (facing.getAxis().isHorizontal())
    {
        int frontX = facing.getXOffset();
        int frontZ = facing.getZOffset();

        if (facing == EnumFacing.NORTH || facing == EnumFacing.WEST)
        {
            frontX = -frontX;
            frontZ = -frontZ;
            frontOffset = 1.0D - frontOffset;
        }

        x += frontX * frontOffset + frontZ * 0.5D;
        z += frontZ * frontOffset + frontX * 0.5D;

        y += 1.25D;
        angleH = facing.getHorizontalAngle() + 180f;
    }
    else
    {
        if (facing == EnumFacing.DOWN)
        {
            frontOffset = 1.0D - frontOffset;
            x += 0.5D;
            z -= 0.25D;
        }
        else
        {
            x += 0.5D;
            z += 1.25D;
        }

        y += frontOffset;
        angleV = facing.getYOffset() * -90f;
    }

    this.renderLabel(text, x - dx, y - dy, z - dz, angleH, angleV);
}
 
Example 8
Source File: UpgradePlacer.java    From BetterChests with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
	if (getTickTime(chest, stack) != 0 || !hasUpgradeOperationCost(chest)) {
		return;
	}

	IBetterChest inv = (IBetterChest) chest;

	IFilter filter = ((IBetterChest) chest).getFilterFor(stack);

	int slot = InvUtil.findInInvInternal(inv, null, filter::matchesStack);

	ItemStack targetItem;
	if (slot != -1) {
		targetItem = inv.getStackInSlot(slot);
	} else if (!filter.hasStackFilter()) {
		targetItem = ItemStack.EMPTY;
	} else {
		return;
	}

	EntityPlayerMP player = chest.getFakePlayer();
	if (player == null) {
		return;
	}

	EnumFacing side = getCurrentSide(stack, chest);
	BlockPos targetPos = chest.getPosition().offset(side);

	if (WorldUtil.isBlockAir(chest.getWorldObj(), targetPos)) {
		BlockPos nextPos = targetPos.offset(side);
		if (!WorldUtil.isBlockAir(chest.getWorldObj(), nextPos)) {
			targetPos = nextPos;
		}
	}

	player.inventory.clear();
	player.setHeldItem(EnumHand.MAIN_HAND, targetItem);
	player.rotationPitch = (float) -Math.toDegrees(Math.asin(side.getFrontOffsetY()));
	player.rotationYaw = side.getHorizontalAngle();

	Vec3d playerTargetPos = player.getPositionVector().add(player.getLookVec().normalize());
	player.setPosition(playerTargetPos.x, playerTargetPos.y, playerTargetPos.z);

	if (placeBlock(player, targetPos, side)) {
		drawUpgradeOperationCode(chest);
	}
	if (slot != -1) {
		inv.setInventorySlotContents(slot, player.getHeldItem(EnumHand.MAIN_HAND));
		player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
		for (ItemStack current : InvUtil.getFromInv(player.inventory)) {
			current.setCount(InvUtil.putStackInInventoryInternal(current, inv, false).getCount());
		}
		player.inventory.dropAllItems();
	}
}
 
Example 9
Source File: TESRBBarrel.java    From BetterChests with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void render(TileEntityBBarrel te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {

	if (te.getChestPart().isItemSet()) {
		GlStateManager.pushMatrix();
		GlStateManager.translate((float) x, (float) y, (float) z);
		GlStateManager.translate(0.5F, 0.5F, 0.5F);

		ItemStack stack = te.getChestPart().getDummy();

		EnumFacing side = EnumFacing.HORIZONTALS[te.getBlockMetadata()];

		float angle = side.getHorizontalAngle();
		switch (side) {
		case SOUTH:
			//south
			angle = 180;
			break;
		case WEST:
			//west
			angle = 90;
			break;
		case NORTH:
			//north
			angle = 0;
			break;
		case EAST:
			//east
			angle = -90;
			break;
		}
		GlStateManager.rotate(angle, 0, 1, 0);

		{
			GlStateManager.pushMatrix();

			GlStateManager.translate(0, 0.1, -0.5);
			GlStateManager.scale(0.8, 0.8, 0.8);

			int skyBrightness = te.getWorld().getCombinedLight(te.getPosition().offset(side), 0);
			int skyBrightness1 = skyBrightness % 65536;
			int skyBrightness2 = skyBrightness / 65536;
			OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, skyBrightness1,
					skyBrightness2);

			Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.FIXED);

			GlStateManager.popMatrix();
		}

		{
			GlStateManager.pushMatrix();

			GlStateManager.translate(0, -0.25, -0.51);
			GlStateManager.scale(0.015, 0.015, 0.015);
			GlStateManager.rotate(180, 0, 0, 1);

			String text = te.getChestPart().getAmountDescr();
			int textlen = Minecraft.getMinecraft().fontRenderer.getStringWidth(text);
			Minecraft.getMinecraft().fontRenderer.drawString(text, -textlen / 2, 0, 0xFFFFFFFF);

			GlStateManager.popMatrix();
		}

		GlStateManager.popMatrix();
	}

}