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:
David Quintana authored and GitHub committed 2020-08-25 03:11:28 +02:00
1 parent 625cd746ef
commit 600e68cace
16 files changed
+208 -20

No files matched your search

@@ -38,6 +38,7 @@ import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;
public class VanillaInventoryCodeHooks
{
@@ -210,7 +211,7 @@ public class VanillaInventoryCodeHooks
return stack;
}
private static LazyOptional<Pair<IItemHandler, Object>> getItemHandler(IHopper hopper, Direction hopperFacing)
private static Optional<Pair<IItemHandler, Object>> getItemHandler(IHopper hopper, Direction hopperFacing)
{
double x = hopper.getXPos() + (double) hopperFacing.getXOffset();
double y = hopper.getYPos() + (double) hopperFacing.getYOffset();
@@ -244,7 +245,7 @@ public class VanillaInventoryCodeHooks
return true;
}
public static LazyOptional<Pair<IItemHandler, Object>> getItemHandler(World worldIn, double x, double y, double z, final Direction side)
public static Optional<Pair<IItemHandler, Object>> getItemHandler(World worldIn, double x, double y, double z, final Direction side)
{
int i = MathHelper.floor(x);
int j = MathHelper.floor(y);
@@ -262,6 +263,6 @@ public class VanillaInventoryCodeHooks
}
}
return LazyOptional.empty();
return Optional.empty();
}
}