Java Code Examples for net.minecraftforge.fluids.capability.IFluidHandler#getTankProperties()

The following examples show how to use net.minecraftforge.fluids.capability.IFluidHandler#getTankProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
    if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
        IFluidHandler fluidHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputFluidInventory : fluidInventory;
        if(fluidHandler.getTankProperties().length > 0) {
            return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(fluidHandler);
        }
        return null;
    } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
        IItemHandler itemHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputItemInventory : itemInventory;
        if(itemHandler.getSlots() > 0) {
            return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler);
        }
        return null;
    }
    return super.getCapability(capability, side);
}
 
Example 2
Source File: CoverPump.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static int moveHandlerFluids(IFluidHandler sourceHandler, IFluidHandler destHandler, int transferLimit, Predicate<FluidStack> fluidFilter) {
    int fluidLeftToTransfer = transferLimit;
    for (IFluidTankProperties tankProperties : sourceHandler.getTankProperties()) {
        FluidStack currentFluid = tankProperties.getContents();
        if (currentFluid == null || currentFluid.amount == 0 || !fluidFilter.test(currentFluid)) continue;
        currentFluid.amount = fluidLeftToTransfer;
        FluidStack fluidStack = sourceHandler.drain(currentFluid, false);
        if (fluidStack == null || fluidStack.amount == 0) continue;
        int canInsertAmount = destHandler.fill(fluidStack, false);
        if (canInsertAmount > 0) {
            fluidStack.amount = canInsertAmount;
            fluidStack = sourceHandler.drain(fluidStack, true);
            if (fluidStack != null && fluidStack.amount > 0) {
                destHandler.fill(fluidStack, true);

                fluidLeftToTransfer -= fluidStack.amount;
                if (fluidLeftToTransfer == 0) break;
            }
        }
    }
    return transferLimit - fluidLeftToTransfer;
}
 
Example 3
Source File: TileGenericPipe.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
public ArrayList<FluidStack> getFluidStacksInInventory(EnumFacing face){
	ArrayList<FluidStack> result = new ArrayList<FluidStack>();
	
	if (!hasInventoryOnSide(face.getIndex())) {
		return result;
	}
	TileEntity te = world.getTileEntity(getPos().offset(face));
	if (!te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite())) {
		return result;
	}
	IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite());
	for (IFluidTankProperties tank : fluidHandler.getTankProperties()) {
		if (!(tank.getContents() == null)) {
			result.add(tank.getContents());
		}
	}
	return result;
}
 
Example 4
Source File: GTTileDisplayScreen.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void collectFluidTankInformation() {
	IFluidHandler fluidTile = GTHelperFluid.getFluidHandler(world, this.targetPos, null);
	if (fluidTile != null) {
		IFluidTankProperties[] props = fluidTile.getTankProperties();
		for (int i = 0; i < props.length; ++i) {
			FluidStack fluid = props[i].getContents();
			if (fluid != null && fluid.amount > 0) {
				addInfoToScreen(fluid.amount + MB);
				addInfoToScreen(fluid.getLocalizedName());
			} else {
				addInfoToScreen(EMPTY_TANK);
			}
		}
	}
}
 
Example 5
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void cacheCapacity(ItemStack stack)
{
    if (LinkMode.fromStack(stack) == LinkMode.ENABLED)
    {
        ItemStack moduleStack = this.getSelectedModuleStack(stack, ModuleType.TYPE_LINKCRYSTAL);

        if (moduleStack.isEmpty() == false && moduleStack.getTagCompound() != null)
        {
            NBTTagCompound moduleNbt = moduleStack.getTagCompound();
            IFluidHandler handler = this.getLinkedTank(stack);

            if (handler != null)
            {
                IFluidTankProperties[] tank = handler.getTankProperties();

                if (tank != null && tank.length > 0 && tank[0] != null)
                {
                    moduleNbt.setInteger("CapacityCached", tank[0].getCapacity());
                }
                else
                {
                    moduleNbt.setInteger("CapacityCached", 0);
                }
            }
            else
            {
                moduleNbt.removeTag("CapacityCached");
            }

            moduleStack.setTagCompound(moduleNbt);
            this.setSelectedModuleStack(stack, ModuleType.TYPE_LINKCRYSTAL, moduleStack);
        }
    }
}
 
Example 6
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int getCapacityAvailable(ItemStack stack, FluidStack fluidStackIn, EntityPlayer player)
{
    FluidStack existingFluidStack;

    // Linked to a tank
    if (LinkMode.fromStack(stack) == LinkMode.ENABLED)
    {
        IFluidHandler handler = this.getLinkedTank(stack);

        if (handler != null)
        {
            IFluidTankProperties[] tank = handler.getTankProperties();

            if (tank == null || tank.length < 1 || tank[0] == null)
            {
                return 0;
            }

            existingFluidStack = tank[0].getContents();

            if (fluidStackIn == null)
            {
                return tank[0].getCapacity() - (existingFluidStack != null ? existingFluidStack.amount : 0);
            }
            else
            {
                fluidStackIn = fluidStackIn.copy();
                fluidStackIn.amount = Integer.MAX_VALUE;

                return handler.fill(fluidStackIn, false);
            }
        }

        return 0;
    }

    // Not linked to a tank, get the bucket's internal free capacity
    existingFluidStack = this.getFluid(stack, player);

    if (existingFluidStack != null)
    {
        return this.getCapacity(stack, player) - existingFluidStack.amount;
    }

    return this.getCapacity(stack, player);
}
 
Example 7
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int getCapacity(ItemStack stack, @Nullable EntityPlayer player)
{
    if (LinkMode.fromStack(stack) == LinkMode.DISABLED)
    {
        return Configs.enderBucketCapacity;
    }

    // Linked to a tank

    if (OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
    {
        return 0;
    }

    TargetData targetData = this.getLinkedTankTargetData(stack);
    IFluidHandler handler = this.getLinkedTank(stack);

    if (targetData != null && handler != null)
    {
        IFluidTankProperties[] tank = handler.getTankProperties();

        // If we have tank info, it is the easiest and simplest way to get the tank capacity
        if (tank != null && tank.length > 0 && tank[0] != null)
        {
            return tank[0].getCapacity();
        }

        // No tank info available, get the capacity via simulating filling

        FluidStack fluidStack = handler.drain(Integer.MAX_VALUE, false);

        // Tank has fluid
        if (fluidStack != null)
        {
            FluidStack fs = fluidStack.copy();
            fs.amount = Integer.MAX_VALUE;

            // Filled amount plus existing amount
            return handler.fill(fs, false) + fluidStack.amount;
        }
        // Tank has no fluid
        else
        {
            // Since we have no fluid stored, get the capacity via simulating filling water into the tank
            return handler.fill(new FluidStack(FluidRegistry.WATER, Integer.MAX_VALUE), false);
        }
    }

    return 0;
}