Example #1
0
  public static ItemStack toItemStack(FluidStack fluidStack) {
    if (fluidStack == null
        || fluidStack.getFluid() == null
        || fluidStack.getFluid().getBlock() == null) return null;

    return new ItemStack(fluidStack.getFluid().getBlock());
  }
Example #2
0
  @Override
  public void onNetworksCreated(List<FluidNetwork> networks) {
    if (fluidStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
      int[] caps = new int[networks.size()];
      int cap = 0;

      for (FluidNetwork network : networks) {
        caps[networks.indexOf(network)] = network.getCapacity();
        cap += network.getCapacity();
      }

      fluidStored.amount = Math.min(cap, fluidStored.amount);

      int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), fluidStored.amount);

      for (FluidNetwork network : networks) {
        int index = networks.indexOf(network);

        if (values[index] > 0) {
          network.fluidStored = new FluidStack(fluidStored.getFluid(), values[index]);
          network.fluidScale = network.getScale();
          network.refFluid = fluidStored.getFluid();
        }
      }
    }

    fluidScale = 0;
    fluidStored = null;
    refFluid = null;
  }
 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;
 }
Example #4
0
  public boolean addLiquid(FluidStack inFS) {
    if (inFS != null) {
      // We dont want very hot liquids stored here so if they are much hotter than boiling water, we
      // prevent it.
      if (inFS.getFluid() != null && inFS.getFluid().getTemperature(inFS) > 385) return false;

      if (fluid == null) {
        fluid = inFS.copy();
        if (fluid.amount > this.getMaxLiquid()) {
          fluid.amount = getMaxLiquid();
          inFS.amount = inFS.amount - this.getMaxLiquid();

        } else inFS.amount = 0;
      } else {
        // check if the barrel is full or if the fluid being added does not match the barrel liquid
        if (fluid.amount == getMaxLiquid() || !fluid.isFluidEqual(inFS)) return false;

        int a = fluid.amount + inFS.amount - getMaxLiquid();
        fluid.amount = Math.min(fluid.amount + inFS.amount, getMaxLiquid());
        if (a > 0) inFS.amount = a;
        else inFS.amount = 0;
      }
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      return true;
    }

    return false;
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   int maxDrain = resource.amount;
   if (this.canDrain(from, resource.getFluid()) && this.isValidFluid(resource.getFluid())) {
     return tank.drain(maxDrain, doDrain);
   }
   return null;
 }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.getFluid() == null) return 0;
   int toadd = Math.min(resource.amount, this.getCapacity(resource.getFluid()) - tank.getLevel());
   if (toadd <= 0) return 0;
   FluidStack fs = new FluidStack(resource.getFluid(), toadd);
   return this.canFill(from, resource.getFluid()) ? tank.fill(fs, doFill) : 0;
 }
 public static void setFluidStack(ItemStack stack, String key, FluidStack val) {
   if (val != null && val.getFluid() != null) {
     NBTTagCompound tag = getTagCompound(stack, key);
     tag.setString("fluid", val.getFluid().getName());
     tag.setInteger("amount", val.amount);
     setTagCompound(stack, key, tag);
   } else remove(stack, "fluid");
 }
  private void normalOperation(byte type) {

    int amount = tank[1].getCapacity() - tank[1].getFluidAmount();

    if (amount > FluidContainerRegistry.BUCKET_VOLUME / 10)
      amount = FluidContainerRegistry.BUCKET_VOLUME / 10;
    if (amount > 0) {
      FluidStack fluidStack;
      FluidStack activeLava;
      int activeValue;

      if (tank[0].getFluid().getFluid() == ModFluids.ActiveLava) {

        fluidStack = tank[0].drain(amount, true);
        activeLava = new FluidStack(ModFluids.ActiveLava, fluidStack.amount);
        activeValue = ((ActiveLava) activeLava.getFluid()).getActiveValue(fluidStack);

      } else {

        activeValue = tank[0].getFluid().getFluid().getTemperature();
        fluidStack = tank[0].drain(amount * 2, true);
        activeLava = new FluidStack(ModFluids.ActiveLava, fluidStack.amount / 2);
      }

      ActiveLava fluid = (ActiveLava) tank[1].getFluid().getFluid();

      // activeValue += fluid.getActiveValue(tank[1].getFluid());

      activeValue += type * 6;

      activeValue = Math.abs(activeValue);

      ((ActiveLava) activeLava.getFluid()).setActiveValue(activeLava, activeValue);

      tank[1].fill(activeLava, true);

      if (Math.random() < 0.42) {
        fluid.increaseActiveValue(tank[1].getFluid());
        if (Math.random() < 0.16) decrStackSize(1, 1);
      }

    } else {

      ActiveLava fluid = (ActiveLava) tank[1].getFluid().getFluid();
      int activeValue = fluid.getActiveValue(tank[1].getFluid());
      activeValue += type * 2;
      fluid.setActiveValue(tank[1].getFluid(), activeValue);

      if (Math.random() < 0.22) decrStackSize(1, 1);

      if (Math.random() < 0.27) heatOperation(type);
    }
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (hasValidMaster() && canDrain(from, resource.getFluid())) {
     SmelteryLogic smeltery =
         (SmelteryLogic)
             worldObj.getTileEntity(
                 getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
     if (resource.getFluid() == smeltery.getFluid().getFluid()) {
       return smeltery.drain(resource.amount, doDrain);
     }
   }
   return null;
 }
Example #10
0
  private boolean isValidWaterContainer(ItemStack stack) {
    if (stack == null || stack.stackSize != 1) return false;
    if (stack.getItem() == ModItems.waterBowl) return true;

    if (stack.getItem() instanceof IFluidContainerItem) {
      FluidStack fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
      return fluidStack != null
          && fluidStack.getFluid() == FluidRegistry.WATER
          && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
    }
    FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
    return fluidStack != null
        && fluidStack.getFluid() == FluidRegistry.WATER
        && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
  }
Example #11
0
  @Override
  public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
    // this is where all the action happens
    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    // if empty, find a new recipe
    if (this.tank.getFluidAmount() == 0) {
      CastingRecipe recipe = findRecipe(resource.getFluid());
      if (recipe == null) {
        // no recipe found -> can't fill
        return 0;
      }

      int capacity = recipe.fluid.amount;
      IFluidTank calcTank = new FluidTank(capacity);

      // no extra checks needed for the tank since it's empty and we have to set the capacity anyway
      if (doFill) {
        this.recipe = recipe;
        tank.setCapacity(capacity);
        calcTank = tank;
      }

      int filled = calcTank.fill(resource, doFill);
      if (filled > 0 && doFill) {
        renderOffset = filled;
        if (!worldObj.isRemote && worldObj instanceof WorldServer) {
          TinkerNetwork.sendToClients(
              (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
        }
      }
      return filled;
    }

    // non-empty tank. just try to fill
    int filled = tank.fill(resource, doFill);
    if (filled > 0 && doFill) {
      renderOffset += filled;
      if (!worldObj.isRemote && worldObj instanceof WorldServer) {
        TinkerNetwork.sendToClients(
            (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
      }
    }

    return filled;
  }
  /** @return a string representation of the object. */
  @Override
  public String toString() {

    StringBuilder stringBuilder = new StringBuilder();

    if (wrappedStack instanceof ItemStack) {
      ItemStack itemStack = (ItemStack) wrappedStack;
      try {
        stringBuilder.append(
            String.format(
                "%sxitemStack[%s:%s:%s:%s]",
                stackSize,
                itemStack.itemID,
                itemStack.getItemDamage(),
                itemStack.getUnlocalizedName(),
                itemStack.getItem().getClass().getCanonicalName()));
      } catch (ArrayIndexOutOfBoundsException e) {
        // NOOP
      }
    } else if (wrappedStack instanceof OreStack) {
      OreStack oreStack = (OreStack) wrappedStack;
      stringBuilder.append(String.format("%sxoreStack.%s", stackSize, oreStack.oreName));
    } else if (wrappedStack instanceof EnergyStack) {
      EnergyStack energyStack = (EnergyStack) wrappedStack;
      stringBuilder.append(String.format("%sxenergyStack.%s", stackSize, energyStack.energyName));
    } else if (wrappedStack instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) wrappedStack;
      stringBuilder.append(
          String.format("%sxfluidStack.%s", stackSize, fluidStack.getFluid().getName()));
    } else {
      stringBuilder.append("null");
    }

    return stringBuilder.toString();
  }
  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;
  }
  /** @return a string representation of the object. */
  @Override
  public String toString() {
    if (wrappedStack instanceof ItemStack) {
      ItemStack itemStack = (ItemStack) wrappedStack;
      String unlocalizedName = "";
      try {
        unlocalizedName = itemStack.getUnlocalizedName();
      } catch (ArrayIndexOutOfBoundsException e) {
        unlocalizedName = "no-name";
      }

      if (itemStack.hasTagCompound()) {
        return String.format(
            "%sxitemStack[%s@%s:%s]",
            stackSize, unlocalizedName, itemStack.getItemDamage(), itemStack.getTagCompound());
      } else {
        return String.format(
            "%sxitemStack[%s@%s]", stackSize, unlocalizedName, itemStack.getItemDamage());
      }
    } else if (wrappedStack instanceof OreStack) {
      OreStack oreStack = (OreStack) wrappedStack;
      return String.format("%sxoreStack.%s", stackSize, oreStack.oreName);
    } else if (wrappedStack instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) wrappedStack;
      return String.format("%sxfluidStack.%s", stackSize, fluidStack.getFluid().getName());
    } else {
      return "null-wrappedstack";
    }
  }
Example #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());
      }
    }
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (!canDrain(from, resource != null ? resource.getFluid() : null)) return null;
   if (master() != null) return master().drain(from, resource, doDrain);
   if (resource != null) return drain(from, resource.amount, doDrain);
   return null;
 }
Example #17
0
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   Fluid fluid = resource.getFluid();
   Tank emptyTank = null;
   for (Tank tank : fluidTanks) {
     Fluid type = tank.getFluidType();
     if (type == fluid) {
       int used = tank.fill(resource, doFill);
       if (used > 0 && doFill) {
         sendNetworkUpdate();
       }
       return used;
     } else if (emptyTank == null && tank.isEmpty()) {
       emptyTank = tank;
     }
   }
   if (emptyTank != null) {
     int used = emptyTank.fill(resource, doFill);
     if (used > 0 && doFill) {
       sendNetworkUpdate();
     }
     return used;
   }
   return 0;
 }
Example #18
0
  public int fill(
      ForgeDirection from, FluidStack resource, boolean doFill, boolean doPush, int pushToken) {
    if (resource == null || resource.amount <= 0) {
      return 0;
    }

    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    if (network == null) {
      return 0;
    }
    if (network.canAcceptLiquid(resource)) {
      network.setFluidType(resource);
    } else {
      return 0;
    }
    resource = resource.copy();
    resource.amount = Math.min(MAX_IO_PER_TICK, resource.amount);

    if (doPush) {
      return pushLiquid(from, resource, doFill, pushToken);
    } else {
      return tank.fill(resource, doFill);
    }
  }
Example #19
0
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {

    if (network == null || resource == null) {
      return 0;
    }
    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    // Note: This is just a guard against mekansims pipes that will continuously
    // call
    // fill on us if we push liquid to them.
    if (filledFromThisTick.contains(getLocation().getLocation(from))) {
      return 0;
    }

    if (network.lockNetworkForFill()) {
      if (doFill) {
        filledFromThisTick.add(getLocation().getLocation(from));
      }
      try {
        int res =
            fill(from, resource, doFill, true, network == null ? -1 : network.getNextPushToken());
        if (doFill && externalConnections.contains(from) && network != null) {
          network.addedFromExternal(res);
        }
        return res;
      } finally {
        network.unlockNetworkFromFill();
      }
    } else {
      return 0;
    }
  }
 private boolean canMake(FluidStack liq) {
   if (worldObj.isRemote) return false;
   if (tank.isEmpty()) return true;
   if (!tank.getActualFluid().equals(liq.getFluid())) return false;
   if (tank.getLevel() + liq.amount > tank.getCapacity()) return false;
   return true;
 }
Example #21
0
  private static int findFuelValue(ItemStack stack) {
    try {
      Item item = stack.getItem();

      if (item instanceof ItemBlock) {
        Block block = InvTools.getBlockFromStack(stack);

        String name = block.getUnlocalizedName();
        if (name != null && name.contains("blockScaffold")) return 0;
      }

      //            if (itemID == Item.coal.itemID && stack.getItemDamage() == 0)
      //                return 1600;

      if (item == Items.blaze_rod) return 1000;

      FluidStack liquid = FluidItemHelper.getFluidStackInContainer(stack);
      if (liquid != null && Fluids.LAVA.get() == liquid.getFluid()) return liquid.amount;

      String name = stack.getItem().getUnlocalizedName();
      if (name != null && name.contains("itemScrap")) return 0;

      return TileEntityFurnace.getItemBurnTime(stack);
    } catch (Exception ex) {
      Game.logThrowable(
          "Error in Fuel Handler! Is some mod creating items that are not compliant with standards?",
          ex);
    }
    return 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;
  }
  @Override
  public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
    if (resource != null && canDrain(from, resource.getFluid())) {
      return fluidTank.drain(resource.amount, doDrain);
    }

    return null;
  }
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (from == ForgeDirection.UP && resource.getFluid().canBePlacedInWorld()) {
      return fluidTank.fill(resource, true);
    }

    return 0;
  }
 /**
  * Used to get the resulting ItemStack form a source ItemStack
  *
  * @param item The Source ItemStack
  * @return The result ItemStack
  */
 public ItemStack getFreezingResult(FluidStack liquid) {
   Fluid f = liquid.getFluid();
   if (amounts.containsKey(f)) {
     int req = amounts.get(f);
     if (req > liquid.amount) return null;
     return recipeList.get(f);
   } else return null;
 }
Example #26
0
  @Override
  public int fill(FluidStack resource, boolean doFill) {
    int result = super.fill(resource, doFill);
    if (doFill && result > 0) {
      this.setToHot(resource.getFluid().getTemperature() > (300 + 273));
    }

    return result;
  }
Example #27
0
 public static void addMeltableOre(ItemStack stack, FluidStack output, int temperature) {
   if (stack != null
       && output != null
       && stack.getItem() != null
       && output.getFluid() != null) // More null checks than you can poke a stick at
   {
     Instance.addMeltable(stack, true, output, temperature);
   }
 }
 @Override
 public final int onTick(TileEntity te, FluidStack stored) {
   if (stored != null
       && stored.amount >= 1000
       && stored.getFluid() == FluidRegistry.getFluid("chroma")) {
     return this.doTick(te, stored);
   } else {
     return 0;
   }
 }
  @Override
  public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
    if (fluidTank.getFluid() != null
        && fluidTank.getFluid().getFluid() == resource.getFluid()
        && from == ForgeDirection.getOrientation(1)) {
      return drain(from, resource.amount, doDrain);
    }

    return null;
  }
Example #30
0
  public synchronized int emit(FluidStack fluidToSend, boolean doTransfer) {
    if (fluidToSend == null
        || (fluidStored != null && fluidStored.getFluid() != fluidToSend.getFluid())) {
      return 0;
    }

    int toUse = Math.min(getFluidNeeded(), fluidToSend.amount);

    if (doTransfer) {
      if (fluidStored == null) {
        fluidStored = fluidToSend.copy();
        fluidStored.amount = toUse;
      } else {
        fluidStored.amount += toUse;
      }
    }

    return toUse;
  }