/**
  * 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];
 }
  public String getItemDisplayName(ItemStack par1ItemStack) {
    if (par1ItemStack.hasTagCompound()) {
      NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();
      NBTTagString nbttagstring = (NBTTagString) nbttagcompound.getTag("title");

      if (nbttagstring != null) {
        return nbttagstring.toString();
      }
    }

    return super.getItemDisplayName(par1ItemStack);
  }
  /**
   * 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];
  }
Example #4
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);
  }
  /** allows items to add custom lines of information to the mouseover description */
  public void addInformation(ItemStack par1ItemStack, List par2List) {
    if (par1ItemStack.hasTagCompound()) {
      NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();
      NBTTagString nbttagstring = (NBTTagString) nbttagcompound.getTag("author");

      if (nbttagstring != null) {
        par2List.add(
            (new StringBuilder())
                .append("\2477")
                .append(
                    String.format(
                        StatCollector.translateToLocalFormatted(
                            "book.byAuthor", new Object[] {nbttagstring.data}),
                        new Object[0]))
                .toString());
      }
    }
  }
  /** 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);
  }
  public void processCommand(ICommandSender sender, String[] args) {
    if (args.length != 2) {
      throw new WrongUsageException(getCommandUsage(sender), new Object[0]);
    }

    EntityPlayerMP player = ((EntityPlayerMP) sender);
    ItemStack stack = player.inventory.getCurrentItem();

    if (args[0].equalsIgnoreCase("add")) {
      NBTTagCompound regionSelection = (NBTTagCompound) stack.getTagCompound().copy();

      if (regionSelection.hasKey("pos1") && regionSelection.hasKey("pos2")) {
        if (SimpleRegions.regionData.hasKey(args[1])) {
          throw new WrongUsageException("Region name already used.");
        } else {
          regionSelection.setString("Owner", sender.getCommandSenderName());
          SimpleRegions.regionData.setCompoundTag(args[1], regionSelection);
          SimpleRegions.availableRegions.add(args[1]);
          sender.sendChatToPlayer("Region " + args[1] + " added. You have been set as owner.");
        }
      } else {
        throw new WrongUsageException("Selection has to be square.");
      }
    } else if (args[0].equalsIgnoreCase("remove")) {
      if (SimpleRegions.regionData.hasKey(args[1])) {
        NBTTagCompound newData = new NBTTagCompound();
        Iterator i = SimpleRegions.regionData.getTags().iterator();
        while (i.hasNext()) {
          NBTBase tag = (NBTBase) i.next();
          if (!tag.getName().equals(args[1])) {
            newData.setTag(args[1], tag);
          } else {
            sender.sendChatToPlayer("Region " + args[1] + " removed.");
            SimpleRegions.availableRegions.remove(tag.getName());
            return;
          }
        }
      } else {
        sender.sendChatToPlayer("Region " + args[1] + " not found!");
      }
    } else {
      throw new WrongUsageException(getCommandUsage(sender), new Object[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;
      }
    }
  }