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

The following are Jave code examples for showing how to use getCurrentEquippedItem() 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: BaseClient   File: BlockTNT.java   View Source Code Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (playerIn.getCurrentEquippedItem() != null)
    {
        Item item = playerIn.getCurrentEquippedItem().getItem();

        if (item == Items.flint_and_steel || item == Items.fire_charge)
        {
            this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
            worldIn.setBlockToAir(pos);

            if (item == Items.flint_and_steel)
            {
                playerIn.getCurrentEquippedItem().damageItem(1, playerIn);
            }
            else if (!playerIn.capabilities.isCreativeMode)
            {
                --playerIn.getCurrentEquippedItem().stackSize;
            }

            return true;
        }
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
}
 
Example 2
Project: DecompiledMinecraft   File: BlockTNT.java   View Source Code Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (playerIn.getCurrentEquippedItem() != null)
    {
        Item item = playerIn.getCurrentEquippedItem().getItem();

        if (item == Items.flint_and_steel || item == Items.fire_charge)
        {
            this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
            worldIn.setBlockToAir(pos);

            if (item == Items.flint_and_steel)
            {
                playerIn.getCurrentEquippedItem().damageItem(1, playerIn);
            }
            else if (!playerIn.capabilities.isCreativeMode)
            {
                --playerIn.getCurrentEquippedItem().stackSize;
            }

            return true;
        }
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
}
 
Example 3
Project: Uranium   File: WorldCapture.java   View Source Code Vote up 5 votes
public CaptureBlock startCapture(EntityPlayer pPlayer){
    ItemStack tItem=null;
    int tSlot=-1;
    if(pPlayer!=null){
        tSlot=pPlayer.inventory.currentItem;
        tItem=pPlayer.getCurrentEquippedItem();
    }
    return this.startCapture(pPlayer,tItem,tSlot);

}
 
Example 4
Project: BaseClient   File: BlockVine.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Blocks.vine, 1, 0));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 5
Project: BaseClient   File: BlockDoublePlant.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (worldIn.isRemote || player.getCurrentEquippedItem() == null || player.getCurrentEquippedItem().getItem() != Items.shears || state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.LOWER || !this.onHarvest(worldIn, pos, state, player))
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 6
Project: DecompiledMinecraft   File: BlockTripWire.java   View Source Code Vote up 5 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (!worldIn.isRemote)
    {
        if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
        {
            worldIn.setBlockState(pos, state.withProperty(DISARMED, Boolean.valueOf(true)), 4);
        }
    }
}
 
Example 7
Project: DecompiledMinecraft   File: BlockDoublePlant.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (worldIn.isRemote || player.getCurrentEquippedItem() == null || player.getCurrentEquippedItem().getItem() != Items.shears || state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.LOWER || !this.onHarvest(worldIn, pos, state, player))
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 8
Project: BaseClient   File: BlockDeadBush.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Blocks.deadbush, 1, 0));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 9
Project: BaseClient   File: BlockOldLeaf.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata()));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 10
Project: DecompiledMinecraft   File: BlockTallGrass.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Blocks.tallgrass, 1, ((BlockTallGrass.EnumType)state.getValue(TYPE)).getMeta()));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 11
Project: BaseClient   File: BlockTallGrass.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Blocks.tallgrass, 1, ((BlockTallGrass.EnumType)state.getValue(TYPE)).getMeta()));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 12
Project: BaseClient   File: EntityZombie.java   View Source Code Vote up 5 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.getCurrentEquippedItem();

    if (itemstack != null && itemstack.getItem() == Items.golden_apple && itemstack.getMetadata() == 0 && this.isVillager() && this.isPotionActive(Potion.weakness))
    {
        if (!player.capabilities.isCreativeMode)
        {
            --itemstack.stackSize;
        }

        if (itemstack.stackSize <= 0)
        {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
        }

        if (!this.worldObj.isRemote)
        {
            this.startConversion(this.rand.nextInt(2401) + 3600);
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 13
Project: BaseClient   File: BlockOldLeaf.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata()));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 14
Project: BaseClient   File: BlockTripWire.java   View Source Code Vote up 5 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (!worldIn.isRemote)
    {
        if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
        {
            worldIn.setBlockState(pos, state.withProperty(DISARMED, Boolean.valueOf(true)), 4);
        }
    }
}
 
Example 15
Project: DecompiledMinecraft   File: BlockDoublePlant.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (worldIn.isRemote || player.getCurrentEquippedItem() == null || player.getCurrentEquippedItem().getItem() != Items.shears || state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.LOWER || !this.onHarvest(worldIn, pos, state, player))
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 16
Project: DecompiledMinecraft   File: BlockVine.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Blocks.vine, 1, 0));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 17
Project: connor41-etfuturum2   File: ModEnchantments.java   View Source Code Vote up 5 votes
public static void onPlayerPickupXP(PlayerPickupXpEvent event) {
	EntityPlayer player = event.entityPlayer;
	EntityXPOrb orb = event.orb;
	if (player.worldObj.isRemote)
		return;
	if (!EtFuturum.enableMending)
		return;

	ItemStack[] stacks = new ItemStack[5];
	stacks[0] = player.getCurrentEquippedItem(); // held
	stacks[1] = player.getEquipmentInSlot(1); // boots
	stacks[2] = player.getEquipmentInSlot(2); // leggings
	stacks[3] = player.getEquipmentInSlot(3); // chestplate
	stacks[4] = player.getEquipmentInSlot(4); // helmet

	for (ItemStack stack : stacks)
		if (stack != null && stack.getItemDamage() > 0 && EnchantmentHelper.getEnchantmentLevel(mending.effectId, stack) > 0) {
			int xp = orb.xpValue;
			while (xp > 0 && stack.getItemDamage() > 0) {
				stack.setItemDamage(stack.getItemDamage() - 2);
				xp--;
			}
			if (xp <= 0) {
				orb.setDead();
				event.setCanceled(true);
				return;
			}
		}
}
 
Example 18
Project: BaseClient   File: BlockNewLeaf.java   View Source Code Vote up 5 votes
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
    {
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
        spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4));
    }
    else
    {
        super.harvestBlock(worldIn, player, pos, state, te);
    }
}
 
Example 19
Project: DecompiledMinecraft   File: BlockDoublePlant.java   View Source Code Vote up 4 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        if (worldIn.getBlockState(pos.down()).getBlock() == this)
        {
            if (!player.capabilities.isCreativeMode)
            {
                IBlockState iblockstate = worldIn.getBlockState(pos.down());
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);

                if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
                else if (!worldIn.isRemote)
                {
                    if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
                    {
                        this.onHarvest(worldIn, pos, iblockstate, player);
                        worldIn.setBlockToAir(pos.down());
                    }
                    else
                    {
                        worldIn.destroyBlock(pos.down(), true);
                    }
                }
                else
                {
                    worldIn.setBlockToAir(pos.down());
                }
            }
            else
            {
                worldIn.setBlockToAir(pos.down());
            }
        }
    }
    else if (player.capabilities.isCreativeMode && worldIn.getBlockState(pos.up()).getBlock() == this)
    {
        worldIn.setBlockState(pos.up(), Blocks.air.getDefaultState(), 2);
    }

    super.onBlockHarvested(worldIn, pos, state, player);
}
 
Example 20
Project: DecompiledMinecraft   File: BlockDoublePlant.java   View Source Code Vote up 4 votes
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
    if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        if (worldIn.getBlockState(pos.down()).getBlock() == this)
        {
            if (!player.capabilities.isCreativeMode)
            {
                IBlockState iblockstate = worldIn.getBlockState(pos.down());
                BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);

                if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
                {
                    worldIn.destroyBlock(pos.down(), true);
                }
                else if (!worldIn.isRemote)
                {
                    if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears)
                    {
                        this.onHarvest(worldIn, pos, iblockstate, player);
                        worldIn.setBlockToAir(pos.down());
                    }
                    else
                    {
                        worldIn.destroyBlock(pos.down(), true);
                    }
                }
                else
                {
                    worldIn.setBlockToAir(pos.down());
                }
            }
            else
            {
                worldIn.setBlockToAir(pos.down());
            }
        }
    }
    else if (player.capabilities.isCreativeMode && worldIn.getBlockState(pos.up()).getBlock() == this)
    {
        worldIn.setBlockState(pos.up(), Blocks.air.getDefaultState(), 2);
    }

    super.onBlockHarvested(worldIn, pos, state, player);
}