Java Code Examples for net.minecraft.entity.EntityLivingBase#isSneaking()

The following examples show how to use net.minecraft.entity.EntityLivingBase#isSneaking() . 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: LayerTofunianHeldItem.java    From TofuCraftReload with MIT License 6 votes vote down vote up
private void renderHeldItem(EntityLivingBase p_188358_1_, ItemStack p_188358_2_, ItemCameraTransforms.TransformType p_188358_3_, EnumHandSide handSide)
{
    if (!p_188358_2_.isEmpty())
    {
        GlStateManager.pushMatrix();

        if (p_188358_1_.isSneaking())
        {
            GlStateManager.translate(0.0F, 0.2F, 0.0F);
        }
        // Forge: moved this call down, fixes incorrect offset while sneaking.
        this.translateToHand(handSide);
        GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
        boolean flag = handSide == EnumHandSide.LEFT;
        GlStateManager.translate((float)(flag ? -1 : 1) / 60.0F, 0.125F, -0.25F);
        Minecraft.getMinecraft().getItemRenderer().renderItemSide(p_188358_1_, p_188358_2_, p_188358_3_, flag);
        GlStateManager.popMatrix();
    }
}
 
Example 2
Source File: RenderUtils.java    From SimplyJetpacks with MIT License 6 votes vote down vote up
public static ModelBiped getArmorModel(PackBase pack, EntityLivingBase entity) {
    ModelBiped model = null;
    switch (pack.armorModel) {
    case JETPACK:
        model = ModelJetpack.INSTANCE;
        break;
    case FLUX_PACK:
        model = ModelFluxPack.INSTANCE;
    default:
    }
    if (model == null) {
        return null;
    }
    model.isSneak = entity.isSneaking();
    model.isRiding = entity.isRiding();
    model.isChild = entity.isChild();
    model.heldItemRight = entity.getEquipmentInSlot(0) != null ? 1 : 0;
    if (entity instanceof EntityPlayer) {
        model.aimedBow = ((EntityPlayer) entity).getItemInUseDuration() > 2;
    }
    return model;
}
 
Example 3
Source File: BlockSpeedTelegraph.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 4
Source File: BlockShipHelm.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 5
Source File: BlockGearbox.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }
    return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
 
Example 6
Source File: BlockLiftLever.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }
    return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
 
Example 7
Source File: BlockCaptainsChair.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX,
    float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 8
Source File: BlockPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    EnumFacing playerFacing = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        playerFacing = playerFacing.getOpposite();
    }

    // Find the facing that's closest to what the player wanted.
    EnumFacing facingHorizontal;
    if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing)) {
        facingHorizontal = playerFacing;
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.rotateY())) {
        facingHorizontal = playerFacing.rotateY();
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.rotateYCCW())) {
        facingHorizontal = playerFacing.rotateYCCW();
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.getOpposite())) {
        facingHorizontal = playerFacing.getOpposite();
    } else {
        // There was no valid facing! How the did this method even get called!
        throw new IllegalStateException(
            "Cannot find valid state for placement for Physics Infuser!");
    }

    return this.getDefaultState()
        .withProperty(FACING, facingHorizontal)
        .withProperty(INFUSER_LIGHT_ON, false);
}
 
Example 9
Source File: ItemKimono.java    From Sakura_mod with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public static ModelBiped getKimonoModel(EntityLivingBase entityLiving, ItemStack itemStack,ModelBiped model)
{
  if (model != null)
  {
    model.setVisible(true);
    
    model.isSneak = entityLiving.isSneaking();
    
    model.isRiding = entityLiving.isRiding();
    model.isChild = entityLiving.isChild();
    ItemStack itemstack = entityLiving.getHeldItemMainhand();
    ItemStack itemstack1 = entityLiving.getHeldItemOffhand();
    ModelBiped.ArmPose modelbiped$armpose = ModelBiped.ArmPose.EMPTY;
    ModelBiped.ArmPose modelbiped$armpose1 = ModelBiped.ArmPose.EMPTY;
    if ((itemstack != null) && (!itemstack.isEmpty()))
    {
      modelbiped$armpose = ModelBiped.ArmPose.ITEM;
      if (entityLiving.getItemInUseCount() > 0)
      {
        EnumAction enumaction = itemstack.getItemUseAction();
        if (enumaction == EnumAction.BLOCK) {
          modelbiped$armpose = ModelBiped.ArmPose.BLOCK;
        } else if (enumaction == EnumAction.BOW) {
          modelbiped$armpose = ModelBiped.ArmPose.BOW_AND_ARROW;
        }
      }
    }
    if ((itemstack1 != null) && (!itemstack1.isEmpty()))
    {
      modelbiped$armpose1 = ModelBiped.ArmPose.ITEM;
      if (entityLiving.getItemInUseCount() > 0)
      {
        EnumAction enumaction1 = itemstack1.getItemUseAction();
        if (enumaction1 == EnumAction.BLOCK) {
          modelbiped$armpose1 = ModelBiped.ArmPose.BLOCK;
        }
      }
    }
    if (entityLiving.getPrimaryHand() == EnumHandSide.RIGHT)
    {
      model.rightArmPose = modelbiped$armpose;
      model.leftArmPose = modelbiped$armpose1;
    }
    else
    {
      model.rightArmPose = modelbiped$armpose1;
      model.leftArmPose = modelbiped$armpose;
    }
  }
  return model;
}
 
Example 10
Source File: ItemLegUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void playerJumps(LivingEvent.LivingJumpEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 0);
	if (CyberwareAPI.isCyberwareInstalled(e, test))
	{
		int numLegs = 0;
		if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(CyberwareContent.cyberlimbs, 1, 2)))
		{
			numLegs++;
		}
		if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(CyberwareContent.cyberlimbs, 1, 3)))
		{
			numLegs++;
		}
		ICyberwareUserData ware = CyberwareAPI.getCapability(e);
		if (ware.usePower(test, this.getPowerConsumption(test)))
		{
			if (e.isSneaking())
			{
				Vec3d vector = e.getLook(0.5F);
				double total = Math.abs(vector.zCoord + vector.xCoord);
				double jump = 0;
				if (jump >= 1)
				{
					jump = (jump + 2D) / 4D;
				}

				double y = vector.yCoord < total ? total : vector.yCoord;

				e.motionY += (numLegs * ((jump + 1) * y)) / 3F;
				e.motionZ += (jump + 1) * vector.zCoord * numLegs;
				e.motionX += (jump + 1) * vector.xCoord * numLegs;
			}
			else
			{
				e.motionY += numLegs * (0.2750000059604645D / 2D);
			}
		}
	}
}
 
Example 11
Source File: RendererBackpack.java    From WearableBackpacks with MIT License 4 votes vote down vote up
public void doRenderLayer(EntityLivingBase entity, float limbSwing, float limbSwingAmount,
                          float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
	
	IBackpack backpack;
	RenderOptions renderOptions;
	if (_overrideBackpack != null) {
		backpack = _overrideBackpack;
		renderOptions = _overrideRenderOptions;
	} else {
		backpack = BackpackHelper.getBackpack(entity);
		BackpackEntityEntry entry = BackpackRegistry.getEntityEntry(entity.getClass());
		renderOptions = (entry != null) ? entry.renderOptions : null;
	}
	if ((backpack == null) || (renderOptions == null)) return;
	
	GlStateManager.pushMatrix();
	
	if (entity.isChild()) {
		GlStateManager.scale(0.5F, 0.5F, 0.5F);
		GlStateManager.translate(0.0F, 24.0F * scale, 0.0F);
	}
	
	ModelBase modelBase = this.livingEntityRenderer.getMainModel();
	if (modelBase instanceof ModelBiped) {
		ModelRenderer bipedBody = ((ModelBiped) modelBase).bipedBody;
		
		if (entity.isSneaking()) {
			// FIXME: Can be sneaking while flying with the elytra, then backpack is misaligned..?
			GlStateManager.translate(0.0F, 0.2F, 0.0F);
		}
		
		bipedBody.postRender(scale);
	} else {
		// Fallback to the custom way of transforming the backpack.
		// Make backpack swing with body as players swing their arms.
		float swingProgress = entity.getSwingProgress(partialTicks);
		float swingAngle = MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float)Math.PI * 2.0F)) * 0.2F;
		if ((entity.swingingHand == EnumHand.OFF_HAND) ^
		    (entity.getPrimaryHand() == EnumHandSide.LEFT)) swingAngle *= -1;
		if (swingAngle != 0) GlStateManager.rotate((float)Math.toDegrees(swingAngle), 0.0F, 1.0F, 0.0F);
		
		// Rotate backpack if entity is sneaking.
		if (entity.isSneaking()) {
			// FIXME: Can be sneaking while flying with the elytra, then backpack is misaligned..?
			GlStateManager.translate(0.0F, 0.2F, 0.0F);
			GlStateManager.rotate(90.0F / (float)Math.PI, 1.0F, 0.0F, 0.0F);
		}
	}
	
	GlStateManager.scale(renderOptions.scale, renderOptions.scale, renderOptions.scale);
	GlStateManager.translate(8.0F * scale, renderOptions.y * scale, renderOptions.z * scale);
	GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
	GlStateManager.rotate((float)renderOptions.rotate, 1.0F, 0.0F, 0.0F);
	GlStateManager.translate(0, ProxyClient.MODEL_BACKPACK_BOX.maxY * scale * -16,
	                            ProxyClient.MODEL_BACKPACK_BOX.minZ * scale * -16);
	
	renderBackpack(backpack, entity.ticksExisted + partialTicks, false);
	
	GlStateManager.popMatrix();
	
}
 
Example 12
Source File: BlockHardMEDrive.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	super.onBlockPlacedBy(world, x, y, z, player, itemstack);
	int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

	if (!player.isSneaking())
	{
		if (l == 0)
		{
			world.setBlockMetadataWithNotify(x, y, z, 2, 2);
		}

		if (l == 1)
		{
			world.setBlockMetadataWithNotify(x, y, z, 5, 2);
		}

		if (l == 2)
		{
			world.setBlockMetadataWithNotify(x, y, z, 3, 2);
		}

		if (l == 3)
		{
			world.setBlockMetadataWithNotify(x, y, z, 4, 2);
		}
	} else
	{
		if (l == 0)
		{
			world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(2).getOpposite().ordinal(), 2);
		}

		if (l == 1)
		{
			world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(5).getOpposite().ordinal(), 2);
		}

		if (l == 2)
		{
			world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(3).getOpposite().ordinal(), 2);
		}

		if (l == 3)
		{
			world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(4).getOpposite().ordinal(), 2);
		}
	}
}
 
Example 13
Source File: ColorBlock.java    From ExtraCells1 with MIT License 4 votes vote down vote up
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	ForgeDirection orientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));

	TileEntity clickedOnTileEntity = world.getBlockTileEntity(x + orientation.getOpposite().offsetX, y + orientation.getOpposite().offsetY, z + orientation.getOpposite().offsetZ);
	TileEntity blockTileEntity = world.getBlockTileEntity(x, y, z);

	if (blockTileEntity instanceof IColoredMETile)
	{
		if (clickedOnTileEntity instanceof IColoredMETile)
		{

			// All this shit to make it compatible w/ AE 13 AND 14 :D
			Method isColoredMethod = null;
			boolean isColored = false;

			try
			{
				// Method for AE 14 (With forgeDireciton argument)
				isColoredMethod = ((IColoredMETile) clickedOnTileEntity).getClass().getDeclaredMethod("isColored", ForgeDirection.class);
				isColored = (Boolean) isColoredMethod.invoke((IColoredMETile) clickedOnTileEntity, orientation);
			} catch (Throwable ex)
			{
				try
				{
					// Method for AE 13 (W/O the argument)
					isColoredMethod = ((IColoredMETile) clickedOnTileEntity).getClass().getDeclaredMethod("isColored");
					isColored = (Boolean) isColoredMethod.invoke(clickedOnTileEntity);
				} catch (Throwable e)
				{
				}
			}

			if (isColored)
			{
				((IColoredMETile) blockTileEntity).setColor(((IColoredMETile) clickedOnTileEntity).getColor());
			} else
			{
				((IColoredMETile) blockTileEntity).setColor(-1);
			}
		} else
		{
			((IColoredMETile) blockTileEntity).setColor(-1);
		}
	}

	if (player.isSneaking())
	{
		world.setBlockMetadataWithNotify(x, y, z, orientation.getOpposite().ordinal(), 3);
	}
}