diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-05-03 00:46:10 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-05-03 00:46:10 +0800 |
| commit | fc2d4973c401ed54438f3e13fa2a95d378b3e277 (patch) | |
| tree | dace841ec4d470325e11dff9df1769eba14b1cd8 /forge/src | |
| parent | 01472327420c131b759d0b3db4fb59623bf95e3f (diff) | |
| download | RoughlyEnoughItems-fc2d4973c401ed54438f3e13fa2a95d378b3e277.tar.gz RoughlyEnoughItems-fc2d4973c401ed54438f3e13fa2a95d378b3e277.tar.bz2 RoughlyEnoughItems-fc2d4973c401ed54438f3e13fa2a95d378b3e277.zip | |
Adds support for forge fluid handler
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'forge/src')
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java b/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java new file mode 100644 index 000000000..7d44dd528 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java @@ -0,0 +1,58 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.common.forge; + +import com.google.common.base.Predicates; +import me.shedaniel.architectury.hooks.forge.FluidStackHooksForge; +import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; + +import java.util.stream.IntStream; + +public class DefaultPluginImpl { + public static void registerForgeFluidSupport(FluidSupportProvider support) { + support.register(stack -> { + ItemStack itemStack = stack.getValue(); + LazyOptional<IFluidHandlerItem> handlerOptional = FluidUtil.getFluidHandler(itemStack); + if (handlerOptional.isPresent()) { + IFluidHandlerItem handler = handlerOptional.orElse(null); + if (handler.getTanks() > 0) { + return InteractionResultHolder.success(IntStream.range(0, handler.getTanks()) + .mapToObj(handler::getFluidInTank) + .filter(Predicates.not(FluidStack::isEmpty)) + .map(FluidStackHooksForge::fromForge) + .map(EntryStacks::of)); + } + } + + return InteractionResultHolder.pass(null); + }); + } +} |
