mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Clarify in the LazyOptional which methods carry the lazyness over to the returned value and which don't. (#6750)
For consistency, this meant making a few changes: - Renamed the existing lazy mapping method to lazyMap, to indicate that it doesn't run the mapping immediately. - Added a new implementation of map(), which returns Optional<T>, and resolves the value in the process. - Changed filter() to return Optional, since there's no way to filter lazily. - Added a new method resolve(), which helps convert the custom LazyOptional class into a standard Optional, for use with library methods that expect Optional<T>. * Update License headers.
This commit is contained in:
1 parent
625cd746ef
commit
600e68cace
16 files changed
+208
-20
No files matched your search
@@ -48,6 +48,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class FluidUtil
|
||||
{
|
||||
private FluidUtil()
|
||||
@@ -428,7 +430,7 @@ public class FluidUtil
|
||||
/**
|
||||
* Helper method to get the fluid contained in an itemStack
|
||||
*/
|
||||
public static LazyOptional<FluidStack> getFluidContained(@Nonnull ItemStack container)
|
||||
public static Optional<FluidStack> getFluidContained(@Nonnull ItemStack container)
|
||||
{
|
||||
if (!container.isEmpty())
|
||||
{
|
||||
@@ -436,7 +438,7 @@ public class FluidUtil
|
||||
return getFluidHandler(container)
|
||||
.map(handler -> handler.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.SIMULATE));
|
||||
}
|
||||
return LazyOptional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user