net.minecraftforge.fluids.capability.CapabilityFluidHandler Java Examples

The following examples show how to use net.minecraftforge.fluids.capability.CapabilityFluidHandler. 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: BlockTFStorage.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {

        return true;

    } else {
        ItemStack stack = playerIn.getHeldItem(hand);
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof TileEntityTFStorage) {
            IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));

            if (handler != null) {
                FluidUtil.interactWithFluidHandler(playerIn, hand, tileentity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side));

                return true;
            } else {
                playerIn.openGui(TofuMain.instance, TofuGuiHandler.ID_STORAGE_MACHINE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
            }
        }
        return true;
    }
}
 
Example #2
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == 1) {
        ItemStack itemStack = gui.entityPlayer.inventory.getItemStack().copy();
        if (!itemStack.isEmpty()) {
            itemStack.setCount(1);
            IFluidHandlerItem fluidHandler = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            if (fluidHandler != null) {
                FluidStack resultFluid = fluidHandler.drain(Integer.MAX_VALUE, false);
                fluidStackUpdater.accept(resultFluid);
            }
        } else {
            fluidStackUpdater.accept(null);
        }
    } else if (id == 2) {
        FluidStack fluidStack;
        try {
            fluidStack = FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        fluidStackUpdater.accept(fluidStack);
    }
}
 
Example #3
Source File: MetaItem.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack stack) {
    if (stack.getItemDamage() >= metaItemOffset) {
        T item = getItem(stack);
        if (item == null) {
            return "invalid item";
        }
        String unlocalizedName = String.format("metaitem.%s.name", item.unlocalizedName);
        if (item.getNameProvider() != null) {
            return item.getNameProvider().getItemStackDisplayName(stack, unlocalizedName);
        }
        IFluidHandlerItem fluidHandlerItem = ItemHandlerHelper.copyStackWithSize(stack, 1)
            .getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
        if (fluidHandlerItem != null) {
            FluidStack fluidInside = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
            return I18n.format(unlocalizedName, fluidInside == null ? I18n.format("metaitem.fluid_cell.empty") : fluidInside.getLocalizedName());
        }
        return I18n.format(unlocalizedName);
    }
    return super.getItemStackDisplayName(stack);
}
 
Example #4
Source File: TileEntityEnderFurnace.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Uses one dose (1000 mB) of fluid fuel, returns the amount of burn time that was gained from it.
 * @param stack
 * @return burn time gained, in ticks
 */
private static int consumeFluidFuelDosage(ItemStack stack)
{
    if (itemContainsFluidFuel(stack) == false)
    {
        return 0;
    }

    // All the null checks happened already in itemContainsFluidFuel()
    IFluidHandler handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);

    // Consume max 1000 mB per use.
    FluidStack fluidStack = handler.drain(new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME), true);

    //System.out.printf("consumeFluidFuelDosageFluidCapability: %s - %d\n", (fluidStack != null ? fluidStack.getFluid().getName() : "null"), fluidStack != null ? fluidStack.amount : 0);
    // 1.5 times vanilla lava fuel value (150 items per bucket)
    return fluidStack != null ? (fluidStack.amount * 15 * COOKTIME_DEFAULT / 100) : 0;
}
 
Example #5
Source File: FillerTileEntity.java    From EmergingTechnology with MIT License 6 votes vote down vote up
private void fillAdjacent() {
    for (EnumFacing facing : EnumFacing.VALUES) {
        TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing));

        // Return if no tile entity or another filler
        if (neighbour == null || neighbour instanceof FillerTileEntity) {
            continue;
        }

        IFluidHandler neighbourFluidHandler = neighbour
                .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());

        // Return if neighbour has no fluid tank
        if (neighbourFluidHandler == null) {
            continue;
        }

        // Fill the neighbour
        neighbourFluidHandler.fill(new FluidStack(FluidRegistry.WATER,
                EmergingTechnologyConfig.HYDROPONICS_MODULE.FILLER.fillerFluidTransferRate), true);
    }
}
 
Example #6
Source File: FWTile.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> getCapability(Capability<T> capability, Direction direction) {
		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
//			return (Optional<T>) Optional.of(new FWFluidHandler(
//				block.components.getOp(FluidProvider.class, direction),
//				block.components.getOp(FluidConsumer.class, direction),
//				block.components.getOp(FluidHandler.class, direction),
//				Optional.of(block)
//					.filter(b -> b instanceof SidedTankProvider)
//					.map(b -> (SidedTankProvider) b), direction)).filter(FWFluidHandler::isPresent);
		} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return Optional.empty(); // TODO: implement
		}

		return Optional.empty();
	}
 
Example #7
Source File: FWEntity.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> getCapability(Capability<T> capability, Direction direction) {
		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
//			return (Optional<T>) Optional.of(new FWFluidHandler(
//				wrapped.components.getOp(FluidProvider.class),
//				wrapped.components.getOp(FluidConsumer.class),
//				wrapped.components.getOp(FluidHandler.class),
//				Optional.of(wrapped)
//					.filter(e -> e instanceof SidedTankProvider)
//					.map(e -> (SidedTankProvider) e), direction)).filter(FWFluidHandler::isPresent);
		} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return Optional.empty(); // TODO: implement
		}

		return Optional.empty();
	}
 
Example #8
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void pullFluidsFromNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        //use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly
        IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing);
        if (fluidHandler == null || myFluidHandler == null) {
            continue;
        }
        CoverPump.moveHandlerFluids(fluidHandler, myFluidHandler, Integer.MAX_VALUE, fluid -> true);
    }
    blockPos.release();
}
 
Example #9
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void pushFluidsIntoNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        //use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly
        IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing);
        if (fluidHandler == null || myFluidHandler == null) {
            continue;
        }
        CoverPump.moveHandlerFluids(myFluidHandler, fluidHandler, Integer.MAX_VALUE, fluid -> true);
    }
    blockPos.release();
}
 
Example #10
Source File: TileEntityFluidPipeTickable.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void pushFluidsFromTank(IPipeTile<FluidPipeType, FluidPipeProperties> pipeTile) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    int blockedConnections = pipeTile.getBlockedConnections();
    BlockFluidPipe blockFluidPipe = (BlockFluidPipe) pipeTile.getPipeBlock();
    for (EnumFacing side : EnumFacing.VALUES) {
        if ((blockedConnections & 1 << side.getIndex()) > 0) {
            continue; //do not dispatch energy to blocked sides
        }
        blockPos.setPos(pipeTile.getPipePos()).move(side);
        if (!pipeTile.getPipeWorld().isBlockLoaded(blockPos)) {
            continue; //do not allow cables to load chunks
        }
        TileEntity tileEntity = pipeTile.getPipeWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue; //do not emit into multiparts or other fluid pipes
        }
        IFluidHandler sourceHandler = pipeTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        IFluidHandler receiverHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite());
        if (sourceHandler != null && receiverHandler != null && blockFluidPipe.canPushIntoFluidHandler(pipeTile, tileEntity, sourceHandler, receiverHandler)) {
            CoverPump.moveHandlerFluids(sourceHandler, receiverHandler, Integer.MAX_VALUE, FLUID_FILTER_ALWAYS_TRUE);
        }
    }
    blockPos.release();
}
 
Example #11
Source File: TileEntitySoymilkAggregator.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
   @Override
   public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
       if (facing == null)
           return (T) handlerInput;

       switch (facing) {
           case WEST:
           case EAST:
           case NORTH:
           case SOUTH:
               return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(input);
           case DOWN:
               return (T) handlerOutput;
           default:
               return (T) handlerInput;
       }
   }
 
Example #12
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 #13
Source File: GlassBottleFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private IFluidHandlerItem getNextInChain() {
    if(rawCapabilityProviders != null) {
        boolean foundMyself = false;
        for(ICapabilityProvider provider : rawCapabilityProviders) {
            IFluidHandlerItem fluidHandlerItem = provider.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            if(fluidHandlerItem != null) {
                if(fluidHandlerItem == this) {
                    foundMyself = true;
                } else if(foundMyself) {
                    this.nextHandlerInChain = fluidHandlerItem;
                    break;
                }
            }
        }
        this.rawCapabilityProviders = null;
    }
    return nextHandlerInChain;
}
 
Example #14
Source File: ItemBlockFluidTank.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player,
		World world, BlockPos pos, EnumFacing side, float hitX, float hitY,
		float hitZ, IBlockState newState) {
	super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ,
			newState);
	
	TileEntity tile = world.getTileEntity(pos);
	
	if(tile != null && tile instanceof TileFluidTank) {
		IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
		ItemStack stack2 = stack.copy();
		stack2.setCount(1);
		handler.fill(drain(stack2, Integer.MAX_VALUE), true);
	}
	
	return true;
}
 
Example #15
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private FluidStack drainFrom(Object ingredient) {
    if (ingredient instanceof ItemStack) {
        ItemStack itemStack = (ItemStack) ingredient;
        IFluidHandlerItem fluidHandler = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
        if (fluidHandler != null)
            return fluidHandler.drain(Integer.MAX_VALUE, false);
    }
    return null;
}
 
Example #16
Source File: FWCapabilityProvider.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public boolean hasCapability(Capability<?> capability, Direction direction) {
		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
//			return
//				getComponent(FluidProvider.class, direction).isPresent() ||
//				getComponent(FluidConsumer.class, direction).isPresent() ||
//				getComponent(FluidHandler.class, direction).isPresent() ||
//				componentProvider instanceof SidedTankProvider;
		} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return false; // TODO: implement
		}

		return false;
	}
 
Example #17
Source File: MetaTileEntityCokeOvenHatch.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void update() {
    super.update();
    if (!getWorld().isRemote && getTimer() % 5 == 0L && isAttachedToMultiBlock()) {
        TileEntity tileEntity = getWorld().getTileEntity(getPos().offset(getFrontFacing()));
        IFluidHandler fluidHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getFrontFacing().getOpposite());
        if (fluidHandler != null) {
            CoverPump.moveHandlerFluids(fluidInventory, fluidHandler, Integer.MAX_VALUE, ALWAYS_TRUE);
        }
    }
}
 
Example #18
Source File: PlungerBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity == null) {
        return EnumActionResult.PASS;
    }
    IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
    if (fluidHandler == null) {
        return EnumActionResult.PASS;
    }
    ItemStack toolStack = player.getHeldItem(hand);
    boolean isShiftClick = player.isSneaking();
    IFluidHandler handlerToRemoveFrom = isShiftClick ?
        (fluidHandler instanceof FluidHandlerProxy ? ((FluidHandlerProxy) fluidHandler).input : null) :
        (fluidHandler instanceof FluidHandlerProxy ? ((FluidHandlerProxy) fluidHandler).output : fluidHandler);

    if (handlerToRemoveFrom != null && GTUtility.doDamageItem(toolStack, cost, false)) {
        if (!world.isRemote) {
            FluidStack drainStack = handlerToRemoveFrom.drain(1000, true);
            int amountOfFluid = drainStack == null ? 0 : drainStack.amount;
            if (amountOfFluid > 0) {
                player.playSound(SoundEvents.ENTITY_SLIME_SQUISH, 1.0f, amountOfFluid / 1000.0f);
            }
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
 
Example #19
Source File: FoamSprayerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public double getDurabilityForDisplay(ItemStack itemStack) {
    IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    IFluidTankProperties fluidTankProperties = fluidHandlerItem.getTankProperties()[0];
    FluidStack fluidStack = fluidTankProperties.getContents();
    return fluidStack == null ? 1.0 : (1.0 - fluidStack.amount / (fluidTankProperties.getCapacity() * 1.0));
}
 
Example #20
Source File: GlassBottleFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
    if(capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY) {
        return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this);
    }
    return null;
}
 
Example #21
Source File: GTHelperFluid.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Helper method to get an IFluidHandler for at tile position.
 *
 * Returns null if there is no valid fluid handler tile.
 */
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) {
	IBlockState state = world.getBlockState(blockPos);
	Block block = state.getBlock();
	if (block.hasTileEntity(state)) {
		TileEntity tileEntity = world.getTileEntity(blockPos);
		if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
			return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
		}
	}
	return null;
}
 
Example #22
Source File: FWEntity.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public boolean hasCapability(Capability<?> capability, Direction direction) {
		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
//			return
//				wrapped.components.has(FluidProvider.class) ||
//				wrapped.components.has(FluidConsumer.class) ||
//				wrapped.components.has(FluidHandler.class) ||
//				wrapped instanceof SidedTankProvider;
		} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return false; // TODO: implement
		}

		return false;
	}
 
Example #23
Source File: TileCrucible.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
	if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
	{
		itemHandler.setTe(this);
		return (T) itemHandler;
	}
	if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
		return (T) tank;

	return super.getCapability(capability, facing);
}
 
Example #24
Source File: TileBarrel.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
	if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
	{
		return (T) itemHandler;
	}
	if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
		return (T) tank;

	return super.getCapability(capability, facing);
}
 
Example #25
Source File: TileFloader.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
private boolean findTankAndFill() {
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (facing != EnumFacing.DOWN) {
            TileEntity te = world.getTileEntity(pos.offset(facing));
            if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) {
                IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
                // Simulate filling
                if (handler != null && handler.fill(new FluidStack(ModLiquids.fload, 100), true) != 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #26
Source File: FWTile.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public boolean hasCapability(Capability<?> capability, Direction direction) {
		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
//			return
//				block.components.has(FluidProvider.class, direction) ||
//				block.components.has(FluidConsumer.class, direction) ||
//				block.components.has(FluidHandler.class, direction) ||
//				block instanceof SidedTankProvider;
		} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return false; // TODO: implement
		}

		return false;
	}
 
Example #27
Source File: InjectorTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private void pushToFluidConsumers() {
    for (EnumFacing facing : EnumFacing.VALUES) {

        if (this.getNutrientFluid() < EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate) {
            return;
        }

        TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing));

        // Return if no tile entity
        if (neighbour == null) {
            continue;
        }

        IFluidHandler neighbourFluidHandler = neighbour
                .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());

        // Return if neighbour has no fluid tank
        if (neighbourFluidHandler == null) {
            continue;
        }

        // Fill the neighbour
        int filled = neighbourFluidHandler.fill(new FluidStack(ModFluids.NUTRIENT,
                EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate), true);

        this.nutrientFluidHandler.drain(filled, true);
    }
}
 
Example #28
Source File: AlgaeBioreactorTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
    if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
        return true;
    if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
        return true;
    if (capability == CapabilityEnergy.ENERGY)
        return true;

    return super.hasCapability(capability, facing);
}
 
Example #29
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos,
        EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    if (LinkMode.fromStack(stack) == LinkMode.ENABLED &&
        OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
    {
        return EnumActionResult.FAIL;
    }

    if (world.isRemote == false)
    {
        if (this.useBucketOnFluidBlock(world, player, stack) == EnumActionResult.SUCCESS)
        {
            return EnumActionResult.SUCCESS;
        }

        TileEntity te = world.getTileEntity(pos);

        if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
        {
            // If we are in bind mode, bind the bucket to the targeted tank and then return
            if (BucketMode.fromStack(stack) == BucketMode.BIND)
            {
                return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
            }

            return this.useBucketOnTank(world, pos, side, player, stack);
        }
    }

    return EnumActionResult.PASS;
}
 
Example #30
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
private void ejectLiquid() {
    IFluidHandler source = getStorage();
    for (Direction side : Direction.BY_INDEX) {
        IFluidHandler dest = capCache.getCapabilityOr(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side, EmptyFluidHandler.INSTANCE);
        FluidStack drain = source.drain(100, IFluidHandler.FluidAction.SIMULATE);
        if (!drain.isEmpty()) {
            int qty = dest.fill(drain, IFluidHandler.FluidAction.EXECUTE);
            if (qty > 0) {
                source.drain(qty, IFluidHandler.FluidAction.EXECUTE);
            }
        }
    }
}