private void crafting(ShapedRecipe recipe, InventoryHolder invMinecart) {

    HashSet<ItemStack> removedItems = new HashSet<ItemStack>();
    for (Iterator<Entry<Character, ItemStack>> irt2 =
            recipe.getIngredientMap().entrySet().iterator();
        irt2.hasNext(); ) {
      Entry<Character, ItemStack> entry = irt2.next();
      ItemStack is = entry.getValue();

      if (is == null) {
        continue;
      }
      ItemStack remove = invMinecart.getInventory().removeItem(is).get(0);
      if (remove == null) {
        removedItems.add(is);
      } else {
        invMinecart.getInventory().addItem(remove);
        for (ItemStack backItem : removedItems) {
          invMinecart.getInventory().addItem(backItem);
        }
        return;
      }
    }
    invMinecart.getInventory().addItem(recipe.getResult());
  }
 /**
  * Get the type of chest that the inventory holder is.
  *
  * @param inventoryHolder holder to get the chest type for.
  * @return {@link com.caved_in.commons.block.ChestType} of the given inventory holder. Unknown if
  *     it's not a chest.
  */
 public static ChestType getChestType(InventoryHolder inventoryHolder) {
   if (isChest(inventoryHolder)) {
     return ChestType.SINGLE_CHEST;
   } else if (isDoubleChest(inventoryHolder)) {
     return ChestType.DOUBLE_CHEST;
   } else if (inventoryHolder.getInventory().getType() == InventoryType.ENDER_CHEST) {
     return ChestType.ENDER_CHEST;
   } else {
     return ChestType.UNKNOWN;
   }
 }
示例#3
0
  private ItemStack[] getRecords(List<Block> containables) {
    List<ItemStack> tempItems = new ArrayList<ItemStack>();
    ItemStack[] isTotalItems;

    for (Block bHolder : containables) {
      if (bHolder.getState() instanceof InventoryHolder) {
        InventoryHolder Holder = (InventoryHolder) bHolder.getState();
        for (ItemStack item : Holder.getInventory().getContents()) {
          if (item != null && item.getAmount() > 0 && item.getType().isRecord()) {
            tempItems.add(item);
          }
        }
      }
    }
    isTotalItems = tempItems.toArray(new ItemStack[tempItems.size()]);
    return isTotalItems;
  }
示例#4
0
  public static void handleHolderRemoval(Consumer consumer, String remover, BlockState state) {
    InventoryHolder holder = (InventoryHolder) state;

    if (InventoryUtil.isHolderValid(holder)) {
      List<ItemStack> invContents =
          compressInventory(
              (holder instanceof Chest
                      ? ((Chest) state).getBlockInventory()
                      : holder.getInventory())
                  .getContents());

      if (!invContents.isEmpty()) {
        for (String str : serializeInventory(ContainerEntry.getSerializer(), invContents))
          consumer.addEntry(
              new ContainerExtract(
                  remover, DataType.CONTAINER_EXTRACT, InventoryUtil.getHolderLoc(holder), str));
      }
    }
  }
  public static void clear(final Location bottom, final Location top) {
    final AthionMaps pmi = getMap(bottom);

    final int bottomX = bottom.getBlockX();
    final int topX = top.getBlockX();
    final int bottomZ = bottom.getBlockZ();
    final int topZ = top.getBlockZ();

    final int minChunkX = (int) Math.floor((double) bottomX / 16);
    final int maxChunkX = (int) Math.floor((double) topX / 16);
    final int minChunkZ = (int) Math.floor((double) bottomZ / 16);
    final int maxChunkZ = (int) Math.floor((double) topZ / 16);

    final World w = bottom.getWorld();

    for (int cx = minChunkX; cx <= maxChunkX; cx++) {
      for (int cz = minChunkZ; cz <= maxChunkZ; cz++) {
        final Chunk chunk = w.getChunkAt(cx, cz);

        for (final Entity e : chunk.getEntities()) {
          final Location eloc = e.getLocation();

          if (!(e instanceof Player)
              && (eloc.getBlockX() >= bottom.getBlockX())
              && (eloc.getBlockX() <= top.getBlockX())
              && (eloc.getBlockZ() >= bottom.getBlockZ())
              && (eloc.getBlockZ() <= top.getBlockZ())) {
            e.remove();
          }
        }
      }
    }

    for (int x = bottomX; x <= topX; x++) {
      for (int z = bottomZ; z <= topZ; z++) {
        Block block = new Location(w, x, 0, z).getBlock();

        block.setBiome(Biome.PLAINS);

        for (int y = w.getMaxHeight(); y >= 0; y--) {
          block = new Location(w, x, y, z).getBlock();

          final BlockState state = block.getState();

          if (state instanceof InventoryHolder) {
            final InventoryHolder holder = (InventoryHolder) state;
            holder.getInventory().clear();
          }

          if (state instanceof Jukebox) {
            final Jukebox jukebox = (Jukebox) state;
            // Remove once they fix the NullPointerException
            try {
              jukebox.setPlaying(Material.AIR);
            } catch (final Exception e) {
            }
          }

          if (y == 0) {
            block.setTypeId(pmi.BottomBlockId);
          } else if (y == pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFloorBlockId);
          } else if (y < pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFillingBlockId);
          } else {
            if ((y == (pmi.RoadHeight))
                && ((x == (bottomX - 1))
                    || (x == (topX + 1))
                    || (z == (bottomZ - 1))
                    || (z == (topZ + 1)))) {
              // block.setTypeId(pmi.WallBlockId);
            } else {
              block.setTypeIdAndData(0, (byte) 0, false); // .setType(Material.AIR);
            }
          }
        }
      }
    }

    adjustWall(bottom);
  }