forked from CleanroomMC/ModularUI
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,024 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/com/cleanroommc/modularui/utils/fluid/FluidInteractions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.cleanroommc.modularui.utils.fluid; | ||
|
||
import static com.cleanroommc.modularui.ModularUI.isGT5ULoaded; | ||
|
||
import codechicken.nei.recipe.StackInfo; | ||
import gregtech.api.util.GT_Utility; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fluids.FluidContainerRegistry; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.IFluidContainerItem; | ||
import net.minecraftforge.fluids.IFluidTank; | ||
|
||
public class FluidInteractions { | ||
/** | ||
* Gets fluid actually stored in item. Used for transferring fluid. | ||
*/ | ||
public static FluidStack getFluidForRealItem(ItemStack itemStack) { | ||
FluidStack fluidStack = null; | ||
if (isGT5ULoaded) { | ||
fluidStack = GT_Utility.getFluidForFilledItem(itemStack, true); | ||
} | ||
if (fluidStack == null && itemStack.getItem() instanceof IFluidContainerItem container) { | ||
fluidStack = container.getFluid(itemStack); | ||
} | ||
if (fluidStack == null) { | ||
fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStack); | ||
} | ||
if (fluidStack == null) { | ||
fluidStack = StackInfo.getFluid(itemStack); | ||
} | ||
return fluidStack; | ||
} | ||
|
||
/** | ||
* Gets fluid for use in phantom slot. | ||
*/ | ||
public static FluidStack getFluidForPhantomItem(ItemStack itemStack) { | ||
if (isGT5ULoaded) { | ||
return GT_Utility.getFluidFromContainerOrFluidDisplay(itemStack); | ||
} else { | ||
return StackInfo.getFluid(itemStack); | ||
} | ||
} | ||
|
||
public static ItemStack fillFluidContainer(FluidStack fluidStack, ItemStack itemStack) { | ||
ItemStack filledContainer = fillFluidContainerWithoutIFluidContainerItem(fluidStack, itemStack); | ||
if (filledContainer == null) { | ||
filledContainer = fillFluidContainerWithIFluidContainerItem(fluidStack, itemStack); | ||
} | ||
if (filledContainer == null) { | ||
filledContainer = FluidContainerRegistry.fillFluidContainer(fluidStack, itemStack); | ||
FluidStack newFluid = getFluidForRealItem(filledContainer); | ||
fluidStack.amount -= newFluid.amount; | ||
} | ||
return filledContainer; | ||
} | ||
|
||
public static ItemStack fillFluidContainerWithoutIFluidContainerItem(FluidStack fluidStack, ItemStack itemStack) { | ||
if (isGT5ULoaded) { | ||
return GT_Utility.fillFluidContainer(fluidStack, itemStack, true, false); | ||
} | ||
return null; | ||
} | ||
|
||
public static ItemStack fillFluidContainerWithIFluidContainerItem(FluidStack fluidStack, ItemStack itemStack) { | ||
if (itemStack.getItem() instanceof IFluidContainerItem) { | ||
IFluidContainerItem tContainerItem = (IFluidContainerItem) itemStack.getItem(); | ||
int tFilledAmount = tContainerItem.fill(itemStack, fluidStack, true); | ||
if (tFilledAmount > 0) { | ||
fluidStack.amount -= tFilledAmount; | ||
return itemStack; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static ItemStack getContainerForFilledItem(ItemStack itemStack) { | ||
ItemStack stack = getContainerForFilledItemWithoutIFluidContainerItem(itemStack); | ||
if (stack == null && itemStack.getItem() instanceof IFluidContainerItem container) { | ||
stack = itemStack.copy(); | ||
container.drain(stack, Integer.MAX_VALUE, true); | ||
} | ||
if (stack == null) { | ||
stack = FluidContainerRegistry.drainFluidContainer(itemStack.copy()); | ||
} | ||
return stack; | ||
} | ||
|
||
public static ItemStack getContainerForFilledItemWithoutIFluidContainerItem(ItemStack itemStack) { | ||
if (isGT5ULoaded) { | ||
return GT_Utility.getContainerForFilledItem(itemStack, false); | ||
} | ||
return null; | ||
} | ||
|
||
public static int getRealCapacity(IFluidTank fluidTank) { | ||
if (fluidTank instanceof IOverflowableTank) { | ||
return ((IOverflowableTank) fluidTank).getRealCapacity(); | ||
} | ||
return fluidTank.getCapacity(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.