Search in sources :

Example 1 with Tank

use of buildcraft.lib.fluid.Tank in project BuildCraft by BuildCraft.

the class TankManagerTester method testSimpleMoving.

@Test
public void testSimpleMoving() {
    TankManager manager = new TankManager();
    manager.add(new Tank("tank_1", 3, null));
    Assert.assertEquals(2, manager.fill(new FluidStack(FluidRegistry.WATER, 2), true));
    Assert.assertEquals(1, manager.fill(new FluidStack(FluidRegistry.WATER, 2), true));
    Assert.assertTrue(new FluidStack(FluidRegistry.WATER, 3).isFluidStackIdentical(manager.drain(new FluidStack(FluidRegistry.WATER, 5), true)));
    manager.add(new Tank("tank_2", 3, null));
    Assert.assertEquals(5, manager.fill(new FluidStack(FluidRegistry.LAVA, 5), true));
    Assert.assertTrue(new FluidStack(FluidRegistry.LAVA, 4).isFluidStackIdentical(manager.drain(new FluidStack(FluidRegistry.LAVA, 4), true)));
    Assert.assertEquals(1, manager.get(1).getFluid().amount);
}
Also used : TankManager(buildcraft.lib.fluid.TankManager) FluidStack(net.minecraftforge.fluids.FluidStack) Tank(buildcraft.lib.fluid.Tank) Test(org.junit.Test)

Example 2 with Tank

use of buildcraft.lib.fluid.Tank in project BuildCraft by BuildCraft.

the class TileHeatExchangeStart method craft.

private void craft() {
    Tank c_in = tileEnd.tankCoolableIn;
    Tank c_out = tankCoolableOut;
    Tank h_in = tankHeatableIn;
    Tank h_out = tileEnd.tankHeatableOut;
    IRefineryRecipeManager reg = BuildcraftRecipeRegistry.refineryRecipes;
    ICoolableRecipe c_recipe = reg.getCoolableRegistry().getRecipeForInput(c_in.getFluid());
    IHeatableRecipe h_recipe = reg.getHeatableRegistry().getRecipeForInput(h_in.getFluid());
    if (h_recipe == null || c_recipe == null) {
        progressState = TileHeatExchange.EnumProgressState.STOPPING;
        return;
    }
    if (c_recipe.heatFrom() <= h_recipe.heatFrom()) {
        BCLog.logger.warn("Invalid heat values!");
        progressState = TileHeatExchange.EnumProgressState.STOPPING;
        return;
    }
    int c_diff = c_recipe.heatFrom() - c_recipe.heatTo();
    int h_diff = h_recipe.heatTo() - h_recipe.heatFrom();
    if (h_diff < 1 || c_diff < 1) {
        throw new IllegalStateException("Invalid recipe " + c_recipe + ", " + h_recipe);
    }
    // TODO: Make mult the *maximum* multiplier, not the exact one.
    int mult = FLUID_MULT[middles - 1];
    boolean needs_c = heatProvided <= 0;
    boolean needs_h = coolingProvided <= 0;
    FluidStack c_in_f = setAmount(c_recipe.in(), mult);
    FluidStack c_out_f = setAmount(c_recipe.out(), mult);
    FluidStack h_in_f = setAmount(h_recipe.in(), mult);
    FluidStack h_out_f = setAmount(h_recipe.out(), mult);
    if (canFill(c_out, c_out_f) && canFill(h_out, h_out_f) && canDrain(c_in, c_in_f) && canDrain(h_in, h_in_f)) {
        if (progressState == TileHeatExchange.EnumProgressState.OFF) {
            progressState = TileHeatExchange.EnumProgressState.PREPARING;
        } else if (progressState == TileHeatExchange.EnumProgressState.RUNNING) {
            heatProvided--;
            coolingProvided--;
            if (needs_c) {
                heatProvided += c_diff;
                fill(c_out, c_out_f);
                drain(c_in, c_in_f);
            }
            if (needs_h) {
                coolingProvided += h_diff;
                fill(h_out, h_out_f);
                drain(h_in, h_in_f);
            }
        }
    } else {
        progressState = TileHeatExchange.EnumProgressState.STOPPING;
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IHeatableRecipe(buildcraft.api.recipes.IRefineryRecipeManager.IHeatableRecipe) IRefineryRecipeManager(buildcraft.api.recipes.IRefineryRecipeManager) Tank(buildcraft.lib.fluid.Tank) ICoolableRecipe(buildcraft.api.recipes.IRefineryRecipeManager.ICoolableRecipe)

Aggregations

Tank (buildcraft.lib.fluid.Tank)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IRefineryRecipeManager (buildcraft.api.recipes.IRefineryRecipeManager)1 ICoolableRecipe (buildcraft.api.recipes.IRefineryRecipeManager.ICoolableRecipe)1 IHeatableRecipe (buildcraft.api.recipes.IRefineryRecipeManager.IHeatableRecipe)1 TankManager (buildcraft.lib.fluid.TankManager)1 Test (org.junit.Test)1