Java Code Examples for net.minecraft.client.entity.AbstractClientPlayer#isHandActive()

The following examples show how to use net.minecraft.client.entity.AbstractClientPlayer#isHandActive() . 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: RenderCyberlimbHand.java    From Cyberware with MIT License 4 votes vote down vote up
public void renderItemInFirstPerson(AbstractClientPlayer p_187457_1_, float p_187457_2_, float p_187457_3_, EnumHand p_187457_4_, float p_187457_5_, @Nullable ItemStack p_187457_6_, float p_187457_7_)
{
	boolean flag = p_187457_4_ == EnumHand.MAIN_HAND;
	EnumHandSide enumhandside = flag ? p_187457_1_.getPrimaryHand() : p_187457_1_.getPrimaryHand().opposite();
	GlStateManager.pushMatrix();

	if (p_187457_6_ == null)
	{
		if (flag && !p_187457_1_.isInvisible())
		{
			
			this.renderArmFirstPerson(p_187457_7_, p_187457_5_, enumhandside);
		}
	}
	else if (p_187457_6_.getItem() instanceof net.minecraft.item.ItemMap)
	{
		if (flag && itemStackOffHand == null)
		{
			this.renderMapFirstPerson(p_187457_3_, p_187457_7_, p_187457_5_);
		}
		else
		{
			this.renderMapFirstPersonSide(p_187457_7_, enumhandside, p_187457_5_, p_187457_6_);
		}
	}
	else
	{
		boolean flag1 = enumhandside == EnumHandSide.RIGHT;

		if (p_187457_1_.isHandActive() && p_187457_1_.getItemInUseCount() > 0 && p_187457_1_.getActiveHand() == p_187457_4_)
		{
			int j = flag1 ? 1 : -1;

			switch (p_187457_6_.getItemUseAction())
			{
				case NONE:
					this.transformSideFirstPerson(enumhandside, p_187457_7_);
					break;
				case EAT:
				case DRINK:
					this.transformEatFirstPerson(p_187457_2_, enumhandside, p_187457_6_);
					this.transformSideFirstPerson(enumhandside, p_187457_7_);
					break;
				case BLOCK:
					this.transformSideFirstPerson(enumhandside, p_187457_7_);
					break;
				case BOW:
					this.transformSideFirstPerson(enumhandside, p_187457_7_);
					GlStateManager.translate((float)j * -0.2785682F, 0.18344387F, 0.15731531F);
					GlStateManager.rotate(-13.935F, 1.0F, 0.0F, 0.0F);
					GlStateManager.rotate((float)j * 35.3F, 0.0F, 1.0F, 0.0F);
					GlStateManager.rotate((float)j * -9.785F, 0.0F, 0.0F, 1.0F);
					float f5 = (float)p_187457_6_.getMaxItemUseDuration() - ((float)this.mc.thePlayer.getItemInUseCount() - p_187457_2_ + 1.0F);
					float f6 = f5 / 20.0F;
					f6 = (f6 * f6 + f6 * 2.0F) / 3.0F;

					if (f6 > 1.0F)
					{
						f6 = 1.0F;
					}

					if (f6 > 0.1F)
					{
						float f7 = MathHelper.sin((f5 - 0.1F) * 1.3F);
						float f3 = f6 - 0.1F;
						float f4 = f7 * f3;
						GlStateManager.translate(f4 * 0.0F, f4 * 0.004F, f4 * 0.0F);
					}

					GlStateManager.translate(f6 * 0.0F, f6 * 0.0F, f6 * 0.04F);
					GlStateManager.scale(1.0F, 1.0F, 1.0F + f6 * 0.2F);
					GlStateManager.rotate((float)j * 45.0F, 0.0F, -1.0F, 0.0F);
			}
		}
		else
		{
			float f = -0.4F * MathHelper.sin(MathHelper.sqrt_float(p_187457_5_) * (float)Math.PI);
			float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt_float(p_187457_5_) * ((float)Math.PI * 2F));
			float f2 = -0.2F * MathHelper.sin(p_187457_5_ * (float)Math.PI);
			int i = flag1 ? 1 : -1;
			GlStateManager.translate((float)i * f, f1, f2);
			this.transformSideFirstPerson(enumhandside, p_187457_7_);
			this.transformFirstPerson(enumhandside, p_187457_5_);
		}

		this.renderItemSide(p_187457_1_, p_187457_6_, flag1 ? ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND : ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, !flag1);
	}

	GlStateManager.popMatrix();
}
 
Example 2
Source File: EssentialsMissingHandlerClient.java    From Cyberware with MIT License 4 votes vote down vote up
private void renderItemInFirstPerson(float partialTicks)
{
	ItemRenderer ir = mc.getItemRenderer();
	AbstractClientPlayer abstractclientplayer = mc.thePlayer;
	float f = abstractclientplayer.getSwingProgress(partialTicks);
	EnumHand enumhand = (EnumHand)Objects.firstNonNull(abstractclientplayer.swingingHand, EnumHand.MAIN_HAND);
	float f1 = abstractclientplayer.prevRotationPitch + (abstractclientplayer.rotationPitch - abstractclientplayer.prevRotationPitch) * partialTicks;
	float f2 = abstractclientplayer.prevRotationYaw + (abstractclientplayer.rotationYaw - abstractclientplayer.prevRotationYaw) * partialTicks;
	boolean flag = true;
	boolean flag1 = true;

	if (abstractclientplayer.isHandActive())
	{
		ItemStack itemstack = abstractclientplayer.getActiveItemStack();

		if (itemstack != null && itemstack.getItem() == Items.BOW) //Forge: Data watcher can desync and cause this to NPE...
		{
			EnumHand enumhand1 = abstractclientplayer.getActiveHand();
			flag = enumhand1 == EnumHand.MAIN_HAND;
			flag1 = !flag;
		}
	}

	rotateArroundXAndY(f1, f2);
	setLightmap();
	rotateArm(partialTicks);
	GlStateManager.enableRescaleNormal();

	ItemStack itemStackMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 3);
	ItemStack itemStackOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 4);
	float equippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 5);
	float prevEquippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 6);
	float equippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 7);
	float prevEquippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 8);

	RenderCyberlimbHand.INSTANCE.itemStackMainHand = itemStackMainHand;
	RenderCyberlimbHand.INSTANCE.itemStackOffHand = itemStackOffHand;

	if (flag && !missingSecondArm)
	{
		float f3 = enumhand == EnumHand.MAIN_HAND ? f : 0.0F;
		float f5 = 1.0F - (prevEquippedProgressMainHand + (equippedProgressMainHand - prevEquippedProgressMainHand) * partialTicks);
		RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft;
		RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight;
		RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.MAIN_HAND, f3, itemStackMainHand, f5);
	}

	if (flag1 && !missingArm)
	{
		float f4 = enumhand == EnumHand.OFF_HAND ? f : 0.0F;
		float f6 = 1.0F - (prevEquippedProgressOffHand + (equippedProgressOffHand - prevEquippedProgressOffHand) * partialTicks);
		RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft;
		RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight;
		RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.OFF_HAND, f4, itemStackOffHand, f6);
	}

	GlStateManager.disableRescaleNormal();
	RenderHelper.disableStandardItemLighting();
}