예제 #1
0
 public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
   MovingObjectPosition movingobjectposition = func_40402_a(world, entityplayer, true);
   if (movingobjectposition == null) {
     return itemstack;
   }
   if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
     int i = movingobjectposition.blockX;
     int j = movingobjectposition.blockY;
     int k = movingobjectposition.blockZ;
     if (!world.canMineBlock(entityplayer, i, j, k)) {
       return itemstack;
     }
     if (!entityplayer.canPlayerEdit(i, j, k)) {
       return itemstack;
     }
     if (world.getBlockMaterial(i, j, k) == Material.water) {
       itemstack.stackSize--;
       if (itemstack.stackSize <= 0) {
         return new ItemStack(Item.potion);
       }
       if (!entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.potion))) {
         entityplayer.dropPlayerItem(new ItemStack(Item.potion.shiftedIndex, 1, 0));
       }
     }
   }
   return itemstack;
 }
  /** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    super.onCraftGuiClosed(par1EntityPlayer);
    this.theMerchant.setCustomer((EntityPlayer) null);
    super.onCraftGuiClosed(par1EntityPlayer);

    if (!this.theWorld.isRemote) {
      ItemStack var2 = this.merchantInventory.getStackInSlotOnClosing(0);

      if (var2 != null) {
        par1EntityPlayer.dropPlayerItem(var2);
      }

      var2 = this.merchantInventory.getStackInSlotOnClosing(1);

      if (var2 != null) {
        par1EntityPlayer.dropPlayerItem(var2);
      }
    }
  }
 public void onCraftGuiClosed(EntityPlayer entityplayer) {
   super.onCraftGuiClosed(entityplayer);
   for (int i = 0; i < 4; i++) {
     ItemStack itemstack = craftMatrix.getStackInSlot(i);
     if (itemstack != null) {
       entityplayer.dropPlayerItem(itemstack);
       craftMatrix.setInventorySlotContents(i, null);
     }
   }
 }
예제 #4
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    MovingObjectPosition var4 =
        this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

    if (var4 == null) {
      return par1ItemStack;
    } else {
      if (var4.typeOfHit == EnumMovingObjectType.TILE) {
        int var5 = var4.blockX;
        int var6 = var4.blockY;
        int var7 = var4.blockZ;

        if (!par2World.canMineBlock(par3EntityPlayer, var5, var6, var7)) {
          return par1ItemStack;
        }

        if (!par3EntityPlayer.canPlayerEdit(var5, var6, var7)) {
          return par1ItemStack;
        }

        if (par2World.getBlockMaterial(var5, var6, var7) == Material.water) {
          --par1ItemStack.stackSize;

          if (par1ItemStack.stackSize <= 0) {
            return new ItemStack(Item.potion);
          }

          if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.potion))) {
            par3EntityPlayer.dropPlayerItem(new ItemStack(Item.potion.shiftedIndex, 1, 0));
          }
        }
      }

      return par1ItemStack;
    }
  }
예제 #5
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    float var4 = 1.0F;
    double var5 =
        par3EntityPlayer.prevPosX
            + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double) var4;
    double var7 =
        par3EntityPlayer.prevPosY
            + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double) var4
            + 1.62D
            - (double) par3EntityPlayer.yOffset;
    double var9 =
        par3EntityPlayer.prevPosZ
            + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double) var4;
    boolean var11 = this.isFull == 0;
    MovingObjectPosition var12 =
        this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, var11);

    if (var12 == null) {
      return par1ItemStack;
    } else {
      if (var12.typeOfHit == EnumMovingObjectType.TILE) {
        int var13 = var12.blockX;
        int var14 = var12.blockY;
        int var15 = var12.blockZ;

        if (!par2World.canMineBlock(par3EntityPlayer, var13, var14, var15)) {
          return par1ItemStack;
        }

        if (this.isFull == 0) {
          if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15, var12.sideHit, par1ItemStack)) {
            return par1ItemStack;
          }

          if (par2World.getBlockMaterial(var13, var14, var15) == Material.water
              && par2World.getBlockMetadata(var13, var14, var15) == 0) {
            par2World.setBlockToAir(var13, var14, var15);

            if (par3EntityPlayer.capabilities.isCreativeMode) {
              return par1ItemStack;
            }

            if (--par1ItemStack.stackSize <= 0) {
              return new ItemStack(Item.bucketWater);
            }

            if (!par3EntityPlayer.inventory.addItemStackToInventory(
                new ItemStack(Item.bucketWater))) {
              par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.itemID, 1, 0));
            }

            return par1ItemStack;
          }

          if (par2World.getBlockMaterial(var13, var14, var15) == Material.lava
              && par2World.getBlockMetadata(var13, var14, var15) == 0) {
            par2World.setBlockToAir(var13, var14, var15);

            if (par3EntityPlayer.capabilities.isCreativeMode) {
              return par1ItemStack;
            }

            if (--par1ItemStack.stackSize <= 0) {
              return new ItemStack(Item.bucketLava);
            }

            if (!par3EntityPlayer.inventory.addItemStackToInventory(
                new ItemStack(Item.bucketLava))) {
              par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketLava.itemID, 1, 0));
            }

            return par1ItemStack;
          }
        } else {
          if (this.isFull < 0) {
            return new ItemStack(Item.bucketEmpty);
          }

          if (var12.sideHit == 0) {
            --var14;
          }

          if (var12.sideHit == 1) {
            ++var14;
          }

          if (var12.sideHit == 2) {
            --var15;
          }

          if (var12.sideHit == 3) {
            ++var15;
          }

          if (var12.sideHit == 4) {
            --var13;
          }

          if (var12.sideHit == 5) {
            ++var13;
          }

          if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15, var12.sideHit, par1ItemStack)) {
            return par1ItemStack;
          }

          if (this.tryPlaceContainedLiquid(par2World, var5, var7, var9, var13, var14, var15)
              && !par3EntityPlayer.capabilities.isCreativeMode) {
            return new ItemStack(Item.bucketEmpty);
          }
        }
      } else if (this.isFull == 0 && var12.entityHit instanceof EntityCow) {
        return new ItemStack(Item.bucketMilk);
      }

      return par1ItemStack;
    }
  }