/**
   * Handles what should be done on right clicking the item.
   *
   * @param is The ItemStack which is right clicked.
   * @param world The world in which the player is.
   * @param player The player who right clicked the item.
   * @param Returns the ItemStack after the process.
   */
  @Override
  public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
    // if world.isRemote than we are on the client side
    if (world.isRemote) {
      // display rename GUI if player is sneaking
      if (player.isSneaking() && is.getItemDamage() != ItemBackpack.ENDERBACKPACK) {
        FMLCommonHandler.instance().showGuiScreen(new BackpackGui(player));
      }
      return is;
    }

    // when the player is not sneaking
    if (!player.isSneaking()) {
      // get the inventory
      IInventory inv;
      if (is.getItemDamage() == ItemBackpack.ENDERBACKPACK) {
        inv = player.getInventoryEnderChest();
      } else {
        inv = new BackpackInventory(player, is);
      }

      // open the GUI for a chest based on the loaded inventory
      player.displayGUIChest(inv);
    }
    return is;
  }
 public int compare(ItemStack o1, ItemStack o2) {
   if (o1 == null && o2 == null) {
     return 0;
   }
   if (o1 != null && o2 == null) {
     return o1.itemID;
   }
   if (o2 != null && o1 == null) {
     return -o2.itemID;
   }
   if (byName) {
     org.spoutcraft.api.material.Material other1 =
         MaterialData.getMaterial(o1.itemID, (short) (o1.getItemDamage()));
     org.spoutcraft.api.material.Material other2 =
         MaterialData.getMaterial(o2.itemID, (short) (o2.getItemDamage()));
     if (other1 == null && other2 == null) {
       return 0;
     }
     if (other1 != null && other2 == null) {
       return o1.itemID;
     }
     if (other2 != null && other1 == null) {
       return -o2.itemID;
     }
     return other1.getName().compareTo(other2.getName());
   } else {
     int idDiff = o1.itemID - o2.itemID;
     int dataDiff = o1.getItemDamage() - o2.getItemDamage();
     return idDiff * 1000 - dataDiff;
   }
 }
  @Override
  public String getItemNameIS(ItemStack itemstack) {
    int metadata = 0;

    if (itemstack.getItemDamage() >= BlockBasicMachine.ELECTRIC_FURNACE_METADATA) {
      metadata = 2;
    } else if (itemstack.getItemDamage() >= BlockBasicMachine.BATTERY_BOX_METADATA) {
      metadata = 1;
    }

    return Block.blocksList[this.getBlockID()].getBlockName() + "." + metadata;
  }
 @Override
 public boolean isItemValid(ItemStack itemstack) {
   if (itemstack.getItem().shiftedIndex == item.shiftedIndex) {
     if (damage == -1) return true;
     else return itemstack.getItemDamage() == damage;
   } else return false;
 }
Ejemplo n.º 5
0
 public boolean onItemUse(
     ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) {
   if (l == 0) {
     return false;
   }
   if (l == 1) {
     return false;
   }
   byte byte0 = 0;
   if (l == 4) {
     byte0 = 1;
   }
   if (l == 3) {
     byte0 = 2;
   }
   if (l == 5) {
     byte0 = 3;
   }
   EntityBeams_Kaevator entitybeams =
       new EntityBeams_Kaevator(world, i, j, k, byte0, itemstack.getItemDamage());
   if (entitybeams.canStay()) {
     if (!world.isRemote) {
       world.spawnEntityInWorld(entitybeams);
     }
     itemstack.stackSize--;
   }
   return true;
 }
Ejemplo n.º 6
0
 public BukkitItemStack(net.minecraft.src.ItemStack item) {
   super(
       item != null ? item.itemID : 0,
       item != null ? item.stackSize : 0,
       (short) (item != null ? item.getItemDamage() : 0));
   this.item = item;
 }
Ejemplo n.º 7
0
 @Override
 public void writeData(DataOutputStream data) throws IOException {
   super.writeData(data);
   data.writeInt(item.itemID);
   data.writeInt(item.stackSize);
   data.writeInt(item.getItemDamage());
 }
Ejemplo n.º 8
0
 @Override
 public String getItemNameIS(ItemStack itemstack) {
   return "tile."
       + Block.blocksList[getBlockID()].getBlockName()
       + "."
       + itemstack.getItemDamage();
 }
Ejemplo n.º 9
0
 @Override
 public String getItemNameIS(ItemStack itemstack) {
   String name = "";
   switch (itemstack.getItemDamage()) {
     case 0:
       name = "PlatinumBlock";
       break;
     case 1:
       name = "RedstoneBlock";
       break;
     case 2:
       name = "RefinedObsidian";
       break;
     case 3:
       name = "CoalBlock";
       break;
     case 4:
       name = "RefinedGlowstone";
       break;
     default:
       name = "Unknown";
       break;
   }
   return getItemName() + "." + name;
 }
Ejemplo n.º 10
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;
  }
Ejemplo n.º 11
0
 @SuppressWarnings({"all"})
 // @Override (client only)
 public void addInformation(ItemStack itemstack, List list) {
   BptBase bpt = BuildCraftBuilders.getBptRootIndex().getBluePrint(itemstack.getItemDamage());
   if (bpt != null) {
     list.add(bpt.getName());
   }
 }
Ejemplo n.º 12
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;
 }
 /**
  * Gets item name based on the ItemStack.
  *
  * @param itemstack The ItemStack to use for check.
  * @return The name of the backpack.
  */
 @Override
 public String getItemNameIS(ItemStack itemstack) {
   if (itemstack.getTagCompound() != null) {
     if (itemstack.getTagCompound().hasKey("display")) {
       return itemstack.getTagCompound().getCompoundTag("display").getString("Name");
     }
   }
   int dmg = itemstack.getItemDamage();
   if (dmg >= 0 && dmg < 17) {
     return backpackNames[itemstack.getItemDamage()];
   }
   if (dmg >= 32 && dmg < 49) {
     return "Big " + backpackNames[itemstack.getItemDamage() - 32];
   }
   if (itemstack.getItemDamage() == ENDERBACKPACK) {
     return backpackNames[17];
   }
   return backpackNames[16];
 }
Ejemplo n.º 14
0
 // Don't call this method, for future use.
 protected Texture getTextureFromItemStack(ItemStack itemStack) {
   BlockDesign design = null;
   Texture texture = null;
   org.spoutcraft.api.material.CustomItem item =
       MaterialData.getCustomItem(itemStack.getItemDamage());
   if (item != null) {
     String textureURI = item.getTexture();
     if (textureURI == null) {
       org.spoutcraft.api.material.CustomBlock block =
           MaterialData.getCustomBlock(itemStack.getItemDamage());
       design = block != null ? block.getBlockDesign() : null;
       textureURI = design != null ? design.getTextureURL() : null;
     }
     if (textureURI != null) {
       texture = CustomTextureManager.getTextureFromUrl(item.getAddon(), textureURI);
     }
   }
   return texture;
 }
Ejemplo n.º 15
0
 @Override
 public String getItemNameIS(ItemStack itemstack) {
   String s =
       new StringBuilder()
           .append(super.getItemName())
           .append(".")
           .append(Names[itemstack.getItemDamage()])
           .toString();
   return s;
 }
Ejemplo n.º 16
0
 public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
   if (itemstack.getItemDamage() == 0) {
     entityplayer.openGui(
         ObsidianIngots.instance,
         20,
         world,
         (int) entityplayer.posX,
         (int) entityplayer.posY,
         (int) entityplayer.posZ);
   }
   return itemstack;
 }
Ejemplo n.º 17
0
  @Override
  public void doAction(IInventory matrix, DaemonEnergy energy) {
    int size = DaemonMatrix.MATRIX_SIZE;
    int orb = -1;
    ItemOrb orbItem = null;
    int lastSlot = 0;

    // find 1st orb
    for (; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        orb = lastSlot;
        orbItem = (ItemOrb) stack.getItem();
        break;
      }
    }
    if (orb < 0) return;

    // charge with glass shard if possible
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null
          && stack.getItem() instanceof ItemShardGlass
          && stack.getItemDamage() >= ItemShardGlass.DAMAGE_CHARGED) {
        matrix.setInventorySlotContents(i, null);
        orbItem.chargeOrb(matrix.getStackInSlot(orb));
        return;
      }
    }

    // charge with crystal
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null && stack.getItem() instanceof ItemCrystal) {
        matrix.setInventorySlotContents(i, null);
        DaemonEnergy de = UtilItem.getDaemonEnergy(matrix.getStackInSlot(orb));
        DaemonEnergy de2 = UtilItem.getDaemonEnergy(stack);
        de.merge(de2);
        UtilItem.setDaemonEnergy(matrix.getStackInSlot(orb), de);
        return;
      }
    }

    for (lastSlot++; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        matrix.setInventorySlotContents(orb, orbItem.mergeOrbs(matrix.getStackInSlot(orb), stack));
        matrix.setInventorySlotContents(lastSlot, null);
        return;
      }
    }
  }
  /**
   * Returns the item name to display in the tooltip.
   *
   * @param itemstack The ItemStack to use for check.
   * @return The name of the backpack for the tooltip.
   */
  @Override
  public String getItemDisplayName(ItemStack itemstack) {
    // it ItemStack has a NBTTagCompound load name from inventory title.
    if (itemstack.hasTagCompound()) {
      if (itemstack.getTagCompound().hasKey("Inventory")) {
        return itemstack.getTagCompound().getCompoundTag("Inventory").getString("title");
      }
    }
    // else if damage is between 0 and 15 return name from backpackNames array
    int dmg = itemstack.getItemDamage();
    if (dmg >= 0 && dmg < 17) {
      return backpackNames[itemstack.getItemDamage()];
    }
    if (dmg >= 32 && dmg < 49) {
      return "Big " + backpackNames[itemstack.getItemDamage() - 32];
    }
    // else if damage is equal to ENDERBACKPACK then return backpackNames index 16
    if (itemstack.getItemDamage() == ENDERBACKPACK) {
      return backpackNames[17];
    }

    // return index 0 of backpackNames array as fallback
    return backpackNames[16];
  }
 public static void preRender(ItemStack itemStack) {
   if (renderingEnchantment) {
     // rendering custom enchantment -- keep current state
   } else if (itemStack == null) {
     clear();
   } else if (itemStack.getItem() instanceof ItemBlock) {
     clear();
     ctm = CTMUtils18.getInstance();
     ctm.preRenderHeld(
         null, ((ItemBlock) itemStack.getItem()).getBlock(), itemStack.getItemDamage());
   } else {
     ctm = null;
     currentItem = itemStack;
     itemOverride = CITUtils.findItemOverride(itemStack);
   }
 }
Ejemplo n.º 20
0
  @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);
  }
  /** 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.item.setTagCompound((NBTTagCompound) var9.getTagCompound().copy());
            }
          }
        }
      }
    }

    super.breakBlock(par1World, par2, par3, par4, par5, par6);
  }
Ejemplo n.º 22
0
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
    InventoryPlayer inventory = par3EntityPlayer.inventory;
    for (int var2 = 0; var2 < par3EntityPlayer.inventory.mainInventory.length; ++var2) {
      if (par3EntityPlayer.inventory.mainInventory[var2] != null
          && par3EntityPlayer.inventory.mainInventory[var2].itemID
              == Alptraum.alpMultiItem.shiftedIndex
          && par3EntityPlayer.inventory.mainInventory[var2].getItemDamage() == 2) {
        System.out.println("yup");
        ItemStack residueItemStack = inventory.mainInventory[var2];
        int stackSize = residueItemStack.stackSize;
        if (stackSize >= 5) {
          for (int i = 0; i < 5; i++) {
            if (par3EntityPlayer.inventory.mainInventory[var2].getItemDamage() == 2) {
              par3EntityPlayer.inventory.mainInventory[var2].stackSize--;
            }
          }
          par1ItemStack.damageItem(-100, par3EntityPlayer);

        } else if (stackSize < 5) {
          System.out.println("" + stackSize);
          for (int i = 0; i <= stackSize + 1; i++) {
            if (par3EntityPlayer.inventory.mainInventory[var2] != null
                && par3EntityPlayer.inventory.mainInventory[var2].getItemDamage() == 2) {
              par3EntityPlayer.inventory.mainInventory[var2].stackSize--;
              stackSize--;
              System.out.println("" + stackSize);
              if (stackSize <= 0) {
                inventory.mainInventory[var2] = null;
              }
            }
            par1ItemStack.damageItem(-20, par3EntityPlayer);
          }
        }
        if (par1ItemStack.getItemDamage() < 0) {
          par1ItemStack.setItemDamage(0);
        }
        return par1ItemStack;
      }
    }
    return par1ItemStack;
  }
Ejemplo n.º 23
0
  private void dropItems(World world, int x, int y, int z) {
    Random rand = new Random();

    TileEntity tile_entity = world.getBlockTileEntity(x, y, z);

    if (!(tile_entity instanceof IInventory)) {
      return;
    }

    IInventory inventory = (IInventory) tile_entity;

    for (int i = 0; i < inventory.getSizeInventory(); i++) {
      ItemStack item = inventory.getStackInSlot(i);

      if (item != null && item.stackSize > 0) {
        float rx = rand.nextFloat() * 0.6F + 0.1F;
        float ry = rand.nextFloat() * 0.6F + 0.1F;
        float rz = rand.nextFloat() * 0.6F + 0.1F;

        EntityItem entity_item =
            new EntityItem(
                world,
                x + rx,
                y + ry,
                z + rz,
                new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

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

        float factor = 0.5F;

        entity_item.motionX = rand.nextGaussian() * factor;
        entity_item.motionY = rand.nextGaussian() * factor + 0.2F;
        entity_item.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entity_item);
        item.stackSize = 0;
      }
    }
  }
  public String getItemNameIS(ItemStack item) {
    String name = "";

    switch (item.getItemDamage()) {
      case 0:
        {
          name = "cocoBlock";
          break;
        }
      case 1:
        {
          name = "mithrilBlock";
          break;
        }
      case 2:
        {
          name = "silverBlock";
          break;
        }
      case 3:
        {
          name = "amethystBlock";
          break;
        }
      case 4:
        {
          name = "superStone";
          break;
        }
      case 5:
        {
          name = "coalBlock";
          break;
        }
      default:
        name = "cocoBlock";
    }
    return getItemName() + "." + name;
  }
Ejemplo n.º 25
0
 public static short getFuelValueFor(ItemStack itemstack) {
   if (itemstack == null) {
     return 0;
   }
   int i = itemstack.getItem().shiftedIndex;
   if (i < 256 && Block.blocksList[i].blockMaterial == Material.wood) {
     return 300;
   }
   if (i == Item.stick.shiftedIndex) {
     return 100;
   }
   if (i == Item.coal.shiftedIndex) {
     return 1600;
   }
   if (i == Item.bucketLava.shiftedIndex) {
     return 2000;
   }
   if (i == Block.sapling.blockID) {
     return 100;
   } else {
     return (short) ModLoader.addAllFuel(i, itemstack.getItemDamage());
   }
 }
Ejemplo n.º 26
0
  @Override
  protected void mouseClicked(int i, int j, int k) {
    super.mouseClicked(i, j, k);

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;

    int position = getSlotAtLocation(i - cornerX, j - cornerY);

    IInventorySlot slot = null;

    if (position != -1) slot = (IInventorySlot) slots[position];

    if (slot != null) {
      ItemStack playerStack = mc.thePlayer.inventory.getItemStack();

      ItemStack newStack;
      if (playerStack != null)
        newStack = new ItemStack(playerStack.itemID, 1, playerStack.getItemDamage());
      else newStack = null;

      filterInventory.setInventorySlotContents(position, newStack);

      if (CoreProxy.proxy.isRemote(filterInventory.worldObj)) {
        PacketSlotChange packet =
            new PacketSlotChange(
                PacketIds.DIAMOND_PIPE_SELECT,
                filterInventory.xCoord,
                filterInventory.yCoord,
                filterInventory.zCoord,
                position,
                newStack);
        CoreProxy.proxy.sendToServer(packet.getPacket());
      }
    }
  }
Ejemplo n.º 27
0
 public String getItemNameIS(ItemStack itemstack) {
   return (new StringBuilder())
       .append("mineral")
       .append(blockType[itemstack.getItemDamage()])
       .toString();
 }
Ejemplo n.º 28
0
 public String getItemNameIS(ItemStack itemstack) {
   if (itemstack.getItemDamage() == 1) return "plastic.accelerator";
   return "plastic.trampoline";
 }
Ejemplo n.º 29
0
 public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
   if (itemstack.getItemDamage() > 0) {
     itemstack.damageItem(-1, (EntityLiving) entity);
   }
 }
  @Override
  public ItemStack getContainerItemStack(ItemStack itemStack) {
    itemStack.setItemDamage(itemStack.getItemDamage() + 1);

    return itemStack;
  }