Search in sources :

Example 6 with IFluidTank

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

the class FluidTankList method fillTanksImpl.

// fills exactly one tank if multi-filling is not allowed
// and as much tanks as possible otherwise
// note that it will always try to fill tanks with same fluid first
private int fillTanksImpl(FluidStack resource, boolean doFill) {
    int totalFilled = 0;
    // first, try to fill tanks that already have same fluid type
    for (IFluidTank handler : fluidTanks) {
        if (resource.isFluidEqual(handler.getFluid())) {
            int filledAmount = handler.fill(resource, doFill);
            totalFilled += filledAmount;
            resource.amount -= filledAmount;
            // if filling multiple tanks is not allowed, or resource is empty, return now
            if (!allowSameFluidFill || resource.amount == 0)
                return totalFilled;
        }
    }
    // otherwise, try to fill empty tanks
    for (IFluidTank handler : fluidTanks) {
        if (handler.getFluidAmount() == 0) {
            int filledAmount = handler.fill(resource, doFill);
            totalFilled += filledAmount;
            resource.amount -= filledAmount;
            if (!allowSameFluidFill || resource.amount == 0)
                return totalFilled;
        }
    }
    return totalFilled;
}
Also used : IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 7 with IFluidTank

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

the class MetaTileEntityLargeBoiler method setupRecipeAndConsumeInputs.

private int setupRecipeAndConsumeInputs() {
    for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
        FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
        if (fuelStack == null || ModHandler.isWater(fuelStack))
            // ignore empty tanks and water
            continue;
        FuelRecipe dieselRecipe = RecipeMaps.DIESEL_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
        if (dieselRecipe != null) {
            int fuelAmountToConsume = (int) Math.ceil(dieselRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
            if (fuelStack.amount >= fuelAmountToConsume) {
                fluidTank.drain(fuelAmountToConsume, true);
                long recipeVoltage = FuelRecipeLogic.getTieredVoltage(dieselRecipe.getMinVoltage());
                int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
                return (int) Math.ceil(dieselRecipe.getDuration() * CONSUMPTION_MULTIPLIER / 2.0 * voltageMultiplier * getThrottleMultiplier());
            } else
                continue;
        }
        FuelRecipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
        if (denseFuelRecipe != null) {
            int fuelAmountToConsume = (int) Math.ceil(denseFuelRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
            if (fuelStack.amount >= fuelAmountToConsume) {
                fluidTank.drain(fuelAmountToConsume, true);
                long recipeVoltage = FuelRecipeLogic.getTieredVoltage(denseFuelRecipe.getMinVoltage());
                int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
                return (int) Math.ceil(denseFuelRecipe.getDuration() * CONSUMPTION_MULTIPLIER * 2 * voltageMultiplier * getThrottleMultiplier());
            }
        }
    }
    for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
        ItemStack itemStack = itemImportInventory.getStackInSlot(slotIndex);
        int fuelBurnValue = (int) Math.ceil(TileEntityFurnace.getItemBurnTime(itemStack) / (50.0 * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier()));
        if (fuelBurnValue > 0) {
            if (itemStack.getCount() == 1) {
                ItemStack containerItem = itemStack.getItem().getContainerItem(itemStack);
                itemImportInventory.setStackInSlot(slotIndex, containerItem);
            } else {
                itemStack.shrink(1);
                itemImportInventory.setStackInSlot(slotIndex, itemStack);
            }
            return fuelBurnValue;
        }
    }
    return 0;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) FuelRecipe(gregtech.api.recipes.recipes.FuelRecipe) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 8 with IFluidTank

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

the class MetaTileEntityLargeBoiler method getFuels.

@Override
public Collection<IFuelInfo> getFuels() {
    if (!isStructureFormed())
        return Collections.emptySet();
    final LinkedHashMap<Object, IFuelInfo> fuels = new LinkedHashMap<Object, IFuelInfo>();
    // fluid capacity is all non water tanks
    int fluidCapacity = 0;
    for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
        FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
        if (!ModHandler.isWater(fuelStack))
            fluidCapacity += fluidTank.getCapacity();
    }
    for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
        FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
        if (fuelStack == null || ModHandler.isWater(fuelStack))
            continue;
        FuelRecipe dieselRecipe = RecipeMaps.DIESEL_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
        if (dieselRecipe != null) {
            long recipeVoltage = FuelRecipeLogic.getTieredVoltage(dieselRecipe.getMinVoltage());
            int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
            int burnTime = (int) Math.ceil(dieselRecipe.getDuration() * CONSUMPTION_MULTIPLIER / 2.0 * voltageMultiplier * getThrottleMultiplier());
            int fuelAmountToConsume = (int) Math.ceil(dieselRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
            final long fuelBurnTime = (fuelStack.amount * burnTime) / fuelAmountToConsume;
            FluidFuelInfo fluidFuelInfo = (FluidFuelInfo) fuels.get(fuelStack.getUnlocalizedName());
            if (fluidFuelInfo == null) {
                fluidFuelInfo = new FluidFuelInfo(fuelStack, fuelStack.amount, fluidCapacity, fuelAmountToConsume, fuelBurnTime);
                fuels.put(fuelStack.getUnlocalizedName(), fluidFuelInfo);
            } else {
                fluidFuelInfo.addFuelRemaining(fuelStack.amount);
                fluidFuelInfo.addFuelBurnTime(fuelBurnTime);
            }
        }
        FuelRecipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
        if (denseFuelRecipe != null) {
            long recipeVoltage = FuelRecipeLogic.getTieredVoltage(denseFuelRecipe.getMinVoltage());
            int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
            int burnTime = (int) Math.ceil(denseFuelRecipe.getDuration() * CONSUMPTION_MULTIPLIER * 2 * voltageMultiplier * getThrottleMultiplier());
            int fuelAmountToConsume = (int) Math.ceil(denseFuelRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
            final long fuelBurnTime = (fuelStack.amount * burnTime) / fuelAmountToConsume;
            FluidFuelInfo fluidFuelInfo = (FluidFuelInfo) fuels.get(fuelStack.getUnlocalizedName());
            if (fluidFuelInfo == null) {
                fluidFuelInfo = new FluidFuelInfo(fuelStack, fuelStack.amount, fluidCapacity, fuelAmountToConsume, fuelBurnTime);
                fuels.put(fuelStack.getUnlocalizedName(), fluidFuelInfo);
            } else {
                fluidFuelInfo.addFuelRemaining(fuelStack.amount);
                fluidFuelInfo.addFuelBurnTime(fuelBurnTime);
            }
        }
    }
    // item capacity is all slots
    int itemCapacity = 0;
    for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
        itemCapacity += itemImportInventory.getSlotLimit(slotIndex);
    }
    for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
        ItemStack itemStack = itemImportInventory.getStackInSlot(slotIndex);
        final long burnTime = (int) Math.ceil(TileEntityFurnace.getItemBurnTime(itemStack) / (50.0 * this.boilerType.fuelConsumptionMultiplier * getThrottleMultiplier()));
        if (burnTime > 0) {
            ItemFuelInfo itemFuelInfo = (ItemFuelInfo) fuels.get(itemStack.getTranslationKey());
            if (itemFuelInfo == null) {
                itemFuelInfo = new ItemFuelInfo(itemStack, itemStack.getCount(), itemCapacity, 1, itemStack.getCount() * burnTime);
                fuels.put(itemStack.getTranslationKey(), itemFuelInfo);
            } else {
                itemFuelInfo.addFuelRemaining(itemStack.getCount());
                itemFuelInfo.addFuelBurnTime(itemStack.getCount() * burnTime);
            }
        }
    }
    return fuels.values();
}
Also used : IFuelInfo(gregtech.api.capability.IFuelInfo) FluidFuelInfo(gregtech.api.capability.impl.FluidFuelInfo) FluidStack(net.minecraftforge.fluids.FluidStack) ItemFuelInfo(gregtech.api.capability.impl.ItemFuelInfo) FuelRecipe(gregtech.api.recipes.recipes.FuelRecipe) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Metalworks by canitzp.

the class TileBase method writeCapabilities.

private void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
    if (hasEnergyFluidInv().getRight()) {
        IItemHandler inventory = this.getInventory(side);
        if (inventory instanceof IItemHandlerModifiable) {
            nbt.setTag("Inventory", Objects.requireNonNull(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side)));
        }
    }
    if (hasEnergyFluidInv().getMiddle()) {
        IFluidHandler tank = getTank(side);
        if (tank instanceof IFluidTank) {
            nbt.setTag("FluidTank", Objects.requireNonNull(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side)));
        }
    }
    if (hasEnergyFluidInv().getLeft()) {
        IEnergyStorage energy = getEnergy(side);
        if (energy instanceof CustomEnergyStorage) {
            NBTTagCompound energyTag = new NBTTagCompound();
            energyTag.setInteger("Stored", energy.getEnergyStored());
            energyTag.setInteger("Capacity", energy.getMaxEnergyStored());
            energyTag.setInteger("MaxReceive", ((CustomEnergyStorage) energy).getReceiveTransfer());
            energyTag.setInteger("MaxExtract", ((CustomEnergyStorage) energy).getExtractTransfer());
            nbt.setTag("Energy", energyTag);
        }
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CustomEnergyStorage(de.canitzp.metalworks.CustomEnergyStorage) IItemHandler(net.minecraftforge.items.IItemHandler) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 10 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Solar by ArekkuusuJerii.

the class BlockBlastFurnacePipeGauge method onDrawScreenPost.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawScreenPost(RenderGameOverlayEvent.Post event) {
    Minecraft mc = Minecraft.getMinecraft();
    if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
        RayTraceResult ray = mc.objectMouseOver;
        if (ray != null) {
            BlockPos pos = ray.typeOfHit == RayTraceResult.Type.BLOCK ? ray.getBlockPos() : null;
            IBlockState state = pos != null ? mc.world.getBlockState(pos) : null;
            Block block = state == null ? null : state.getBlock();
            if (block == this) {
                EnumFacing facing = state.getValue(BlockDirectional.FACING);
                BlockPos offset = pos.offset(facing);
                TileEntity tile = mc.world.getTileEntity(offset);
                if (tile != null) {
                    IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
                    if (handler != null) {
                        int xc = event.getResolution().getScaledWidth() / 2;
                        int yc = event.getResolution().getScaledHeight() / 2;
                        int max = 0;
                        int amount = 0;
                        if (handler instanceof IFluidTank) {
                            max = ((IFluidTank) handler).getCapacity();
                            amount = ((IFluidTank) handler).getFluidAmount();
                        } else {
                            IFluidTankProperties tankProperty = handler.getTankProperties()[0];
                            max = tankProperty.getCapacity();
                            if (tankProperty.getContents() != null)
                                amount += tankProperty.getContents().amount;
                        }
                        String s = I18n.format("status.gauge");
                        String s1 = amount + "/" + max;
                        mc.fontRenderer.drawStringWithShadow(s, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 10, 0xFFFFFF);
                        mc.fontRenderer.drawStringWithShadow(s1, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 20, 0xFFFFFF);
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Minecraft(net.minecraft.client.Minecraft) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

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