Search in sources :

Example 6 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.

the class TileEntityFluidPipe method getAvailableConnectionByte.

public byte getAvailableConnectionByte() {
    byte connections = 0;
    IFluidTankProperties[] tankInfo;
    for (int i = 5; i >= 0; i--) {
        //			TileEntity con = worldObj.getTileEntity(xCoord+(i==4?-1: i==5?1: 0),yCoord+(i==0?-1: i==1?1: 0),zCoord+(i==2?-1: i==3?1: 0));
        EnumFacing dir = EnumFacing.getFront(i);
        TileEntity con = worldObj.getTileEntity(getPos().offset(dir));
        connections <<= 1;
        if (con != null && con.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite())) {
            IFluidHandler handler = con.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite());
            tankInfo = handler.getTankProperties();
            if (tankInfo != null && tankInfo.length > 0)
                connections |= 1;
        }
    }
    return connections;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 7 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.

the class TileEntityFluidPipe method getConnectionByte.

public byte getConnectionByte() {
    byte connections = 0;
    IFluidTankProperties[] tankInfo;
    for (int i = 5; i >= 0; i--) {
        //			TileEntity con = worldObj.getTileEntity(xCoord+(i==4?-1: i==5?1: 0),yCoord+(i==0?-1: i==1?1: 0),zCoord+(i==2?-1: i==3?1: 0));
        EnumFacing dir = EnumFacing.getFront(i);
        TileEntity con = worldObj.getTileEntity(getPos().offset(dir));
        connections <<= 1;
        if (sideConfig[i] == 0 && con != null && con.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite())) {
            IFluidHandler handler = con.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite());
            tankInfo = handler.getTankProperties();
            if (tankInfo != null && tankInfo.length > 0)
                connections |= 1;
        }
    }
    return connections;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 8 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.

the class ItemDrill method onBlockDestroyed.

@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase living) {
    if ((double) state.getBlockHardness(world, pos) != 0.0D) {
        int dmg = ForgeHooks.isToolEffective(world, pos, stack) ? 1 : 3;
        ItemStack head = getHead(stack);
        if (head != null) {
            if (living instanceof EntityPlayer) {
                if (((EntityPlayer) living).capabilities.isCreativeMode)
                    return true;
                ((IDrillHead) head.getItem()).afterBlockbreak(stack, head, (EntityPlayer) living);
            }
            ((IDrillHead) head.getItem()).damageHead(head, dmg);
            this.setHead(stack, head);
            IFluidHandler handler = FluidUtil.getFluidHandler(stack);
            handler.drain(1, true);
        }
    }
    return true;
}
Also used : IDrillHead(blusunrize.immersiveengineering.api.tool.IDrillHead) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 9 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project Railcraft by Railcraft.

the class TankManager method findNeighbors.

private Collection<IFluidHandler> findNeighbors(AdjacentTileCache cache, Predicate<? super TileEntity> filter, EnumFacing[] sides) {
    List<IFluidHandler> targets = new ArrayList<>();
    for (EnumFacing side : sides) {
        TileEntity tile = cache.getTileOnSide(side);
        if (tile == null)
            continue;
        if (!TANK_FILTER.apply(tile, side.getOpposite()))
            continue;
        if (!filter.test(tile))
            continue;
        IFluidHandler tank = FluidTools.getFluidHandler(side.getOpposite(), tile);
        if (tank != null)
            targets.add(tank);
    }
    return targets;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 10 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project Railcraft by Railcraft.

the class DetectorTank method testCarts.

@Override
public int testCarts(List<EntityMinecart> carts) {
    for (EntityMinecart cart : carts) {
        IFluidHandler fluidHandler = FluidTools.getFluidHandler(null, cart);
        if (fluidHandler != null) {
            AdvancedFluidHandler tank = new AdvancedFluidHandler(fluidHandler);
            boolean liquidMatches = false;
            Fluid filterFluid = getFilterFluid();
            FluidStack tankLiquid = tank.drain(1, false);
            if (filterFluid == null)
                liquidMatches = true;
            else if (Fluids.areEqual(filterFluid, tankLiquid))
                liquidMatches = true;
            else if (tank.canPutFluid(new FluidStack(filterFluid, 1)))
                liquidMatches = true;
            boolean quantityMatches = false;
            ButtonState state = buttonController.getButtonState();
            switch(state) {
                case VOID:
                    quantityMatches = true;
                    break;
                case EMPTY:
                    if (filterFluid != null && tank.isTankEmpty(filterFluid))
                        quantityMatches = true;
                    else if (filterFluid == null && tank.areTanksEmpty())
                        quantityMatches = true;
                    break;
                case NOT_EMPTY:
                    if (filterFluid != null && tank.getFluidQty(filterFluid) > 0)
                        quantityMatches = true;
                    else if (filterFluid == null && tank.isFluidInTank())
                        quantityMatches = true;
                    break;
                case FULL:
                    if (filterFluid != null && tank.isTankFull(filterFluid))
                        quantityMatches = true;
                    else if (filterFluid == null && tank.areTanksFull())
                        quantityMatches = true;
                    break;
                default:
                    float level = filterFluid != null ? tank.getFluidLevel(filterFluid) : tank.getFluidLevel();
                    switch(state) {
                        case ANALOG:
                            return (int) (FULL_POWER * level);
                        case QUARTER:
                            quantityMatches = level >= 0.25f;
                            break;
                        case HALF:
                            quantityMatches = level >= 0.5f;
                            break;
                        case MOST:
                            quantityMatches = level >= 0.75f;
                            break;
                        case LESS_THAN_QUARTER:
                            quantityMatches = level < 0.25f;
                            break;
                        case LESS_THAN_HALF:
                            quantityMatches = level < 0.5f;
                            break;
                        case LESS_THAN_MOST:
                            quantityMatches = level < 0.75f;
                            break;
                        case LESS_THAN_FULL:
                            quantityMatches = level < 1f;
                            break;
                    }
            }
            return liquidMatches && quantityMatches ? FULL_POWER : NO_POWER;
        }
    }
    return NO_POWER;
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IMultiButtonState(mods.railcraft.common.gui.buttons.IMultiButtonState) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)28 FluidStack (net.minecraftforge.fluids.FluidStack)16 TileEntity (net.minecraft.tileentity.TileEntity)12 ItemStack (net.minecraft.item.ItemStack)11 EnumFacing (net.minecraft.util.EnumFacing)10 BlockPos (net.minecraft.util.math.BlockPos)7 IBlockState (net.minecraft.block.state.IBlockState)3 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 AdvancedFluidHandler (mods.railcraft.common.fluids.AdvancedFluidHandler)2 Block (net.minecraft.block.Block)2 BlockLiquid (net.minecraft.block.BlockLiquid)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Fluid (net.minecraftforge.fluids.Fluid)2 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)2 FermenterRecipe (blusunrize.immersiveengineering.api.crafting.FermenterRecipe)1 MixerRecipe (blusunrize.immersiveengineering.api.crafting.MixerRecipe)1 RefineryRecipe (blusunrize.immersiveengineering.api.crafting.RefineryRecipe)1 SqueezerRecipe (blusunrize.immersiveengineering.api.crafting.SqueezerRecipe)1