Exemple #1
0
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float par7,
      float par8,
      float par9) {
    ItemStack stack = player.inventory.getCurrentItem();
    if (stack != null && stack.getItem().itemID == ZapApples.jamBucket.itemID) {
      if (world.getBlockMetadata(x, y, z) == 0) {
        if (!world.isRemote) {
          world.setBlockMetadataWithNotify(x, y, z, 1);

          if (stack.stackSize > 1) {
            stack.stackSize--;
          } else {
            stack = null;
          }

          if (!player.capabilities.isCreativeMode) {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
          }
          if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bucketEmpty))) {
            player.dropPlayerItem(new ItemStack(Item.bucketEmpty));
          }
        }
      }
      return true;
    } else if (stack != null && stack.getItem().itemID == Item.bucketEmpty.itemID) {
      if (world.getBlockMetadata(x, y, z) == 1) {
        if (!world.isRemote) {
          world.setBlockMetadataWithNotify(x, y, z, 0);

          if (stack != null && stack.stackSize > 1) {
            stack.stackSize--;
          } else {
            stack = null;
          }

          if (!player.capabilities.isCreativeMode) {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
          }
          if (!player.inventory.addItemStackToInventory(new ItemStack(ZapApples.jamBucket))) {
            player.dropPlayerItem(new ItemStack(ZapApples.jamBucket));
          }
        }
      }
      return true;
    }
    return false;
  }
Exemple #2
0
  public void onPlayerStoppedUsing(
      ItemStack itemstack, World world, EntityPlayer player, int count) {
    // subtracts the itemInUseCount [that i dont fully understand at this point] from the max use
    // duration//
    int var6 = this.getMaxItemUseDuration(itemstack) - count;

    // all i know is it turns the result from var6 into a float//
    float var7 = (float) var6 / 20.0F;
    var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

    if (var7 >= time) {
      if (player.isSneaking()) {
        if (itemstack.getItemDamage() != 0) {
          itemstack.stackSize--;

          world.playSoundAtEntity(player, "mint.quantumcoins.conversion", 1.0F, 1.0F);

          if (player.inventory.addItemStackToInventory(
                  new ItemStack(
                      QuantumCoins.coin, ConfigHelper.convertAmount, itemstack.getItemDamage() - 1))
              == false) {
            player.dropPlayerItem(
                new ItemStack(
                    QuantumCoins.coin, ConfigHelper.convertAmount, itemstack.getItemDamage() - 1));
          }
        }
      } else {
        if ((itemstack.stackSize >= ConfigHelper.convertAmount)
            && (itemstack.getItemDamage() != ConfigHelper.coinNum - 1)) {
          itemstack.stackSize -= ConfigHelper.convertAmount;

          world.playSoundAtEntity(player, "mint.quantumcoins.conversion", 1.0F, 0.0F);

          if (player.inventory.addItemStackToInventory(
                  new ItemStack(QuantumCoins.coin, 1, itemstack.getItemDamage() + 1))
              == false) {
            player.dropPlayerItem(
                new ItemStack(QuantumCoins.coin, 1, itemstack.getItemDamage() + 1));
          }
        }
      }
    } else {
      player.worldObj.spawnParticle(
          "smoke", player.posX, player.posY, player.posZ, 0.0D, 0.0D, 0.0D);
    }

    rang = false;
  }
  /** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    InventoryPlayer var2 = par1EntityPlayer.inventory;

    if (var2.getItemStack() != null) {
      par1EntityPlayer.dropPlayerItem(var2.getItemStack());
      var2.setItemStack((ItemStack) null);
    }
  }
 @Override
 public void onContainerClosed(EntityPlayer par1EntityPlayer) {
   super.onContainerClosed(par1EntityPlayer);
   if (!worldObj.isRemote) {
     for (int var2 = 0; var2 < 9; ++var2) {
       ItemStack var3 = craftMatrix.getStackInSlotOnClosing(var2);
       if (var3 != null) par1EntityPlayer.dropPlayerItem(var3);
     }
   }
 }
  /** 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 onContainerClosed(EntityPlayer entityplayer) {
   super.onContainerClosed(entityplayer);
   if (worldObj.isRemote) {
     return;
   }
   for (int i = 0; i < 9; i++) {
     ItemStack itemstack = craftMatrix.getStackInSlot(i);
     if (itemstack != null) {
       entityplayer.dropPlayerItem(itemstack);
     }
   }
 }
  @Override
  public void onContainerClosed(EntityPlayer par1EntityPlayer) {
    super.onContainerClosed(par1EntityPlayer);

    if (!this.worldObj.isRemote) {
      for (int var2 = 1; var2 < this.craftMatrix.getSizeInventory(); ++var2) {
        final ItemStack var3 = this.craftMatrix.getStackInSlotOnClosing(var2);

        if (var3 != null) {
          par1EntityPlayer.dropPlayerItem(var3);
        }
      }
    }
  }
  @Override
  public void onCraftGuiClosed(EntityPlayer entityPlayer) {
    super.onCraftGuiClosed(entityPlayer);

    if (!this.world.isRemote) {
      List<ItemStack> dropItemList = new ArrayList<ItemStack>();

      for (int i = 0; i < this.inventoryEnchanter.getSizeInventory(); ++i) {
        dropItemList.add(this.inventoryEnchanter.getStackInSlotOnClosing(i));
      }

      for (ItemStack dropItem : dropItemList) {
        if (dropItem != null) {
          entityPlayer.dropPlayerItem(dropItem);
        }
      }
    }
  }
Exemple #9
0
  /**
   * 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 par1EntityPlayer) {
    ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();

    if (var2 != null && var2.itemID == Item.bucketEmpty.itemID) {
      if (--var2.stackSize <= 0) {
        par1EntityPlayer.inventory.setInventorySlotContents(
            par1EntityPlayer.inventory.currentItem, new ItemStack(ModBreeds.Sheepmilk));
      } else if (!par1EntityPlayer.inventory.addItemStackToInventory(
          new ItemStack(ModBreeds.Sheepmilk))) {
        par1EntityPlayer.dropPlayerItem(new ItemStack(ModBreeds.Sheepmilk.itemID, 1, 0));
      }

      return true;
    }

    if (var2 != null
        && var2.itemID == ModBreeds.XmasSpecial.itemID
        && var2.getItemDamage() == 5
        && !worldObj.isRemote) {
      EntitySheep5 var21 = new EntitySheep5(this.worldObj);
      var21.setLocationAndAngles(
          this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);

      this.worldObj.spawnEntityInWorld(var21);
      this.setDead();

      if (--var2.stackSize <= 0) {
        par1EntityPlayer.inventory.setInventorySlotContents(
            par1EntityPlayer.inventory.currentItem, null);
      }

      return true;
    } else {
      return super.interact(par1EntityPlayer);
    }
  }
 /**
  * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
  * world, entityPlayer
  */
 @Override
 public ItemStack onItemRightClick(ItemStack ist, World world, EntityPlayer player) {
   if (this.isEmptyVial(ist)) {
     boolean var11 = isEmptyVial(ist);
     MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, var11);
     if (mop == null) return ist;
     else {
       if (mop.typeOfHit == EnumMovingObjectType.TILE) {
         int var13 = mop.blockX;
         int var14 = mop.blockY;
         int var15 = mop.blockZ;
         if (world.getBlockMaterial(var13, var14, var15) == Material.water) {
           if (--ist.stackSize <= 0) return new ItemStack(this, 1, waterVialMeta());
           if (!player.inventory.addItemStackToInventory(
               new ItemStack(this, 1, waterVialMeta()))) {
             player.dropPlayerItem(new ItemStack(this, 1, waterVialMeta()));
           }
         }
       }
     }
   } else if (!hasEffect(ist)) return ist;
   else if (isPotion(ist)) {
     player.setItemInUse(ist, this.getMaxItemUseDuration(ist));
   } else if (isSplash(ist)) {
     if (world.isRemote) return ist;
     Entity e = getNewPotionEntity(ist, world, player);
     if (e == null) return ist;
     if (!player.capabilities.isCreativeMode) {
       --ist.stackSize;
     }
     world.playSoundAtEntity(
         player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
     world.spawnEntityInWorld(e);
   }
   return ist;
 }
Exemple #11
0
  @Override
  public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
    // TODO Auto-generated method stub
    MovingObjectPosition movingobjectposition =
        this.getMovingObjectPositionFromPlayer(world, player, true);

    if (movingobjectposition == null) {
      return item;
    } else {
      FillBucketEvent event = new FillBucketEvent(player, item, world, movingobjectposition);
      if (MinecraftForge.EVENT_BUS.post(event)) {
        return item;
      }

      if (event.getResult() == Event.Result.ALLOW) {
        if (player.capabilities.isCreativeMode) {
          return item;
        }

        if (--item.stackSize <= 0) {
          return event.result;
        }

        if (!player.inventory.addItemStackToInventory(event.result)) {
          player.dropPlayerItem(event.result);
        }

        return item;
      }

      if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
        int x = movingobjectposition.blockX;
        int y = movingobjectposition.blockY;
        int z = movingobjectposition.blockZ;

        if (!world.canMineBlock(player, x, y, z)) {
          return item;
        }

        if (movingobjectposition.sideHit == 0) {
          --y;
        }

        if (movingobjectposition.sideHit == 1) {
          ++y;
        }

        if (movingobjectposition.sideHit == 2) {
          --z;
        }

        if (movingobjectposition.sideHit == 3) {
          ++z;
        }

        if (movingobjectposition.sideHit == 4) {
          --x;
        }

        if (movingobjectposition.sideHit == 5) {
          ++x;
        }

        if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, item)) {
          return item;
        }

        if (this.tryPlaceContainedLiquid(world, x, y, z) && !player.capabilities.isCreativeMode) {
          return new ItemStack(Item.bucketEmpty);
        }
      }

      return item;
    }
  }
  public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;
    InventoryPlayer var6 = par4EntityPlayer.inventory;
    Slot var7;
    ItemStack var8;
    int var10;
    ItemStack var11;

    if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
      if (par1 == -999) {
        if (var6.getItemStack() != null && par1 == -999) {
          if (par2 == 0) {
            par4EntityPlayer.dropPlayerItem(var6.getItemStack());
            var6.setItemStack((ItemStack) null);
          }

          if (par2 == 1) {
            // CraftBukkit start - store a reference
            ItemStack itemstack3 = var6.getItemStack();
            par4EntityPlayer.dropPlayerItem(itemstack3.splitStack(1));

            if (itemstack3.stackSize == 0) {
              // CraftBukkit end
              var6.setItemStack((ItemStack) null);
            }
          }
        }
      } else if (par3 == 1) {
        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null && var7.canTakeStack(par4EntityPlayer)) {
          var8 = this.transferStackInSlot(par4EntityPlayer, par1);

          if (var8 != null) {
            int var12 = var8.itemID;
            var5 = var8.copy();

            if (var7 != null && var7.getStack() != null && var7.getStack().itemID == var12) {
              this.retrySlotClick(par1, par2, true, par4EntityPlayer);
            }
          }
        }
      } else {
        if (par1 < 0) {
          return null;
        }

        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null) {
          var8 = var7.getStack();
          ItemStack var13 = var6.getItemStack();

          if (var8 != null) {
            var5 = var8.copy();
          }

          if (var8 == null) {
            if (var13 != null && var7.isItemValid(var13)) {
              var10 = par2 == 0 ? var13.stackSize : 1;

              if (var10 > var7.getSlotStackLimit()) {
                var10 = var7.getSlotStackLimit();
              }

              if (var13.stackSize >= var10) // CraftBukkit
              var7.putStack(var13.splitStack(var10));

              if (var13.stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          } else if (var7.canTakeStack(par4EntityPlayer)) {
            if (var13 == null) {
              var10 = par2 == 0 ? var8.stackSize : (var8.stackSize + 1) / 2;
              var11 = var7.decrStackSize(var10);
              var6.setItemStack(var11);

              if (var8.stackSize == 0) {
                var7.putStack((ItemStack) null);
              }

              var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
            } else if (var7.isItemValid(var13)) {
              if (var8.itemID == var13.itemID
                  && var8.getItemDamage() == var13.getItemDamage()
                  && ItemStack.areItemStackTagsEqual(var8, var13)) {
                var10 = par2 == 0 ? var13.stackSize : 1;

                if (var10 > var7.getSlotStackLimit() - var8.stackSize) {
                  var10 = var7.getSlotStackLimit() - var8.stackSize;
                }

                if (var10 > var13.getMaxStackSize() - var8.stackSize) {
                  var10 = var13.getMaxStackSize() - var8.stackSize;
                }

                var13.splitStack(var10);

                if (var13.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }

                var8.stackSize += var10;
              } else if (var13.stackSize <= var7.getSlotStackLimit()) {
                var7.putStack(var13);
                var6.setItemStack(var8);
              }
            } else if (var8.itemID == var13.itemID
                && var13.getMaxStackSize() > 1
                && (!var8.getHasSubtypes() || var8.getItemDamage() == var13.getItemDamage())
                && ItemStack.areItemStackTagsEqual(var8, var13)) {
              var10 = var8.stackSize;

              if (var10 > 0 && var10 + var13.stackSize <= var13.getMaxStackSize()) {
                var13.stackSize += var10;
                var8 = var7.decrStackSize(var10);

                if (var8.stackSize == 0) {
                  var7.putStack((ItemStack) null);
                }

                var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
              }
            }
          }

          var7.onSlotChanged();
        }
      }
    } else if (par3 == 2 && par2 >= 0 && par2 < 9) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7.canTakeStack(par4EntityPlayer)) {
        var8 = var6.getStackInSlot(par2);
        boolean var9 = var8 == null || var7.inventory == var6 && var7.isItemValid(var8);
        var10 = -1;

        if (!var9) {
          var10 = var6.getFirstEmptyStack();
          var9 |= var10 > -1;
        }

        if (var7.getHasStack() && var9) {
          var11 = var7.getStack();
          var6.setInventorySlotContents(par2, var11);

          if ((var7.inventory != var6 || !var7.isItemValid(var8)) && var8 != null) {
            if (var10 > -1) {
              var6.addItemStackToInventory(var8);
              var7.decrStackSize(var11.stackSize);
              var7.putStack((ItemStack) null);
              var7.onPickupFromSlot(par4EntityPlayer, var11);
            }
          } else {
            var7.decrStackSize(var11.stackSize);
            var7.putStack(var8);
            var7.onPickupFromSlot(par4EntityPlayer, var11);
          }
        } else if (!var7.getHasStack() && var8 != null && var7.isItemValid(var8)) {
          var6.setInventorySlotContents(par2, (ItemStack) null);
          var7.putStack(var8);
        }
      }
    } else if (par3 == 3
        && par4EntityPlayer.capabilities.isCreativeMode
        && var6.getItemStack() == null
        && par1 >= 0) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7 != null && var7.getHasStack()) {
        var8 = var7.getStack().copy();
        var8.stackSize = var8.getMaxStackSize();
        var6.setItemStack(var8);
      }
    }

    return var5;
  }