Java Code Examples for net.minecraft.entity.player.EntityPlayer.getPrimaryHand()

The following are Jave code examples for showing how to use getPrimaryHand() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ArcaneMagic   File: ClientEvents.java   View Source Code Vote up 5 votes
@SubscribeEvent
public static void onRenderHand(RenderSpecificHandEvent ev)
{
	EntityPlayer player = Minecraft.getMinecraft().player;
	if (!player.isSneaking() && ev.getItemStack().getItem() instanceof ItemParchment)
	{

		float f = player.getSwingProgress(ev.getPartialTicks());
		float f1 = player.prevRotationPitch
				+ (player.rotationPitch - player.prevRotationPitch) * ev.getPartialTicks();

		ItemRenderer itemrenderer = Minecraft.getMinecraft().getItemRenderer();

		float prevEquipProgress = ev.getHand() == EnumHand.MAIN_HAND ? itemrenderer.prevEquippedProgressMainHand
				: itemrenderer.prevEquippedProgressOffHand;
		float equipProgress = ev.getHand() == EnumHand.MAIN_HAND ? itemrenderer.equippedProgressMainHand
				: itemrenderer.equippedProgressOffHand;
		float f5 = 1.0F - (prevEquipProgress + (equipProgress - prevEquipProgress) * ev.getPartialTicks());

		GlStateManager.pushMatrix();
		GlStateManager.pushAttrib();

		if (ev.getHand() == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty())
		{
			GLHelper.renderParchmentFirstPerson(f1, f5, f, ev.getItemStack());
		} else
		{
			EnumHandSide enumhandside = ev.getHand() == EnumHand.MAIN_HAND ? player.getPrimaryHand()
					: player.getPrimaryHand().opposite();
			GLHelper.renderParchmentFirstPersonSide(f5, enumhandside, f, ev.getItemStack());
		}

		GlStateManager.popAttrib();
		GlStateManager.popMatrix();
		ev.setCanceled(true);
	}
}
 
Example 2
Project: ToolBelt   File: LayerToolBelt.java   View Source Code Vote up 4 votes
@Override
public void doRenderLayer(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale)
{
    boolean flag = player.getPrimaryHand() == EnumHandSide.RIGHT;

    if (!Config.showBeltOnPlayers)
        return;

    BeltFinder.BeltGetter getter = BeltFinder.instance.findStack(player);
    if (getter == null)
        return;

    ItemStack stack = getter.getBelt();
    if (stack.getCount() <= 0)
        return;

    ToolBeltInventory cap = ItemToolBelt.getItems(stack);

    ItemStack firstItem = cap.getStackInSlot(0);
    ItemStack secondItem = cap.getStackInSlot(1);

    ItemStack leftItem = flag ? firstItem : secondItem;
    ItemStack rightItem = flag ? secondItem : firstItem;

    GlStateManager.pushMatrix();

    if (player.isSneaking())
    {
        GlStateManager.translate(0.0F, 0.2F, 0.0F);
    }

    this.translateToBody();

    if (!leftItem.isEmpty() || !rightItem.isEmpty())
    {
        GlStateManager.pushMatrix();

        if (this.livingEntityRenderer.getMainModel().isChild)
        {
            GlStateManager.translate(0.0F, 0.75F, 0.0F);
            GlStateManager.scale(0.5F, 0.5F, 0.5F);
        }

        this.renderHeldItem(player, rightItem, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
        this.renderHeldItem(player, leftItem, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);

        GlStateManager.popMatrix();
    }

    GlStateManager.translate(0.0F, 0.19F, 0.0F);
    GlStateManager.scale(0.85f, 0.6f, 0.78f);

    this.livingEntityRenderer.bindTexture(TEXTURE_BELT);
    this.beltModel.render(player, 0, 0, 0, 0, 0, scale);

    GlStateManager.popMatrix();
}