Search in sources :

Example 26 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project gregtech6 by GregTech6.

the class MultiTileEntityBathingPot method onTick2.

@Override
public void onTick2(long aTimer, boolean aIsServerSide) {
    if (aIsServerSide) {
        if (SERVER_TIME % 600 == 10 && worldObj.isRaining() && getRainOffset(0, 1, 0)) {
            BiomeGenBase tBiome = getBiome();
            if (tBiome.rainfall > 0 && tBiome.temperature >= 0.2) {
                Block tInFront = getBlockAtSide(SIDE_TOP);
                if (!(tInFront instanceof BlockLiquid) && !(tInFront instanceof IFluidBlock) && !tInFront.isSideSolid(worldObj, xCoord, yCoord + 1, zCoord, FORGE_DIR_OPPOSITES[SIDE_TOP]) && !tInFront.isSideSolid(worldObj, xCoord, yCoord + 1, zCoord, FORGE_DIR[SIDE_TOP])) {
                    FluidStack tWater = FL.Water.make((long) Math.max(1, tBiome.rainfall * 200) * (worldObj.isThundering() ? 2 : 1));
                    if (tWater != null) {
                        IFluidTank tTank = getFluidTankFillable2(SIDE_TOP, tWater);
                        if (tTank != null)
                            tTank.fill(tWater, T);
                    }
                }
            }
        }
        boolean tBreak = F;
        mDisplay = 0;
        for (FluidTankGT tTank : mTanksOutput) if (tTank.has()) {
            mDisplay = (short) (-2 - tTank.getFluid().getFluidID());
            tBreak = T;
            break;
        }
        if (!tBreak) {
            for (FluidTankGT tTank : mTanksInput) if (tTank.has()) {
                mDisplay = (short) (-2 - tTank.getFluid().getFluidID());
                tBreak = T;
                break;
            }
            if (!tBreak) {
                ItemStack tStack;
                for (int i = 0; i < 7; i++) if (ST.valid(tStack = slot(6 - i))) {
                    OreDictItemData tData = OM.data_(tStack);
                    if (tData == null || tData.mMaterial == null) {
                        mDisplay = -1;
                    } else {
                        mDisplay = tData.mMaterial.mMaterial.mID;
                    }
                    tBreak = T;
                    break;
                }
            }
        }
    }
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) FluidStack(net.minecraftforge.fluids.FluidStack) FluidTankGT(gregapi.fluid.FluidTankGT) OreDictItemData(gregapi.oredict.OreDictItemData) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 27 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project EvilCraft by CyclopsMC.

the class BlockTankHelpers method tileDataToItemStack.

/**
 * Convert fluid capabilities of tile to item.
 * @param tile The tile that has already been removed from the world.
 * @param itemStack The input itemstack.
 * @return The resulting itemstack.
 */
public static ItemStack tileDataToItemStack(BlockEntity tile, ItemStack itemStack) {
    IFluidHandler fluidHandlerTile = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
    if (fluidHandlerTile != null) {
        IFluidHandlerItemCapacity fluidHandlerItemCapacity = itemStack.getCapability(Capabilities.FLUID_HANDLER_ITEM_CAPACITY).orElse(null);
        if (fluidHandlerItemCapacity != null) {
            if (fluidHandlerTile instanceof IFluidTank) {
                IFluidTank fluidTank = (IFluidTank) fluidHandlerTile;
                fluidHandlerItemCapacity.setCapacity(fluidTank.getCapacity());
                itemStack = fluidHandlerItemCapacity.getContainer();
            }
        }
        IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).orElse(null);
        if (fluidHandlerItem != null) {
            FluidActionResult res = FluidUtil.tryFillContainer(itemStack, fluidHandlerTile, Integer.MAX_VALUE, null, true);
            if (res.isSuccess()) {
                itemStack = res.getResult();
            }
        }
    }
    return itemStack;
}
Also used : IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidHandlerItemCapacity(org.cyclops.cyclopscore.capability.fluid.IFluidHandlerItemCapacity) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 28 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.

the class WorkableTieredMetaTileEntity method canInputFluid.

protected boolean canInputFluid(FluidStack inputFluid) {
    RecipeMap<?> recipeMap = workable.recipeMap;
    if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
        // if recipe map forces input of given fluid, return true
        return true;
    Set<Recipe> matchingRecipes = null;
    for (IFluidTank fluidTank : importFluids) {
        FluidStack fluidInTank = fluidTank.getFluid();
        if (fluidInTank != null) {
            if (matchingRecipes == null) {
                // if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
                matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
            } else {
                // else, remove recipes that don't contain fluid in this tank from list
                matchingRecipes.removeIf(recipe -> !recipe.hasInputFluid(fluidInTank));
            }
        }
    }
    if (matchingRecipes == null) {
        // if all tanks are empty, generally fluid can be inserted if there are recipes for it
        return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
    } else {
        // otherwise, we can insert fluid only if one of recipes accept it as input
        return matchingRecipes.stream().anyMatch(recipe -> recipe.hasInputFluid(inputFluid));
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 29 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.

the class GTUtility method fluidHandlerToList.

/**
 * @return a list of fluidstack linked with given fluid handler
 * modifications in list will reflect on fluid handler and wise-versa
 */
public static List<FluidStack> fluidHandlerToList(IMultipleTankHandler fluidInputs) {
    List<IFluidTank> backedList = fluidInputs.getFluidTanks();
    return new AbstractList<FluidStack>() {

        @Override
        public FluidStack set(int index, FluidStack element) {
            IFluidTank fluidTank = backedList.get(index);
            FluidStack oldStack = fluidTank.getFluid();
            if (!(fluidTank instanceof FluidTank))
                return oldStack;
            ((FluidTank) backedList.get(index)).setFluid(element);
            return oldStack;
        }

        @Override
        public FluidStack get(int index) {
            return backedList.get(index).getFluid();
        }

        @Override
        public int size() {
            return backedList.size();
        }
    };
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 30 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.

the class FluidTankList method deserializeNBT.

@Override
public void deserializeNBT(NBTTagCompound nbt) {
    NBTTagList tanks = nbt.getTagList("Tanks", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < Math.min(fluidTanks.size(), nbt.getInteger("TankAmount")); i++) {
        NBTBase nbtTag = tanks.get(i);
        IFluidTank fluidTank = fluidTanks.get(i);
        if (fluidTank instanceof FluidTank) {
            ((FluidTank) fluidTank).readFromNBT((NBTTagCompound) nbtTag);
        } else if (fluidTank instanceof INBTSerializable) {
            ((INBTSerializable) fluidTank).deserializeNBT(nbtTag);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) NBTBase(net.minecraft.nbt.NBTBase) INBTSerializable(net.minecraftforge.common.util.INBTSerializable) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Aggregations

IFluidTank (net.minecraftforge.fluids.IFluidTank)58 FluidStack (net.minecraftforge.fluids.FluidStack)30 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)10 FluidTank (net.minecraftforge.fluids.FluidTank)9 Nullable (javax.annotation.Nullable)6 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)5 NBTBase (net.minecraft.nbt.NBTBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 INBTSerializable (net.minecraftforge.common.util.INBTSerializable)4 Recipe (gregtech.api.recipes.Recipe)3 ArrayList (java.util.ArrayList)3 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)3 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)2 FluidTankGT (gregapi.fluid.FluidTankGT)2 OreDictItemData (gregapi.oredict.OreDictItemData)2 FuelRecipe (gregtech.api.recipes.recipes.FuelRecipe)2 BlockLiquid (net.minecraft.block.BlockLiquid)2