package com.lothrazar.cyclicmagic.item;
import java.util.List;
import com.lothrazar.cyclicmagic.IHasRecipe;
import com.lothrazar.cyclicmagic.util.UtilChat;
import com.lothrazar.cyclicmagic.util.UtilNBT;
import com.lothrazar.cyclicmagic.util.UtilSound;
import net.minecraft.block.BlockLever;
import net.minecraft.block.BlockStoneSlab;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemPasswordRemote extends BaseItem implements IHasRecipe {
  public ItemPasswordRemote() {
    this.setMaxStackSize(1);
  }
  @SideOnly(Side.CLIENT)
  public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
    BlockPos pointer = UtilNBT.getItemStackBlockPos(stack);
    if (pointer != null) {
      tooltip.add(TextFormatting.RED + UtilChat.blockPosToString(pointer));
    }
    super.addInformation(stack, playerIn, tooltip, advanced);
  }
  public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.getBlockState(pos).getBlock() instanceof BlockLever) {
      UtilNBT.setItemStackBlockPos(stack, pos);
      if (worldIn.isRemote)
        UtilChat.addChatMessage(playerIn, this.getUnlocalizedName() + ".saved");
      UtilSound.playSound(playerIn, SoundEvents.BLOCK_LEVER_CLICK);
    }
    return EnumActionResult.PASS;
  }
  @Override
  public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    BlockPos pointer = UtilNBT.getItemStackBlockPos(stack);
    if (pointer == null) {
      if (worldIn.isRemote)
        UtilChat.addChatMessage(playerIn, this.getUnlocalizedName() + ".invalid");
      return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
    }
    IBlockState blockState = worldIn.getBlockState(pointer);
    if (blockState == null || blockState.getBlock() != Blocks.LEVER) {
      UtilChat.addChatMessage(playerIn, this.getUnlocalizedName() + ".invalid");
      return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
    }
    boolean hasPowerHere = blockState.getValue(BlockLever.POWERED);//this.block.getStrongPower(blockState, worldIn, pointer, EnumFacing.UP) > 0;
    worldIn.setBlockState(pointer, blockState.withProperty(BlockLever.POWERED, !hasPowerHere));
    UtilSound.playSound(playerIn, SoundEvents.BLOCK_LEVER_CLICK);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
  }
  @Override
  public void addRecipe() {
    GameRegistry.addShapelessRecipe(new ItemStack(this),
        new ItemStack(Blocks.STONE_SLAB, 1, BlockStoneSlab.EnumType.STONE.getMetadata()),
        Blocks.STONE_BUTTON,
        Blocks.LEVER);
  }
}

@@ -1795,32 +1795,33 @@
 orldIn.isRemote)
+%7B
 %0A        UtilCha
@@ -1882,24 +1882,32 @@
  %22.saved%22);%0A
+      %7D%0A
       UtilSo
@@ -1962,26 +1962,180 @@
 CLICK);%0A    
-%7D%0A
+  return EnumActionResult.SUCCESS;%0A    %7D%0A    else%7B%0A      boolean success = false;%0A      success = trigger(stack, worldIn, playerIn);%0A      if (success)%0A    
     return E
@@ -2154,14 +2154,78 @@
 ult.
-PA
+SUCCE
 SS;%0A
+      else%0A        return EnumActionResult.FAIL;%0A     %0A    %7D%0A
   %7D%0A
@@ -2354,24 +2354,362 @@
 and hand) %7B%0A
+    boolean success = false;%0A    success = trigger(stack, worldIn, playerIn);%0A    if (success)%0A      return new ActionResult%3CItemStack%3E(EnumActionResult.SUCCESS, stack);%0A    else%0A      return new ActionResult%3CItemStack%3E(EnumActionResult.FAIL, stack);%0A  %7D%0A  private boolean trigger(ItemStack stack, World worldIn, EntityPlayer playerIn) %7B%0A
     BlockPos
@@ -2810,16 +2810,18 @@
 sRemote)
+ %7B
 %0A       
@@ -2906,80 +2906,49 @@
     
-return new ActionResult%3CItemStack%3E(EnumActionResult.FAIL, stack);%0A    %7D%0A
+%7D%0A      return false;%0A    %7D%0A    else %7B%0A  
     
@@ -3004,16 +3004,18 @@
 inter);%0A
+  
     if (
@@ -3079,24 +3079,26 @@
 ER) %7B%0A      
+ 
+ 
 UtilChat.add
@@ -3170,80 +3170,49 @@
     
+  
 return 
-new ActionResult%3CItemStack%3E(EnumActionResult.FAIL, stack);%0A    %7D%0A
+false;%0A      %7D%0A      else %7B%0A    
     
@@ -3356,16 +3356,20 @@
  0;%0A    
+  
+  
 worldIn.
@@ -3448,24 +3448,28 @@
 owerHere));%0A
+    
     UtilSoun
@@ -3530,76 +3530,38 @@
     
+ 
+   
 return 
-new ActionResult%3CItemStack%3E(EnumActionResult.SUCCESS, stack);
+true;%0A      %7D%0A    %7D
 %0A  %7D

update password user so it works in the automated user