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

The following are Jave code examples for showing how to use isSneaking() 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: Mods   File: EntityTF2Character.java   View Source Code Vote up 6 votes
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
	if (!(player.getHeldItemMainhand() != null
			&& player.getHeldItemMainhand().getItem() instanceof ItemMonsterPlacerPlus)
			&& (this.getOwner() == player || this.getAttackTarget() == null || this.friendly) && this.isEntityAlive() && !this.isTrading()
			&& !this.isChild() && !player.isSneaking()) {
		if (this.world.isRemote && player.getTeam() == null
				&& ((this.getCapability(TF2weapons.WEAPONS_CAP, null).state & 1) == 0 || this.friendly)
				&& !player.isCreative())
			ClientProxy.displayScreenConfirm("Choose a team to interact",
					"Visit the Mann Co. Store located in a village");
		if (!this.world.isRemote && (TF2Util.isOnSameTeam(this, player) || player.isCreative())
				&& (this.tradeOffers == null || !this.tradeOffers.isEmpty())) {
			this.setCustomer(player);
			FMLNetworkHandler.openGui(player, TF2weapons.instance, 4, world, this.getEntityId(), 0, 0);
		}

		player.addStat(StatList.TALKED_TO_VILLAGER);
		return true;
	} else
		return super.processInteract(player, hand);
}
 
Example 2
Project: ArcaneMagic   File: BlockInfusionAltar.java   View Source Code Vote up 6 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (!player.isSneaking())
	{
		if (world.isRemote)
		{
			return true;
		}
		TileEntity te = world.getTileEntity(pos);
		if (!(te instanceof TileEntityInfusionAltar))
		{
			return false;
		}
		player.openGui(ArcaneMagic.instance, GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
		return true;
	}
	return false;
}
 
Example 3
Project: Mods   File: EntitySaxtonHale.java   View Source Code Vote up 6 votes
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
	if (!(player.getHeldItemMainhand() != null
			&& player.getHeldItemMainhand().getItem() instanceof ItemMonsterPlacerPlus)
			&& this.getAttackTarget() == null && this.isEntityAlive() && !this.isTrading() && !this.isChild()
			&& !player.isSneaking()) {
		if (this.world.isRemote && player.getTeam() == null && !player.isCreative())
			ClientProxy.displayScreenJoinTeam();
		else if (!this.world.isRemote && (player.getTeam() != null || player.isCreative())
				&& (this.tradeOffers == null || !this.tradeOffers.isEmpty())) {
			this.setCustomer(player);
			player.displayVillagerTradeGui(this);
		}

		player.addStat(StatList.TALKED_TO_VILLAGER);
		return true;
	} else
		return super.processInteract(player, hand);
}
 
Example 4
Project: minecraft-quiverbow   File: ProximityNeedler.java   View Source Code Vote up 6 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	if (world.isRemote) { return stack; }								// Not doing this on client side
	if (this.getDamage(stack) >= this.getMaxDamage()) { return stack; }	// Is empty

	if (player.isSneaking())	// Dropping the magazine
	{
		this.dropMagazine(world, stack, player);
		return stack;
	}

	if (this.getDamage(stack) >= this.getMaxDamage() - 7) { return stack; }	// Doesn't have enough ammo in it)

	this.doSingleFire(stack, world, player);	// Handing it over to the neutral firing function
	return stack;
}
 
Example 5
Project: minecraft-quiverbow   File: CoinTosser.java   View Source Code Vote up 6 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	//player.setItemInUse(stack, 60);	// Let's try that on both sides...

	if (world.isRemote) { return stack; }								// Not doing this on client side
	if (this.getDamage(stack) >= this.getMaxDamage()) { return stack; }	// Is empty

	if (player.isSneaking())	// Dropping the magazine
	{
		this.dropMagazine(world, stack, player);
		return stack;
	}

	this.doSingleFire(stack, world, player);	// Handing it over to the neutral firing function
	return stack;
}
 
Example 6
Project: FundamentalChemistry   File: BlockMoleculeAssembler.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos,
		IBlockState state, EntityPlayer player, EnumFacing side, float hitX,
		float hitY, float hitZ) 
{
   if (!world.isRemote){
		if(player.isSneaking())
   		player.openGui(FundamentalChemistry.instance, ForgeGuiHandler.CHEMICAL_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
		else
			player.openGui(FundamentalChemistry.instance, ForgeGuiHandler.SIMPLE_MACHINE, world, pos.getX(), pos.getY(), pos.getZ());
   }
	
	return true;
}
 
Example 7
Project: pnc-repressurized   File: ItemLogisticsConfigurator.java   View Source Code Vote up 5 votes
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote && stack.getMaxDamage() - stack.getItemDamage() >= 100) {
        List<ISemiBlock> semiBlocks = SemiBlockManager.getInstance(world).getSemiBlocksAsList(world, pos);
        
        if(semiBlocks.isEmpty()){
            pos = pos.offset(side);
            semiBlocks = SemiBlockManager.getInstance(world).getSemiBlocksAsList(world, pos);
        }

        if (!semiBlocks.isEmpty()) {
            if (player.isSneaking()) {
                semiBlocks.forEach(s -> SemiBlockManager.getInstance(world).breakSemiBlock(s, player));
                return EnumActionResult.SUCCESS;
            } else {
                //TODO raytrace?
                if (semiBlocks.stream().anyMatch(s -> s.onRightClickWithConfigurator(player))) {
                    addAir(stack, -PneumaticValues.USAGE_LOGISTICS_CONFIGURATOR);
                    return EnumActionResult.SUCCESS;
                }
            }
        }
    } else if (world.isRemote) {
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
 
Example 8
Project: pnc-repressurized   File: ItemCamoApplicator.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    // right-click air: clear any camo
    ItemStack stack = playerIn.getHeldItem(handIn);
    if (!worldIn.isRemote && playerIn.isSneaking() && getCamoState(stack) != null) {
        setCamoState(stack, null);
    }
    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
 
Example 9
Project: OpenSensors   File: BlockSensor.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float clickX, float clickY, float clickZ) {
	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if (tileEntity == null || player.isSneaking()) {
		return false;
	}
	player.openGui(OpenSensors.instance, 0, world, x, y, z);
	return true;
}
 
Example 10
Project: pnc-repressurized   File: BlockPneumaticCraft.java   View Source Code Vote up 5 votes
@Override
public boolean rotateBlock(World world, EntityPlayer player, BlockPos pos, EnumFacing side) {
    if (player.isSneaking()) {
        if (!player.capabilities.isCreativeMode) dropBlockAsItem(world, pos, world.getBlockState(pos), 0);
        world.setBlockToAir(pos);
        return true;
    } else {
        if (isRotatable()) {
            IBlockState state = world.getBlockState(pos);
            if (!rotateCustom(world, pos, state, side)) {
                if (rotateForgeWay()) {
                    if (!canRotateToTopOrBottom()) side = EnumFacing.UP;
                    if (getRotation(world, pos).getAxis() != side.getAxis()) {
                        setRotation(world, pos, getRotation(world, pos).rotateAround(side.getAxis()));
                    }
                } else {
                    EnumFacing f = getRotation(world, pos);
                    do {
                        f = EnumFacing.getFront(f.ordinal() + 1);
                    } while (!canRotateToTopOrBottom() && f.getAxis() == Axis.Y);
                    setRotation(world, pos, f);
                }
                TileEntityBase te = (TileEntityBase) world.getTileEntity(pos);
                if (te != null) te.onBlockRotated();
            }
            return true;
        } else {
            return false;
        }
    }
}
 
Example 11
Project: minecraft-quiverbow   File: LargeRedstoneMagazine.java   View Source Code Vote up 5 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) 
   {  
	if (world.isRemote) { return stack; }				// Not doing this on client side
	if (stack.getItemDamage() == 0) { return stack; }	// Already fully loaded
	
	if (player.isSneaking())
	{
		this.fillEight(stack, world, player);
		return stack;
	}
	// else, not sneaking, so just filling one
	
	boolean doSFX = false;
	
	if (player.inventory.hasItem(Items.redstone))
	{
		int dmg = stack.getItemDamage() - 1;
		stack.setItemDamage(dmg);
		
		player.inventory.consumeInventoryItem(Items.redstone);	// We're just grabbing what we need from the inventory
		
		// SFX
		doSFX = true;
	}
	// else, doesn't have what it takes
	
	if (doSFX) { world.playSoundAtEntity(player, "random.wood_click", 0.5F, 0.3F); }
	
	return stack;
   }
 
Example 12
Project: pnc-repressurized   File: BlockAphorismTile.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote && player.getHeldItem(hand).isEmpty() && !player.isSneaking()) {
        player.openGui(PneumaticCraftRepressurized.instance, EnumGuiId.APHORISM_TILE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
        sendEditorMessage(player);
    }
    return true;
}
 
Example 13
Project: SimpleTubes   File: BlockDisplacer.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

	if (!world.isRemote) {

		ItemStack held = player.getHeldItem(hand);

		if (player.isSneaking()) {

			if (state.getValue(FILTER) && ((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
				state = state.withProperty(FILTER, false);
				world.setBlockState(pos, state);

				if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileDisplacer) {
					((TileDisplacer) world.getTileEntity(pos)).setHasFilter(false);
					((TileDisplacer) world.getTileEntity(pos)).markDirty();

					PacketHandler.sendToAll(new PacketDisplacerSync(((TileDisplacer) world.getTileEntity(pos)), false));
					if (!player.isCreative())
						InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(SimpleTubes.proxy.itemUpgrade, 1, 0));
				}
			}
			return true;
		} else {
			if (!(held.getItem() instanceof ItemUpgrade) || held == ItemStack.EMPTY) {
				if (((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
					player.openGui(SimpleTubes.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
					return true;
				}
			}
		}
	}

	return true;
}
 
Example 14
Project: minecraft-quiverbow   File: SugarEngine.java   View Source Code Vote up 5 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	if (world.isRemote) { return stack; }								// Not doing this on client side
	if (this.getDamage(stack) >= this.getMaxDamage()) { return stack; }	// Is empty

	if (player.isSneaking())	// Dropping the magazine
	{
		this.dropMagazine(world, stack, player);
		return stack;
	}

	this.doSingleFire(stack, world, player);	// Handing it over to the neutral firing function
	return stack;
}
 
Example 15
Project: Bewitchment   File: ItemTarots.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
	if (playerIn.isSneaking()) {
		ItemStack stack = playerIn.getHeldItem(handIn);
		if (!stack.hasTagCompound())
			stack.setTagCompound(new NBTTagCompound());
		stack.getTagCompound().setString("read_id", EntityPlayer.getUUID(playerIn.getGameProfile()).toString());
		stack.getTagCompound().setString("read_name", playerIn.getDisplayNameString());
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
	}
	return super.onItemRightClick(worldIn, playerIn, handIn);
}
 
Example 16
Project: FundamentalChemistry   File: BlockItemAnalyzer.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos,
		IBlockState state, EntityPlayer player, EnumFacing side, float hitX,
		float hitY, float hitZ) 
{
   if (!world.isRemote){
		if(player.isSneaking())
   		player.openGui(FundamentalChemistry.instance, ForgeGuiHandler.CHEMICAL_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
		else
			player.openGui(FundamentalChemistry.instance, ForgeGuiHandler.SIMPLE_MACHINE, world, pos.getX(), pos.getY(), pos.getZ());
   }
	
	return true;
}
 
Example 17
Project: pnc-repressurized   File: DroneAIBlockInteract.java   View Source Code Vote up 4 votes
private boolean rightClick(BlockPos pos) {
    EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World world = drone.world();
    ItemStack stack = player.getHeldItemMainhand();

    player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
    player.rotationPitch = faceDir.getFrontOffsetY() * -90;
    player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);

    float hitX = (float)(player.posX - pos.getX());
    float hitY = (float)(player.posY - pos.getY());
    float hitZ = (float)(player.posZ - pos.getZ());

    // this is adapted from PlayerInteractionManager#processRightClickBlock()
    try {
        PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(),  ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
        if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
            return false;
        }

        EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
        if (ret != EnumActionResult.PASS) return false;

        boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
        EnumActionResult result = EnumActionResult.PASS;

        if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            IBlockState iblockstate = world.getBlockState(pos);
            if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
                    result = EnumActionResult.SUCCESS;
                }
        }

        if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
            return false;
        }

        if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
            Block block = ((ItemBlock)stack.getItem()).getBlock();
            if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
                return false;
            }
        }

        if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
                || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            ItemStack copyBeforeUse = stack.copy();
            result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
            if (result == EnumActionResult.PASS) {
                ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
                player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
            }
            if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
            }
        }

        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
 
Example 18
Project: MagicWinds   File: IRenderBauble.java   View Source Code Vote up 4 votes
/**
 * Rotates the render for a bauble correctly if the player is sneaking.
 * Use for renders under {@link RenderType#BODY}.
 */
public static void rotateIfSneaking(EntityPlayer player) {
	if(player.isSneaking())
		applySneakingRotation();
}
 
Example 19
Project: Adventurers-Toolbox   File: ItemATHammer.java   View Source Code Vote up 4 votes
public List<BlockPos> getExtraBlocks(World world, RayTraceResult rt, EntityPlayer player) {
	List<BlockPos> positions = new ArrayList<BlockPos>();
	BlockPos pos = rt.getBlockPos();
	
	if (rt == null || rt.getBlockPos() == null || rt.sideHit == null) {
		return positions;
	}

	if (player.isSneaking()) {
		return positions;
	}

	switch (rt.sideHit.getAxis()) {
		case Y:
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.NORTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.EAST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.SOUTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.WEST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.NORTH).offset(EnumFacing.EAST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.EAST).offset(EnumFacing.SOUTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.SOUTH).offset(EnumFacing.WEST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.WEST).offset(EnumFacing.NORTH), positions);
			break;
		case X:
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.NORTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.UP), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.SOUTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.DOWN), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.NORTH).offset(EnumFacing.UP), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.UP).offset(EnumFacing.SOUTH), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.SOUTH).offset(EnumFacing.DOWN), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.DOWN).offset(EnumFacing.NORTH), positions);
			break;
		case Z:
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.DOWN), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.EAST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.UP), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.WEST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.DOWN).offset(EnumFacing.EAST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.EAST).offset(EnumFacing.UP), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.UP).offset(EnumFacing.WEST), positions);
			attemptAddExtraBlock(world, pos, pos.offset(EnumFacing.WEST).offset(EnumFacing.DOWN), positions);
			break;
	}

	return positions;
}
 
Example 20
Project: Backmemed   File: EntitySkeletonHorse.java   View Source Code Vote up 4 votes
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);
    boolean flag = !itemstack.func_190926_b();

    if (flag && itemstack.getItem() == Items.SPAWN_EGG)
    {
        return super.processInteract(player, hand);
    }
    else if (!this.isTame())
    {
        return false;
    }
    else if (this.isChild())
    {
        return super.processInteract(player, hand);
    }
    else if (player.isSneaking())
    {
        this.openGUI(player);
        return true;
    }
    else if (this.isBeingRidden())
    {
        return super.processInteract(player, hand);
    }
    else
    {
        if (flag)
        {
            if (itemstack.getItem() == Items.SADDLE && !this.isHorseSaddled())
            {
                this.openGUI(player);
                return true;
            }

            if (itemstack.interactWithEntity(player, this, hand))
            {
                return true;
            }
        }

        this.mountTo(player);
        return true;
    }
}