コード例 #1
0
  /**
   * Sets the given item stack to the specified slot in the inventory (can be crafting or armor
   * sections).
   */
  public void setInventorySlotContents(int par1, ItemStack par2ItemStack) {
    this.combinerItemStacks[par1] = par2ItemStack;

    if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) {
      par2ItemStack.stackSize = this.getInventoryStackLimit();
    }
  }
コード例 #2
0
  /**
   * Sets the given item stack to the specified slot in the inventory (can be crafting or armor
   * sections).
   */
  public void setInventorySlotContents(int par1, ItemStack par2ItemStack) {
    cargoItems[par1] = par2ItemStack;

    if (par2ItemStack != null && par2ItemStack.stackSize > getInventoryStackLimit()) {
      par2ItemStack.stackSize = getInventoryStackLimit();
    }
  }
コード例 #3
0
  /** Attempts to right-click use an item by the given EntityPlayer in the given World */
  public boolean tryUseItem(
      EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack) {
    int var4 = par3ItemStack.stackSize;
    int var5 = par3ItemStack.getItemDamage();
    ItemStack var6 = par3ItemStack.useItemRightClick(par2World, par1EntityPlayer);

    if (var6 == par3ItemStack
        && (var6 == null
            || var6.stackSize == var4
                && var6.getMaxItemUseDuration() <= 0
                && var6.getItemDamage() == var5)) {
      return false;
    } else {
      par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = var6;

      if (this.isCreative()) {
        var6.stackSize = var4;

        if (var6.isItemStackDamageable()) {
          var6.setItemDamage(var5);
        }
      }

      if (var6.stackSize == 0) {
        par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = null;
      }

      if (!par1EntityPlayer.isUsingItem()) {
        ((EntityPlayerMP) par1EntityPlayer)
            .sendContainerToPlayer(par1EntityPlayer.inventoryContainer);
      }

      return true;
    }
  }
コード例 #4
0
  public boolean hitEntity(ItemStack itemstack, EntityLiving mob, EntityLiving entityliving1) {
    World world = entityliving1.worldObj;
    if (type1 == type2) {
      attacks(itemstack, world, entityliving1, mob, type1);
    } else {
      if (random.nextInt(100) + 1 <= 80) {
        attacks(itemstack, world, entityliving1, mob, type1);
      }
      if (random.nextInt(100) + 1 <= 20) {
        attacks(itemstack, world, entityliving1, mob, type2);
      }
    }
    int i = itemstack.getItemDamage();
    if (i >= dur) {
      itemstack.stackSize = 0;
    }
    if (type1 == 3 || type2 == 3 || type1 == 4 || type2 == 4 || type1 == 8 || type2 == 8) {
      if (random.nextInt(100) + 1 <= 90) {
        itemstack.damageItem(1, entityliving1);
      }
    } else {
      itemstack.damageItem(1, entityliving1);
    }

    return true;
  }
コード例 #5
0
  /** Handles a players right click */
  public boolean onPlayerRightClick(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7) {
    syncCurrentPlayItem();
    netClientHandler.addToSendQueue(
        new Packet15Place(par4, par5, par6, par7, par1EntityPlayer.inventory.getCurrentItem()));
    int i = par2World.getBlockId(par4, par5, par6);

    if (i > 0
        && Block.blocksList[i].blockActivated(par2World, par4, par5, par6, par1EntityPlayer)) {
      return true;
    }

    if (par3ItemStack == null) {
      return false;
    }

    if (creativeMode) {
      int j = par3ItemStack.getItemDamage();
      int k = par3ItemStack.stackSize;
      boolean flag = par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7);
      par3ItemStack.setItemDamage(j);
      par3ItemStack.stackSize = k;
      return flag;
    } else {
      return par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7);
    }
  }
コード例 #6
0
  /**
   * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x,
   * y, z, side, xOffset, yOffset, zOffset
   */
  public boolean activateBlockOrUseItem(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    int var11 = par2World.getBlockId(par4, par5, par6);

    if (var11 > 0
        && Block.blocksList[var11].onBlockActivated(
            par2World, par4, par5, par6, par1EntityPlayer, par7, par8, par9, par10)) {
      return true;
    } else if (par3ItemStack == null) {
      return false;
    } else if (this.isCreative()) {
      int var12 = par3ItemStack.getItemDamage();
      int var13 = par3ItemStack.stackSize;
      boolean var14 =
          par3ItemStack.func_77943_a(
              par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
      par3ItemStack.setItemDamage(var12);
      par3ItemStack.stackSize = var13;
      return var14;
    } else {
      return par3ItemStack.func_77943_a(
          par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
    }
  }
コード例 #7
0
  /** Adds the item stack to the inventory, returns false if it is impossible. */
  public boolean addItemStackToInventory(ItemStack par1ItemStack) {
    if (par1ItemStack == null
        || !Vars.isActor) // prevents everyone from picking up things except for actors
    {
      return false;
    } else {
      try {
        int var2;

        if (par1ItemStack.isItemDamaged()) {
          var2 = this.getFirstEmptyStack();

          if (var2 >= 0) {
            this.mainInventory[var2] = ItemStack.copyItemStack(par1ItemStack);
            this.mainInventory[var2].animationsToGo = 5;
            par1ItemStack.stackSize = 0;
            return true;
          } else if (this.player.capabilities.isCreativeMode) {
            par1ItemStack.stackSize = 0;
            return true;
          } else {
            return false;
          }
        } else {
          do {
            var2 = par1ItemStack.stackSize;
            par1ItemStack.stackSize = this.storePartialItemStack(par1ItemStack);
          } while (par1ItemStack.stackSize > 0 && par1ItemStack.stackSize < var2);

          if (par1ItemStack.stackSize == var2 && this.player.capabilities.isCreativeMode) {
            par1ItemStack.stackSize = 0;
            return true;
          } else {
            return par1ItemStack.stackSize < var2;
          }
        }
      } catch (Throwable var5) {
        CrashReport var3 = CrashReport.makeCrashReport(var5, "Adding item to inventory");
        CrashReportCategory var4 = var3.makeCategory("Item being added");
        var4.addCrashSection("Item ID", Integer.valueOf(par1ItemStack.itemID));
        var4.addCrashSection("Item data", Integer.valueOf(par1ItemStack.getItemDamage()));
        var4.addCrashSectionCallable("Item name", new CallableItemName(this, par1ItemStack));
        throw new ReportedException(var3);
      }
    }
  }
コード例 #8
0
 public boolean onBlockDestroyed(
     ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving) {
   int i1 = itemstack.getItemDamage();
   if (i1 >= dur) {
     itemstack.stackSize = 0;
   }
   itemstack.damageItem(2, entityliving);
   return true;
 }
コード例 #9
0
 public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {
   if (player != null) {
     item = item.copy();
     if (item.stackSize == 0) {
       item.stackSize = 1;
     }
     countItems(player, item);
   }
 }
コード例 #10
0
 public boolean addItemStackToInventory(ItemStack itemstack) {
   if (!itemstack.isItemDamaged()) {
     int i;
     do {
       i = itemstack.stackSize;
       itemstack.stackSize = func_21083_d(itemstack);
     } while (itemstack.stackSize > 0 && itemstack.stackSize < i);
     return itemstack.stackSize < i;
   }
   int j = getFirstEmptyStack();
   if (j >= 0) {
     mainInventory[j] = ItemStack.func_20117_a(itemstack);
     mainInventory[j].animationsToGo = 5;
     itemstack.stackSize = 0;
     return true;
   } else {
     return false;
   }
 }
コード例 #11
0
ファイル: ItemArmor.java プロジェクト: rezzanate/Spoutcraft
  /**
   * 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) {
    int var4 = EntityLiving.getArmorPosition(par1ItemStack) - 1;
    ItemStack var5 = par3EntityPlayer.getCurrentArmor(var4);

    if (var5 == null) {
      par3EntityPlayer.setCurrentItemOrArmor(var4, par1ItemStack.copy());
      par1ItemStack.stackSize = 0;
    }

    return par1ItemStack;
  }
コード例 #12
0
ファイル: SlotRepair.java プロジェクト: nathanowen42/DuneMod
  public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) {
    if (!par1EntityPlayer.capabilities.isCreativeMode) {
      par1EntityPlayer.addExperienceLevel(-this.anvil.maximumCost);
    }

    ContainerRepair.getRepairInputInventory(this.anvil)
        .setInventorySlotContents(0, (ItemStack) null);

    if (ContainerRepair.getStackSizeUsedInRepair(this.anvil) > 0) {
      ItemStack var3 = ContainerRepair.getRepairInputInventory(this.anvil).getStackInSlot(1);

      if (var3 != null && var3.stackSize > ContainerRepair.getStackSizeUsedInRepair(this.anvil)) {
        var3.stackSize -= ContainerRepair.getStackSizeUsedInRepair(this.anvil);
        ContainerRepair.getRepairInputInventory(this.anvil).setInventorySlotContents(1, var3);
      } else {
        ContainerRepair.getRepairInputInventory(this.anvil)
            .setInventorySlotContents(1, (ItemStack) null);
      }
    } else {
      ContainerRepair.getRepairInputInventory(this.anvil)
          .setInventorySlotContents(1, (ItemStack) null);
    }

    this.anvil.maximumCost = 0;

    if (!par1EntityPlayer.capabilities.isCreativeMode
        && !this.theWorld.isRemote
        && this.theWorld.getBlockId(this.field_82873_b, this.field_82874_c, this.field_82871_d)
            == Block.anvil.blockID
        && par1EntityPlayer.getRNG().nextFloat() < 0.12F) {
      int var6 =
          this.theWorld.getBlockMetadata(
              this.field_82873_b, this.field_82874_c, this.field_82871_d);
      int var4 = var6 & 3;
      int var5 = var6 >> 2;
      ++var5;

      if (var5 > 2) {
        this.theWorld.setBlockWithNotify(
            this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
        this.theWorld.playAuxSFX(
            1020, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
      } else {
        this.theWorld.setBlockMetadataWithNotify(
            this.field_82873_b, this.field_82874_c, this.field_82871_d, var4 | var5 << 2);
        this.theWorld.playAuxSFX(
            1021, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
      }
    } else if (!this.theWorld.isRemote) {
      this.theWorld.playAuxSFX(1021, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
    }
  }
コード例 #13
0
  /** Will get destroyed next tick. */
  public void setDead() {
    if (this.field_82345_h) {
      for (int var1 = 0; var1 < this.getSizeInventory(); ++var1) {
        ItemStack var2 = this.getStackInSlot(var1);

        if (var2 != null) {
          float var3 = this.rand.nextFloat() * 0.8F + 0.1F;
          float var4 = this.rand.nextFloat() * 0.8F + 0.1F;
          float var5 = this.rand.nextFloat() * 0.8F + 0.1F;

          while (var2.stackSize > 0) {
            int var6 = this.rand.nextInt(21) + 10;

            if (var6 > var2.stackSize) {
              var6 = var2.stackSize;
            }

            var2.stackSize -= var6;
            EntityItem var7 =
                new EntityItem(
                    this.worldObj,
                    this.posX + (double) var3,
                    this.posY + (double) var4,
                    this.posZ + (double) var5,
                    new ItemStack(var2.itemID, var6, var2.getItemDamage()));

            if (var2.hasTagCompound()) {
              var7.func_92059_d().setTagCompound((NBTTagCompound) var2.getTagCompound().copy());
            }

            float var8 = 0.05F;
            var7.motionX = (double) ((float) this.rand.nextGaussian() * var8);
            var7.motionY = (double) ((float) this.rand.nextGaussian() * var8 + 0.2F);
            var7.motionZ = (double) ((float) this.rand.nextGaussian() * var8);
            this.worldObj.spawnEntityInWorld(var7);
          }
        }
      }
    }

    super.setDead();

    if (this.field_82344_g != null) {
      this.field_82344_g.update();
    }
  }
コード例 #14
0
ファイル: BlockMachine.java プロジェクト: blued00r/Mekanism
  @Override
  public void breakBlock(World world, int x, int y, int z, int i1, int i2) {
    TileEntityBasicMachine tileEntity = (TileEntityBasicMachine) world.getBlockTileEntity(x, y, z);

    if (tileEntity != null) {
      for (int i = 0; i < tileEntity.getSizeInventory(); ++i) {
        ItemStack slotStack = tileEntity.getStackInSlot(i);

        if (slotStack != null) {
          float xRandom = machineRand.nextFloat() * 0.8F + 0.1F;
          float yRandom = machineRand.nextFloat() * 0.8F + 0.1F;
          float zRandom = machineRand.nextFloat() * 0.8F + 0.1F;

          while (slotStack.stackSize > 0) {
            int j = machineRand.nextInt(21) + 10;

            if (j > slotStack.stackSize) {
              j = slotStack.stackSize;
            }

            slotStack.stackSize -= j;
            EntityItem item =
                new EntityItem(
                    world,
                    (double) ((float) x + xRandom),
                    (double) ((float) y + yRandom),
                    (double) ((float) z + zRandom),
                    new ItemStack(slotStack.itemID, j, slotStack.getItemDamage()));

            if (slotStack.hasTagCompound()) {
              item.item.setTagCompound((NBTTagCompound) slotStack.getTagCompound().copy());
            }

            float k = 0.05F;
            item.motionX = (double) ((float) machineRand.nextGaussian() * k);
            item.motionY = (double) ((float) machineRand.nextGaussian() * k + 0.2F);
            item.motionZ = (double) ((float) machineRand.nextGaussian() * k);
            world.spawnEntityInWorld(item);
          }
        }
      }
      tileEntity.invalidate();
    }

    super.breakBlock(world, x, y, z, i1, i2);
  }
コード例 #15
0
  /** ejects contained items into the world, and notifies neighbours of an update, as appropriate */
  public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
    TileEntityChest var7 = (TileEntityChest) par1World.getBlockTileEntity(par2, par3, par4);

    if (var7 != null) {
      for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8) {
        ItemStack var9 = var7.getStackInSlot(var8);

        if (var9 != null) {
          float var10 = this.random.nextFloat() * 0.8F + 0.1F;
          float var11 = this.random.nextFloat() * 0.8F + 0.1F;
          EntityItem var14;

          for (float var12 = this.random.nextFloat() * 0.8F + 0.1F;
              var9.stackSize > 0;
              par1World.spawnEntityInWorld(var14)) {
            int var13 = this.random.nextInt(21) + 10;

            if (var13 > var9.stackSize) {
              var13 = var9.stackSize;
            }

            var9.stackSize -= var13;
            var14 =
                new EntityItem(
                    par1World,
                    (double) ((float) par2 + var10),
                    (double) ((float) par3 + var11),
                    (double) ((float) par4 + var12),
                    new ItemStack(var9.itemID, var13, var9.getItemDamage()));
            float var15 = 0.05F;
            var14.motionX = (double) ((float) this.random.nextGaussian() * var15);
            var14.motionY = (double) ((float) this.random.nextGaussian() * var15 + 0.2F);
            var14.motionZ = (double) ((float) this.random.nextGaussian() * var15);

            if (var9.hasTagCompound()) {
              var14.getEntityItem().setTagCompound((NBTTagCompound) var9.getTagCompound().copy());
            }
          }
        }
      }
    }

    super.breakBlock(par1World, par2, par3, par4, par5, par6);
  }
コード例 #16
0
  /** Handles a players right click */
  public boolean onPlayerRightClick(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7) {
    this.syncCurrentPlayItem();
    this.netClientHandler.addToSendQueue(
        new Packet15Place(par4, par5, par6, par7, par1EntityPlayer.inventory.getCurrentItem()));

    if (par3ItemStack != null
        && par3ItemStack.getItem() != null
        && par3ItemStack
            .getItem()
            .onItemUseFirst(par3ItemStack, par1EntityPlayer, par2World, par4, par5, par6, par7)) {
      return true;
    }

    int var8 = par2World.getBlockId(par4, par5, par6);

    if (var8 > 0
        && Block.blocksList[var8].blockActivated(par2World, par4, par5, par6, par1EntityPlayer)) {
      return true;
    } else if (par3ItemStack == null) {
      return false;
    } else if (this.creativeMode) {
      int var9 = par3ItemStack.getItemDamage();
      int var10 = par3ItemStack.stackSize;
      boolean var11 = par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7);
      par3ItemStack.setItemDamage(var9);
      par3ItemStack.stackSize = var10;
      return var11;
    } else {
      if (!par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7)) {
        return false;
      }
      if (par3ItemStack.stackSize <= 0) {
        ForgeHooks.onDestroyCurrentItem(par1EntityPlayer, par3ItemStack);
      }
      return true;
    }
  }
コード例 #17
0
  public boolean interact(EntityPlayer entityplayer) {
    ItemStack itemstack = entityplayer.inventory.getCurrentItem();
    if (itemstack != null && itemstack.itemID == Item.shears.shiftedIndex && !getSheared()) {
      if (!worldObj.multiplayerWorld) {
        if (getPuffed()) {
          setPuffed(false);
          int i = 2 + rand.nextInt(3);
          for (int l = 0; l < i; l++) {
            EntityItem entityitem =
                entityDropItem(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()), 1.0F);
            entityitem.motionY += rand.nextFloat() * 0.05F;
            entityitem.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
            entityitem.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
          }

        } else {
          setSheared(true);
          int j = 2 + rand.nextInt(3);
          for (int i1 = 0; i1 < j; i1++) {
            EntityItem entityitem1 =
                entityDropItem(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()), 1.0F);
            entityitem1.motionY += rand.nextFloat() * 0.05F;
            entityitem1.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
            entityitem1.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
          }
        }
      }
      itemstack.damageItem(1, entityplayer);
    }
    if (itemstack != null && itemstack.itemID == Item.dyePowder.shiftedIndex && !getSheared()) {
      int k = BlockCloth.func_21034_c(itemstack.getItemDamage());
      if (getFleeceColor() != k) {
        if (getPuffed() && itemstack.stackSize >= 2) {
          setFleeceColor(k);
          itemstack.stackSize -= 2;
        } else if (!getPuffed()) {
          setFleeceColor(k);
          itemstack.stackSize--;
        }
      }
    }
    return false;
  }
コード例 #18
0
  /** Will get destroyed next tick */
  public void setEntityDead() {
    label0:
    for (int i = 0; i < getSizeInventory(); i++) {
      ItemStack itemstack = getStackInSlot(i);

      if (itemstack == null) {
        continue;
      }

      float f = rand.nextFloat() * 0.8F + 0.1F;
      float f1 = rand.nextFloat() * 0.8F + 0.1F;
      float f2 = rand.nextFloat() * 0.8F + 0.1F;

      do {
        if (itemstack.stackSize <= 0) {
          continue label0;
        }

        int j = rand.nextInt(21) + 10;

        if (j > itemstack.stackSize) {
          j = itemstack.stackSize;
        }

        itemstack.stackSize -= j;
        EntityItem entityitem =
            new EntityItem(
                worldObj,
                posX + (double) f,
                posY + (double) f1,
                posZ + (double) f2,
                new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
        float f3 = 0.05F;
        entityitem.motionX = (float) rand.nextGaussian() * f3;
        entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
        entityitem.motionZ = (float) rand.nextGaussian() * f3;
        worldObj.spawnEntityInWorld(entityitem);
      } while (true);
    }

    super.setEntityDead();
  }
コード例 #19
0
  /**
   * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x,
   * y, z, side, xOffset, yOffset, zOffset
   */
  public boolean activateBlockOrUseItem(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    int var11;

    if (!par1EntityPlayer.isSneaking() || par1EntityPlayer.getHeldItem() == null) {
      var11 = par2World.getBlockId(par4, par5, par6);

      if (var11 > 0
          && Block.blocksList[var11].onBlockActivated(
              par2World, par4, par5, par6, par1EntityPlayer, par7, par8, par9, par10)) {
        return true;
      }
    }

    if (par3ItemStack == null) {
      return false;
    } else if (this.isCreative()) {
      var11 = par3ItemStack.getItemDamage();
      int var12 = par3ItemStack.stackSize;
      boolean var13 =
          par3ItemStack.tryPlaceItemIntoWorld(
              par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
      par3ItemStack.setItemDamage(var11);
      par3ItemStack.stackSize = var12;
      return var13;
    } else {
      return par3ItemStack.tryPlaceItemIntoWorld(
          par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
    }
  }
コード例 #20
0
  public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;

    if (par2 > 1) {
      return null;
    } else {
      if (par2 == 0 || par2 == 1) {
        InventoryPlayer var6 = par4EntityPlayer.inventory;

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

            if (par2 == 1) {
              par4EntityPlayer.dropPlayerItem(var6.getItemStack().splitStack(1));

              if (var6.getItemStack().stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          }
        } else if (par3) {
          ItemStack var7 = this.transferStackInSlot(par1);

          if (var7 != null) {
            int var8 = var7.itemID;
            var5 = var7.copy();
            Slot var9 = (Slot) this.inventorySlots.get(par1);

            if (var9 != null && var9.getStack() != null && var9.getStack().itemID == var8) {
              this.retrySlotClick(par1, par2, par3, par4EntityPlayer);
            }
          }
        } else {
          if (par1 < 0) {
            return null;
          }

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

          if (var12 != null) {
            ItemStack var13 = var12.getStack();
            ItemStack var14 = var6.getItemStack();

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

            int var10;

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

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

                var12.putStack(var14.splitStack(var10));

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

              if (var13.stackSize == 0) {
                var12.putStack((ItemStack) null);
              }

              var12.onPickupFromSlot(var6.getItemStack());
            } else if (var12.isItemValid(var14)) {
              if (var13.itemID == var14.itemID
                  && (!var13.getHasSubtypes() || var13.getItemDamage() == var14.getItemDamage())
                  && ItemStack.func_77970_a(var13, var14)) {
                var10 = par2 == 0 ? var14.stackSize : 1;

                if (var10 > var12.getSlotStackLimit() - var13.stackSize) {
                  var10 = var12.getSlotStackLimit() - var13.stackSize;
                }

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

                var14.splitStack(var10);

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

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

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

                if (var13.stackSize == 0) {
                  var12.putStack((ItemStack) null);
                }

                var12.onPickupFromSlot(var6.getItemStack());
              }
            }

            var12.onSlotChanged();
          }
        }
      }

      return var5;
    }
  }
コード例 #21
0
  /** Called when the entity is attacked. */
  public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {
    if (!this.worldObj.isRemote && !this.isDead) {
      if (this.func_85032_ar()) {
        return false;
      } else {
        this.func_70494_i(-this.func_70493_k());
        this.func_70497_h(10);
        this.setBeenAttacked();
        this.setDamage(this.getDamage() + par2 * 10);

        if (par1DamageSource.getEntity() instanceof EntityPlayer
            && ((EntityPlayer) par1DamageSource.getEntity()).capabilities.isCreativeMode) {
          this.setDamage(100);
        }

        if (this.getDamage() > 40) {
          if (this.riddenByEntity != null) {
            this.riddenByEntity.mountEntity(this);
          }

          this.setDead();
          this.dropItemWithOffset(Item.minecartEmpty.shiftedIndex, 1, 0.0F);

          if (this.minecartType == 1) {
            EntityMinecart var3 = this;

            for (int var4 = 0; var4 < var3.getSizeInventory(); ++var4) {
              ItemStack var5 = var3.getStackInSlot(var4);

              if (var5 != null) {
                float var6 = this.rand.nextFloat() * 0.8F + 0.1F;
                float var7 = this.rand.nextFloat() * 0.8F + 0.1F;
                float var8 = this.rand.nextFloat() * 0.8F + 0.1F;

                while (var5.stackSize > 0) {
                  int var9 = this.rand.nextInt(21) + 10;

                  if (var9 > var5.stackSize) {
                    var9 = var5.stackSize;
                  }

                  var5.stackSize -= var9;
                  EntityItem var10 =
                      new EntityItem(
                          this.worldObj,
                          this.posX + (double) var6,
                          this.posY + (double) var7,
                          this.posZ + (double) var8,
                          new ItemStack(var5.itemID, var9, var5.getItemDamage()));
                  float var11 = 0.05F;
                  var10.motionX = (double) ((float) this.rand.nextGaussian() * var11);
                  var10.motionY = (double) ((float) this.rand.nextGaussian() * var11 + 0.2F);
                  var10.motionZ = (double) ((float) this.rand.nextGaussian() * var11);
                  this.worldObj.spawnEntityInWorld(var10);
                }
              }
            }

            this.dropItemWithOffset(Block.chest.blockID, 1, 0.0F);
          } else if (this.minecartType == 2) {
            this.dropItemWithOffset(Block.stoneOvenIdle.blockID, 1, 0.0F);
          }
        }

        return true;
      }
    } else {
      return true;
    }
  }
コード例 #22
0
  protected void handleMouseClick(Slot par1Slot, int par2, int par3, int par4) {
    this.field_74234_w = true;
    boolean var5 = par4 == 1;
    InventoryPlayer var6;
    ItemStack var7;

    if (par1Slot != null) {
      if (par1Slot == this.field_74235_v && var5) {
        for (int var10 = 0;
            var10 < this.mc.thePlayer.inventoryContainer.getInventory().size();
            ++var10) {
          this.mc.playerController.sendSlotPacket((ItemStack) null, var10);
        }
      } else if (selectedTabIndex == CreativeTabs.tabInventory.getTabIndex()) {
        if (par1Slot == this.field_74235_v) {
          this.mc.thePlayer.inventory.setItemStack((ItemStack) null);
        } else {
          this.mc.thePlayer.inventoryContainer.slotClick(
              SlotCreativeInventory.func_75240_a((SlotCreativeInventory) par1Slot).slotNumber,
              par3,
              par4,
              this.mc.thePlayer);
          this.mc.thePlayer.inventoryContainer.updateCraftingResults();
        }
      } else if (par1Slot.inventory == inventory) {
        var6 = this.mc.thePlayer.inventory;
        var7 = var6.getItemStack();
        ItemStack var8 = par1Slot.getStack();
        ItemStack var9;

        if (par4 == 2) {
          if (var8 != null && par3 >= 0 && par3 < 9) {
            var9 = var8.copy();
            var9.stackSize = var9.getMaxStackSize();
            this.mc.thePlayer.inventory.setInventorySlotContents(par3, var9);
            this.mc.thePlayer.inventoryContainer.updateCraftingResults();
          }

          return;
        }

        if (par4 == 3) {
          if (var6.getItemStack() == null && par1Slot.getHasStack()) {
            var9 = par1Slot.getStack().copy();
            var9.stackSize = var9.getMaxStackSize();
            var6.setItemStack(var9);
          }

          return;
        }

        if (var7 != null && var8 != null && var7.isItemEqual(var8)) {
          if (par3 == 0) {
            if (var5) {
              var7.stackSize = var7.getMaxStackSize();
            } else if (var7.stackSize < var7.getMaxStackSize()) {
              ++var7.stackSize;
            }
          } else if (var7.stackSize <= 1) {
            var6.setItemStack((ItemStack) null);
          } else {
            --var7.stackSize;
          }
        } else if (var8 != null && var7 == null) {
          var6.setItemStack(ItemStack.copyItemStack(var8));
          var7 = var6.getItemStack();

          if (var5) {
            var7.stackSize = var7.getMaxStackSize();
          }
        } else {
          var6.setItemStack((ItemStack) null);
        }
      } else {
        this.inventorySlots.slotClick(par1Slot.slotNumber, par3, par4, this.mc.thePlayer);
        ItemStack var11 = this.inventorySlots.getSlot(par1Slot.slotNumber).getStack();
        this.mc.playerController.sendSlotPacket(
            var11, par1Slot.slotNumber - this.inventorySlots.inventorySlots.size() + 9 + 36);
      }
    } else {
      var6 = this.mc.thePlayer.inventory;

      if (var6.getItemStack() != null) {
        if (par3 == 0) {
          this.mc.thePlayer.dropPlayerItem(var6.getItemStack());
          this.mc.playerController.func_78752_a(var6.getItemStack());
          var6.setItemStack((ItemStack) null);
        }

        if (par3 == 1) {
          var7 = var6.getItemStack().splitStack(1);
          this.mc.thePlayer.dropPlayerItem(var7);
          this.mc.playerController.func_78752_a(var7);

          if (var6.getItemStack().stackSize == 0) {
            var6.setItemStack((ItemStack) null);
          }
        }
      }
    }
  }
コード例 #23
0
 public void setInventorySlotContents(int i, ItemStack itemstack) {
   furnaceItemStacks[i] = itemstack;
   if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
     itemstack.stackSize = getInventoryStackLimit();
   }
 }
コード例 #24
0
  /** Called when the entity is attacked. */
  public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {
    if (worldObj.isRemote || isDead) {
      return true;
    }

    func_41016_d(-func_41021_q());
    func_41014_b(10);
    setBeenAttacked();
    func_41018_e_(func_41020_o() + par2 * 10);

    if (func_41020_o() > 40) {
      if (riddenByEntity != null) {
        riddenByEntity.mountEntity(this);
      }

      setEntityDead();
      dropItemWithOffset(Item.minecartEmpty.shiftedIndex, 1, 0.0F);

      if (minecartType == 1) {
        EntityMinecart entityminecart = this;
        label0:
        for (int i = 0; i < entityminecart.getSizeInventory(); i++) {
          ItemStack itemstack = entityminecart.getStackInSlot(i);

          if (itemstack == null) {
            continue;
          }

          float f = rand.nextFloat() * 0.8F + 0.1F;
          float f1 = rand.nextFloat() * 0.8F + 0.1F;
          float f2 = rand.nextFloat() * 0.8F + 0.1F;

          do {
            if (itemstack.stackSize <= 0) {
              continue label0;
            }

            int j = rand.nextInt(21) + 10;

            if (j > itemstack.stackSize) {
              j = itemstack.stackSize;
            }

            itemstack.stackSize -= j;
            EntityItem entityitem =
                new EntityItem(
                    worldObj,
                    posX + (double) f,
                    posY + (double) f1,
                    posZ + (double) f2,
                    new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
            float f3 = 0.05F;
            entityitem.motionX = (float) rand.nextGaussian() * f3;
            entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) rand.nextGaussian() * f3;
            worldObj.spawnEntityInWorld(entityitem);
          } while (true);
        }

        dropItemWithOffset(Block.chest.blockID, 1, 0.0F);
      } else if (minecartType == 2) {
        dropItemWithOffset(Block.stoneOvenIdle.blockID, 1, 0.0F);
      }
    }

    return true;
  }
コード例 #25
0
  /** merges provided ItemStack with the first avaliable one in the container/player inventory */
  protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) {
    boolean var5 = false;
    int var6 = par2;

    if (par4) {
      var6 = par3 - 1;
    }

    Slot var7;
    ItemStack var8;

    if (par1ItemStack.isStackable()) {
      while (par1ItemStack.stackSize > 0 && (!par4 && var6 < par3 || par4 && var6 >= par2)) {
        var7 = (Slot) this.inventorySlots.get(var6);
        var8 = var7.getStack();

        if (var8 != null
            && var8.itemID == par1ItemStack.itemID
            && (!par1ItemStack.getHasSubtypes()
                || par1ItemStack.getItemDamage() == var8.getItemDamage())
            && ItemStack.func_77970_a(par1ItemStack, var8)) {
          int var9 = var8.stackSize + par1ItemStack.stackSize;

          if (var9 <= par1ItemStack.getMaxStackSize()) {
            par1ItemStack.stackSize = 0;
            var8.stackSize = var9;
            var7.onSlotChanged();
            var5 = true;
          } else if (var8.stackSize < par1ItemStack.getMaxStackSize()) {
            par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - var8.stackSize;
            var8.stackSize = par1ItemStack.getMaxStackSize();
            var7.onSlotChanged();
            var5 = true;
          }
        }

        if (par4) {
          --var6;
        } else {
          ++var6;
        }
      }
    }

    if (par1ItemStack.stackSize > 0) {
      if (par4) {
        var6 = par3 - 1;
      } else {
        var6 = par2;
      }

      while (!par4 && var6 < par3 || par4 && var6 >= par2) {
        var7 = (Slot) this.inventorySlots.get(var6);
        var8 = var7.getStack();

        if (var8 == null) {
          var7.putStack(par1ItemStack.copy());
          var7.onSlotChanged();
          par1ItemStack.stackSize = 0;
          var5 = true;
          break;
        }

        if (par4) {
          --var6;
        } else {
          ++var6;
        }
      }
    }

    return var5;
  }