public ItemStack getFilledItem(ItemStack empty, boolean drainTank) {
    if (empty == null || tank.getFluid() == null) return null;
    BottlingMachineRecipe recipe = BottlingMachineRecipe.findRecipe(empty, tank.getFluid());
    if (recipe != null && recipe.output != null) {
      if (drainTank) tank.drain(recipe.fluidInput.amount, true);
      return recipe.output;
    }

    ItemStack filled =
        FluidContainerRegistry.fillFluidContainer(
            new FluidStack(tank.getFluid(), Integer.MAX_VALUE), empty);
    FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filled);
    if (filled != null && fs.amount <= tank.getFluidAmount()) {
      if (drainTank) tank.drain(fs.amount, true);
      return filled;
    }

    if (empty.getItem() instanceof IFluidContainerItem) {
      int accepted = ((IFluidContainerItem) empty.getItem()).fill(empty, tank.getFluid(), false);
      if (accepted > 0) {
        filled = empty.copy();
        ((IFluidContainerItem) filled.getItem())
            .fill(filled, new FluidStack(tank.getFluid(), accepted), true);
        if (drainTank) tank.drain(accepted, true);
        return filled;
      }
    }
    return null;
  }
  private void outputActiveLava() {
    FluidStack fluid = tank[1].getFluid();
    if (fluid != null) {
      if (itemStacks[2] != null && itemStacks[2].stackSize == 1) {
        ItemStack itemStack = itemStacks[2];
        if (FluidContainerRegistry.isEmptyContainer(itemStack)) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {
            FluidStack oneBucketOfFluid =
                new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
            ItemStack filledBucket =
                FluidContainerRegistry.fillFluidContainer(
                    oneBucketOfFluid, FluidContainerRegistry.EMPTY_BUCKET);
            itemStacks[2] = filledBucket;
            fluid.amount -= FluidContainerRegistry.BUCKET_VOLUME;
          }
        } else if (itemStack.getItem() instanceof IFluidContainerItem && (workingTick % 20) == 10) {
          if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) {

            IFluidContainerItem fluidContainerItem = (IFluidContainerItem) itemStack.getItem();
            FluidStack fluidStack = fluid.copy();

            if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME)
              fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME;

            int amount = fluidContainerItem.fill(itemStack, fluidStack, true);
            if (amount > 0) {
              fluid.amount -= amount;
            }
            if (fluid.amount == 0) tank[1].setFluid(null);
          }
        }
      }
    }
  }
  // result
  private void getRecipeFood(
      World world, int x, int y, int z, EntityPlayer player, ItemStack input, ItemStack result) {
    if (input == null || input.getItem() == null) return;
    ItemStack container = null;
    if (FluidContainerRegistry.isFilledContainer(input)) {
      container = FluidContainerRegistry.drainFluidContainer(input);
    } else {
      container = input.getItem().getContainerItem(input);
    }

    if (!player.capabilities.isCreativeMode && --input.stackSize <= 0) {
      player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack) null);
    }

    if (!world.isRemote) {
      EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, result);
      world.spawnEntityInWorld(entity);
    }

    if (container != null) {
      if (!world.isRemote) {
        EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, container);
        world.spawnEntityInWorld(entity);
      }
    }

    world.playSoundAtEntity(player, "random.pop", 0.4F, 1.8F);
  }
 public ItemStack tryPlaceContainedLiquid(
     World world, ItemStack bucket, int x, int y, int z, int side) {
   if (world.isRemote) return bucket;
   CarbonContainer item = (CarbonContainer) bucket.getItem();
   int id = bucket.getItemDamage();
   if (id != 0) {
     if (!item.canPlaceInWorld) return bucket;
     FluidStack liquid = LiquidRegistry.getLiquid(id);
     if (world.setBlock(x, y, z, liquid.getFluid().getBlock(), 0, 3))
       return item.getContainerItem(bucket);
     return bucket;
   }
   if (!item.canBeFilledFromWorld) return bucket;
   Block block = world.getBlock(x, y, z);
   if (block instanceof IFluidBlock) {
     FluidStack liquid = ((IFluidBlock) block).drain(world, x, y, z, false);
     if (liquid != null && FluidRegistry.isFluidRegistered(liquid.getFluid())) {
       ItemStack r = FluidContainerRegistry.fillFluidContainer(liquid, bucket);
       if (r != null && FluidContainerRegistry.isFilledContainer(r)) {
         ((IFluidBlock) block).drain(world, x, y, z, true);
         return r;
       }
     }
   }
   return bucket;
 }
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack stack) {
   if (!formed) return false;
   if (master() != null) return master().isItemValidForSlot(slot, stack);
   if (slot == 1 || slot == 3 || slot == 5) return false;
   if (slot == 4)
     return (tank2.getFluidAmount() <= 0
         ? FluidContainerRegistry.isEmptyContainer(stack)
         : FluidContainerRegistry.fillFluidContainer(
                 tank2.getFluid(), Utils.copyStackWithAmount(stack, 1))
             != null);
   FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(stack);
   if (fs == null) return false;
   RefineryRecipe partialRecipe = DieselHandler.findIncompleteRefineryRecipe(fs, null);
   if (partialRecipe == null) return false;
   if (slot == 0)
     return (tank0.getFluidAmount() <= 0 || fs.isFluidEqual(tank0.getFluid()))
         && (tank1.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank1.getFluid()) != null);
   if (slot == 2)
     return (tank1.getFluidAmount() <= 0 || fs.isFluidEqual(tank1.getFluid()))
         && (tank0.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank0.getFluid()) != null);
   return false;
 }
Пример #6
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) {
      return true;
    }

    ItemStack held = player.getHeldItem();
    FluidStack fluidHeld = FluidContainerRegistry.getFluidForFilledItem(held);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (fluidHeld != null
        && fluidHeld.getFluid() == FluidRegistry.getFluid("water")
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canReceiveWaterBucket()) {
        tank.addBucketOfWater();
        if (FluidContainerRegistry.isBucket(held)
            && !(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          int heldLocation = player.inventory.currentItem;
          player.inventory.decrStackSize(heldLocation, 1);
          world.spawnEntityInWorld(
              new EntityItem(
                  world, player.posX, player.posY, player.posZ, new ItemStack(Items.bucket, 1)));
          //                    player.inventory.setInventorySlotContents(heldLocation, new
          // ItemStack(Items.bucket, 1));
        }
      }
      return true;
    }
    if (held != null
        && held.getItem() == Items.bucket
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canGiveSolarWater()) {
        ItemStack filledBucket =
            FluidContainerRegistry.fillFluidContainer(
                new FluidStack(ModFluids.fluidSolarWater, 1000), new ItemStack(Items.bucket, 1));
        tank.removeBucketOfSolarWater();
        if (!(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          player.inventory.decrStackSize(player.inventory.currentItem, 1);
          // player.inventory.setInventorySlotContents(player.inventory.getFirstEmptyStack(),
          // filledBucket);
          world.spawnEntityInWorld(
              new EntityItem(world, player.posX, player.posY, player.posZ, filledBucket));
        }
        return true;
      }
    }

    return false;
  }
 public static ItemStack drainFluidContainer(FluidTank tank, ItemStack containerIn) {
   if (FluidContainerRegistry.isFilledContainer(containerIn)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(containerIn);
     if (fs != null && tank.getFluidAmount() + fs.amount <= tank.getCapacity()) {
       ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(containerIn);
       if (emptyContainer != null && tank.fill(fs, true) == fs.amount) return emptyContainer;
     }
   }
   return null;
 }
Пример #8
0
 public ItemStack addLiquid(ItemStack is) {
   if (is == null) return is;
   if (FluidContainerRegistry.isFilledContainer(is)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(is);
     if (addLiquid(fs)) {
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return is.getItem().getContainerItem(is);
     }
   }
   return is;
 }
  @Override
  public boolean isItemValidForSlot(int slotID, ItemStack itemstack) {
    if (slotID == 0) {
      return getFuel(itemstack) > 0
          || (FluidContainerRegistry.getFluidForFilledItem(itemstack) != null
              && FluidContainerRegistry.getFluidForFilledItem(itemstack).getFluidID()
                  == FluidRegistry.LAVA.getID());
    } else if (slotID == 1) {
      return ChargeUtils.canBeCharged(itemstack);
    }

    return true;
  }
Пример #10
0
  public static boolean fillFluidHandlerWithPlayerItem(
      World world, IFluidHandler handler, EntityPlayer player, ItemStack equipped) {
    if (equipped == null) return false;

    FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(equipped);
    if (fluid != null) {
      if (handler.fill(null, fluid, false) == fluid.amount || player.capabilities.isCreativeMode) {
        if (world.isRemote) return true;

        ItemStack filledStack = FluidContainerRegistry.drainFluidContainer(equipped);
        if (!player.capabilities.isCreativeMode) {
          if (equipped.stackSize == 1) {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            player.inventory.addItemStackToInventory(filledStack);
          } else {
            equipped.stackSize -= 1;
            if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
              player.dropItem(filledStack, false, true);
          }
          player.openContainer.detectAndSendChanges();
          if (player instanceof EntityPlayerMP)
            ((EntityPlayerMP) player)
                .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        }
        handler.fill(null, fluid, true);
        return true;
      }
    } else if (equipped.getItem() instanceof IFluidContainerItem) {
      IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
      fluid = container.getFluid(equipped);
      if (handler.fill(null, fluid, false) > 0) {
        if (world.isRemote) return true;

        int fill = handler.fill(null, fluid, true);
        if (equipped.stackSize > 1) {
          ItemStack emptied = ItemStackUtils.copyStackWithAmount(equipped, 1);
          equipped.stackSize -= 1;
          container.drain(emptied, fill, true);
          if (!player.inventory.addItemStackToInventory(emptied))
            player.dropItem(emptied, false, true);
        } else container.drain(equipped, fill, true);
        player.openContainer.detectAndSendChanges();
        if (player instanceof EntityPlayerMP)
          ((EntityPlayerMP) player)
              .updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
        return true;
      }
    }
    return false;
  }
Пример #11
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) return true;
    TileEntityJarOHoney tile = Utils.getTileEntity(world, x, y, z, TileEntityJarOHoney.class);
    if (tile == null) return false;

    ItemStack stack = player.getCurrentEquippedItem();
    if (FluidContainerRegistry.isFilledContainer(stack)) {
      FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
      if (fluidStack.isFluidEqual(tile.getHoney()))
        if (fluidStack.amount + tile.getHoney().amount > TileEntityJarOHoney.HONEY_MAX_AMOUNT)
          return true;
        else {
          tile.addHoney(fluidStack.amount);
          ItemStack container = stack.getItem().getContainerItem(stack);
          stack.stackSize--;
          if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, container);
          else if (!player.inventory.addItemStackToInventory(container))
            Utils.dropStack(world, x, y, z, container);

          return true;
        }
    } else if (FluidContainerRegistry.isEmptyContainer(stack)) {
      ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tile.getHoney(), stack);
      if (filledContainer != null) {
        stack.stackSize--;
        if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, filledContainer);
        else if (!player.inventory.addItemStackToInventory(filledContainer))
          Utils.dropStack(world, x, y, z, filledContainer);

        tile.drainHoney(FluidContainerRegistry.getFluidForFilledItem(filledContainer).amount);
        return true;
      }
    } else {
      player.getFoodStats().addStats(1, 0.8F);
      player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1));
      tile.drainHoney(100);
    }
    return false;
  }
Пример #12
0
  public static ItemStack fillFluidContainer(FluidTank tank, ItemStack containerIn) {
    if (tank.getFluidAmount() > 0)
      if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
        ItemStack filledContainer =
            FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
        if (filledContainer != null) {
          FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
          if (fs.amount <= tank.getFluidAmount()) {
            tank.drain(fs.amount, true);

            return filledContainer;
          }
        }
      }
    return null;
  }
Пример #13
0
  public static boolean canInteractWithFluid(
      DockingStation station, IFluidFilter filter, Class<?> actionClass) {
    boolean actionFound = false;

    for (StatementSlot s : station.getActiveActions()) {
      if (actionClass.isAssignableFrom(s.statement.getClass())) {
        StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);

        if (!param.hasFilter()) {
          actionFound = true;
          break;
        } else {
          for (ItemStack stack : param.getStacks()) {
            if (stack != null) {
              FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);

              if (fluid != null && filter.matches(fluid.getFluid())) {
                actionFound = true;
                break;
              }
            }
          }
        }
      }
    }

    return actionFound;
  }
Пример #14
0
 public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
   List<ItemStack> containers = new ArrayList();
   for (FluidContainerRegistry.FluidContainerData data :
       FluidContainerRegistry.getRegisteredFluidContainerData())
     if (data.fluid.containsFluid(fluidStack)) containers.add(data.filledContainer);
   return containers;
 }
Пример #15
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);

    if (position >= 0 && position < 2) {
      if (k == 0) {
        if (!isShiftKeyDown()) {
          FluidStack liquid =
              FluidContainerRegistry.getFluidForFilledItem(mc.thePlayer.inventory.getItemStack());

          if (liquid == null) {
            return;
          }

          container.setFilter(position, liquid.getFluid());
        } else {
          container.setFilter(position, null);
        }
      } else {
        TileRefinery ref = (TileRefinery) this.tile;

        if (position == 0) container.setFilter(position, ref.tank1.getFluidType());
        else if (position == 1) container.setFilter(position, ref.tank2.getFluidType());
      }
    }
  }
Пример #16
0
 public ItemStack removeLiquid(ItemStack is) {
   if (is == null) return is;
   if (FluidContainerRegistry.isEmptyContainer(is)) {
     ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is);
     if (out != null) {
       FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out);
       fluid.amount -= fs.amount;
       is = null;
       if (fluid.amount == 0) {
         fluid = null;
       }
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return out;
     }
   }
   return is;
 }
Пример #17
0
 public ItemStack addLiquid(ItemStack is) {
   if (is == null || is.stackSize > 1) return is;
   if (FluidContainerRegistry.isFilledContainer(is)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(is);
     if (addLiquid(fs)) {
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return FluidContainerRegistry.drainFluidContainer(is);
     }
   } else if (is.getItem() instanceof IFluidContainerItem) {
     FluidStack isfs = ((IFluidContainerItem) is.getItem()).getFluid(is);
     if (isfs != null && addLiquid(isfs)) {
       ((IFluidContainerItem) is.getItem()).drain(is, is.getMaxDamage(), true);
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     }
   }
   return is;
 }
Пример #18
0
 public static FluidStack getFluidFromItemStack(ItemStack stack) {
   if (stack == null) return null;
   FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
   if (fluid != null) return fluid;
   else if (stack.getItem() instanceof IFluidContainerItem)
     return ((IFluidContainerItem) stack.getItem()).getFluid(stack);
   return null;
 }
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack stack) {
   return stack != null
       && stack.getItem() != null
       && slot == 0
       && (stack.getItem() instanceof IFluidContainerItem
           || FluidContainerRegistry.isContainer(stack));
 }
Пример #20
0
 public static void registerFluidContainers() {
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("latex", FluidContainerRegistry.BUCKET_VOLUME / 4),
       new ItemStack(BCTFCItems.LatexBowl),
       new ItemStack(Items.bowl));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("latex", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 0),
       new ItemStack(TFCItems.woodenBucketEmpty));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("saltwater", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 2),
       new ItemStack(BCTFCItems.Buckets, 1, 1));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("freshwater", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 3),
       new ItemStack(BCTFCItems.Buckets, 1, 1));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("hotwater", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 4),
       new ItemStack(BCTFCItems.Buckets, 1, 1));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("oil", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 6),
       new ItemStack(BCTFCItems.Buckets, 1, 5));
   FluidContainerRegistry.registerFluidContainer(
       FluidRegistry.getFluidStack("fuel", FluidContainerRegistry.BUCKET_VOLUME),
       new ItemStack(BCTFCItems.Buckets, 1, 7),
       new ItemStack(BCTFCItems.Buckets, 1, 5));
 }
Пример #21
0
 public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
   List<ItemStack> containers = new ArrayList<ItemStack>();
   for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
     FluidStack inContainer = FluidItemHelper.getFluidStackInContainer(data.filledContainer);
     if (inContainer != null && inContainer.containsFluid(fluidStack))
       containers.add(data.filledContainer.copy());
   }
   return containers;
 }
 public static void registerAsContainer(Fluid fluid) {
   FluidStack stack =
       FluidRegistry.getFluidStack(fluid.getName(), FluidContainerRegistry.BUCKET_VOLUME);
   stack = stack.copy();
   stack.amount = cell.volume;
   FluidContainerRegistry.registerFluidContainer(
       new FluidContainerData(
           stack, new ItemStack(cell, 1, LiquidRegistry.getID(stack)), new ItemStack(cell, 1, 0)));
 }
Пример #23
0
 public static ItemStack getEmptyFluidContainer(ItemStack itemStack) {
   for (FluidContainerRegistry.FluidContainerData data :
       FluidContainerRegistry.getRegisteredFluidContainerData()) {
     if (data.filledContainer.isItemEqual(itemStack)) {
       return data.emptyContainer;
     }
   }
   return itemStack.getItem().getContainerItemStack(itemStack);
 }
Пример #24
0
 public static boolean fillPlayerItemFromFluidHandler(
     World world, IFluidHandler handler, EntityPlayer player, FluidStack tankFluid) {
   ItemStack equipped = player.getCurrentEquippedItem();
   if (equipped == null) return false;
   if (FluidContainerRegistry.isEmptyContainer(equipped)) {
     ItemStack filledStack = FluidContainerRegistry.fillFluidContainer(tankFluid, equipped);
     FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(filledStack);
     if (fluid == null || filledStack == null) return false;
     if (!player.capabilities.isCreativeMode)
       if (equipped.stackSize == 1) {
         player.inventory.setInventorySlotContents(player.inventory.currentItem, filledStack);
         equipped.stackSize -= 1;
         if (equipped.stackSize <= 0) equipped = null;
       } else {
         if (equipped.stackSize == 1) {
           player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
           player.inventory.addItemStackToInventory(filledStack);
         } else {
           equipped.stackSize -= 1;
           if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack))
             player.func_146097_a(filledStack, false, true);
         }
         player.openContainer.detectAndSendChanges();
         ((EntityPlayerMP) player)
             .sendContainerAndContentsToPlayer(
                 player.openContainer, player.openContainer.getInventory());
       }
     handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
     return true;
   } else if (equipped.getItem() instanceof IFluidContainerItem) {
     IFluidContainerItem container = (IFluidContainerItem) equipped.getItem();
     if (container.fill(equipped, tankFluid, false) > 0) {
       int fill = container.fill(equipped, tankFluid, true);
       handler.drain(ForgeDirection.UNKNOWN, fill, true);
       player.openContainer.detectAndSendChanges();
       ((EntityPlayerMP) player)
           .sendContainerAndContentsToPlayer(
               player.openContainer, player.openContainer.getInventory());
       return true;
     }
   }
   return false;
 }
Пример #25
0
 public static void nerfWaterBottle() {
   for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
     if (data.filledContainer.getItem() == Items.potionitem
         && data.emptyContainer.getItem() == Items.glass_bottle
         && Fluids.WATER.is(data.fluid)) {
       data.fluid.amount = 333;
       return;
     }
   }
 }
  @Override
  public boolean canExtractItem(int slotID, ItemStack itemstack, int side) {
    if (slotID == 1) {
      return ChargeUtils.canBeOutputted(itemstack, true);
    } else if (slotID == 0) {
      return FluidContainerRegistry.isEmptyContainer(itemstack);
    }

    return false;
  }
Пример #27
0
 public static ItemStack fillFluidContainer(
     FluidTank tank, ItemStack containerIn, ItemStack containerOut) {
   if (tank.getFluidAmount() > 0 && containerIn != null) {
     if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
       ItemStack filledContainer =
           FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
       if (filledContainer != null) {
         FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
         if (fs.amount <= tank.getFluidAmount()
             && (containerOut == null
                 || OreDictionary.itemMatches(containerOut, filledContainer, true))) {
           tank.drain(fs.amount, true);
           return filledContainer;
         }
       }
     } else if (containerIn.getItem() instanceof IFluidContainerItem) {
       IFluidContainerItem iContainer = (IFluidContainerItem) containerIn.getItem();
       int available = tank.getFluidAmount();
       int space =
           iContainer.getCapacity(containerIn)
               - (iContainer.getFluid(containerIn) == null
                   ? 0
                   : iContainer.getFluid(containerIn).amount);
       if (available >= space
           && iContainer.fill(containerIn, tank.getFluid(), false) == space) // Fill in one go
       {
         ItemStack filledContainer = copyStackWithAmount(containerIn, 1);
         int filled = iContainer.fill(filledContainer, tank.getFluid(), true);
         if (containerOut == null
             || (OreDictionary.itemMatches(containerOut, filledContainer, true)
                 && ItemStack.areItemStackTagsEqual(filledContainer, containerOut))) {
           tank.drain(filled, true);
           return filledContainer;
         }
       } else {
         int filled = iContainer.fill(containerIn, tank.getFluid(), true);
         tank.drain(filled, true);
       }
     }
   }
   return null;
 }
Пример #28
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote) {
      careForInventorySlot();
      if (worldObj.isRaining()
          && !this.getSealed()
          && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) {
        if (this.fluid == null) fluid = new FluidStack(TFCFluid.FRESHWATER, 1);
        else if (this.fluid != null && fluid.getFluid() == TFCFluid.FRESHWATER)
          fluid.amount = Math.min(fluid.amount + 1, 10000);
      }

      processTimer++;

      if (processTimer > 100) {
        ProcessItems();
        processTimer = 0;
      }

      if (fluid != null && fluid.amount == 0) fluid = null;

      if (mode == MODE_IN) {
        FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(getInputStack());
        if (inLiquid != null) {
          if (this.fluid == null) {
            this.fluid = inLiquid.copy();
            this.setInventorySlotContents(
                0, getInputStack().getItem().getContainerItem(getInputStack()));
          } else if (inLiquid.isFluidEqual(this.fluid)) {
            if (addLiquid(inLiquid.amount)) {
              this.setInventorySlotContents(
                  0, getInputStack().getItem().getContainerItem(getInputStack()));
            }
          }
        }
      } else if (mode == MODE_OUT) {
        if (FluidContainerRegistry.isEmptyContainer(getInputStack())) {
          this.setInventorySlotContents(0, this.removeLiquid(getInputStack()));
        }
      }
    }
  }
Пример #29
0
  @Override
  public void loadCraftingRecipes(ItemStack result) {
    FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(result);
    if (fs != null) {
      ArrayList<ItemStack> li = RecipesCentrifuge.getRecipes().getSources(fs.getFluid());
      for (int i = 0; i < li.size(); i++) arecipes.add(new CentrifugeRecipe(li.get(i)));
    }

    ArrayList<ItemStack> li = RecipesCentrifuge.getRecipes().getSources(result);
    for (int i = 0; i < li.size(); i++) arecipes.add(new CentrifugeRecipe(li.get(i)));
  }
Пример #30
0
  private ItemStack getContainer(ItemStack stack) {
    if (stack.getItem() == ModItems.waterBowl) return new ItemStack(Items.bowl);

    if (stack.getItem().hasContainerItem(stack)) return stack.getItem().getContainerItem(stack);
    else if (stack.getItem() instanceof IFluidContainerItem) {
      ((IFluidContainerItem) stack.getItem())
          .drain(stack, FluidContainerRegistry.BUCKET_VOLUME, true);
      return stack;
    }
    return FluidContainerRegistry.drainFluidContainer(stack);
  }