public ItemStack dispenseStack(IBlockSource blockSource, ItemStack itemstack) {
    EnumFacing facing = EnumFacing.func_82600_a(blockSource.func_82620_h());
    World world = blockSource.getWorld();
    int targetX = blockSource.getXInt() + facing.func_82601_c();
    int targetY = blockSource.getYInt();
    int targetZ = blockSource.getZInt() + facing.func_82599_e();

    TileEntity te = world.getBlockTileEntity(targetX, targetY, targetZ);
    if (te != null && te instanceof ITankContainer) {
      return fillOrEmptyContainer((ITankContainer) te, itemstack, facing);
    }
    if (world.isAirBlock(targetX, targetY, targetZ)) {
      TileEntity tileabove = world.getBlockTileEntity(targetX, targetY + 1, targetZ);
      TileEntity tilebelow = world.getBlockTileEntity(targetX, targetY - 1, targetZ);
      if (tileabove != null && LiquidContainerRegistry.isEmptyContainer(itemstack)) {
        return fillContainer((ITankContainer) tileabove, itemstack, EnumFacing.UP);
      }
      if (tilebelow != null && LiquidContainerRegistry.isFilledContainer(itemstack)) {
        return emptyContainer((ITankContainer) tilebelow, itemstack, EnumFacing.DOWN);
      }
    }
    System.out.println("Not matched");

    return null;
  }
예제 #2
0
  @Override
  public boolean addRecipe(Recipe recipe) {
    //	GameRegistry.addRecipe((IRecipe) recipe);
    if (recipe instanceof ShapedRecipe) {
      ShapedRecipe r = (ShapedRecipe) recipe;
      boolean useOreDict = false;
      // Map<Character,net.minecraft.item.ItemStack> nmsRecipe = Maps.newHashMap();
      List<Object> objRecipe = new ArrayList<Object>();
      objRecipe.addAll(Arrays.asList(r.getShape()));
      for (Character j : r.getIngredientMap().keySet()) {
        ItemStack x = r.getIngredientMap().get(j);
        net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(x);
        if (OreDictionary.getOreID(nms) != -1) {
          useOreDict = true;
        }
        if (LiquidContainerRegistry.isContainer(nms)) {
          useOreDict = true;
        }
        objRecipe.add(j);
        objRecipe.add(nms);
      }

      if (useOreDict) {
        ShapedOreRecipe rec =
            new ShapedOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe);
        GameRegistry.addRecipe(rec);
      } else {
        GameRegistry.addRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe);
      }
    } else if (recipe instanceof ShapelessRecipe) {
      ShapelessRecipe r = (ShapelessRecipe) recipe;
      List<net.minecraft.item.ItemStack> items = new ArrayList<net.minecraft.item.ItemStack>();
      boolean useOreDict = false;
      for (ItemStack i : r.getIngredientList()) {
        net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(i);
        if (OreDictionary.getOreID(nms) != -1) {
          useOreDict = true;
        }
        if (LiquidContainerRegistry.isContainer(nms)) {
          useOreDict = true;
        }
        items.add(nms);
      }
      if (useOreDict) {
        // TODO: Check if the new Class is even required
        // ShapelessOreRecipe nmsRec =
        new ShapelessOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), items);
      } else {
        ShapelessRecipes nmsRec =
            new ShapelessRecipes(CraftItemStack.createNMSItemStack(recipe.getResult()), items);
        GameRegistry.addRecipe(nmsRec);
      }
    }
    return true;
  }
 protected ItemStack fillOrEmptyContainer(
     ITankContainer tank, ItemStack itemstack, EnumFacing facing) {
   for (LiquidContainerData data : LiquidContainerRegistry.getRegisteredLiquidContainerData()) {
     if (data.container.isItemEqual(itemstack)) {
       int amount = data.stillLiquid.amount;
       LiquidStack liquid =
           tank.drain(
               ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), amount, false);
       if (liquid != null && liquid.isLiquidEqual(data.stillLiquid) && liquid.amount == amount) {
         tank.drain(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), amount, true);
         itemstack.stackSize--;
         ItemStack result = data.filled.copy();
         result.stackSize = 1;
         return result;
       }
     } else if (data.filled.isItemEqual(itemstack)) {
       LiquidStack liquid = data.stillLiquid;
       int amount =
           tank.fill(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), liquid, false);
       if (liquid.amount == amount) {
         tank.fill(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), liquid, true);
         ItemStack result = itemstack.getItem().getContainerItemStack(itemstack);
         itemstack.stackSize--;
         if (result == null) {
           result = data.container.copy();
           result.stackSize = 0;
         }
         return result;
       } else {
         return null;
       }
     }
   }
   return null;
 }