diff --git a/src/main/java/slimeknights/mantle/data/loadable/Loadable.java b/src/main/java/slimeknights/mantle/data/loadable/Loadable.java index a59180c0..dd7f0441 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/Loadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/Loadable.java @@ -163,22 +163,22 @@ default Loadable> mapWithValues(int minSize, Function valueGe /* Mapping */ /** Maps this loader to another type, with error factory on both from and to */ - default Loadable map(BiFunction from, BiFunction to) { + default Loadable xmap(BiFunction from, BiFunction to) { return MappedLoadable.of(this, from, to); } /** Maps this loader to another type, with error factory on from */ default Loadable comapFlatMap(BiFunction from, Function to) { - return map(from, MappedLoadable.flatten(to)); + return xmap(from, MappedLoadable.flatten(to)); } /** Maps this loader to another type */ default Loadable flatComap(Function from, BiFunction to) { - return map(MappedLoadable.flatten(from), to); + return xmap(MappedLoadable.flatten(from), to); } /** Maps this loader to another type */ - default Loadable flatMap(Function from, Function to) { - return map(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); + default Loadable flatXmap(Function from, Function to) { + return xmap(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); } } diff --git a/src/main/java/slimeknights/mantle/data/loadable/Loadables.java b/src/main/java/slimeknights/mantle/data/loadable/Loadables.java index 1ecbc227..c8d267b8 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/Loadables.java +++ b/src/main/java/slimeknights/mantle/data/loadable/Loadables.java @@ -31,14 +31,14 @@ public class Loadables { private Loadables() {} /** Loadable for a resource location */ - public static final StringLoadable RESOURCE_LOCATION = StringLoadable.DEFAULT.map((s, e) -> { + public static final StringLoadable RESOURCE_LOCATION = StringLoadable.DEFAULT.xmap((s, e) -> { try { return new ResourceLocation(s); } catch (ResourceLocationException ex) { throw e.create(ex); } }, (r, e) -> r.toString()); - public static final StringLoadable TOOL_ACTION = StringLoadable.DEFAULT.flatMap(ToolAction::get, ToolAction::name); + public static final StringLoadable TOOL_ACTION = StringLoadable.DEFAULT.flatXmap(ToolAction::get, ToolAction::name); /* Registries */ public static final StringLoadable SOUND_EVENT = new RegistryLoadable<>(Registry.SOUND_EVENT); @@ -73,7 +73,7 @@ private Loadables() {} /** Creates a tag key loadable */ public static StringLoadable> tagKey(ResourceKey> registry) { - return RESOURCE_LOCATION.flatMap(key -> TagKey.create(registry, key), TagKey::location); + return RESOURCE_LOCATION.flatXmap(key -> TagKey.create(registry, key), TagKey::location); } /** Maps a loadable to a variant that disallows a particular value */ @@ -84,6 +84,6 @@ public static StringLoadable notValue(StringLoadable loadable, T notVa } return value; }; - return loadable.map(mapper, mapper); + return loadable.xmap(mapper, mapper); } } diff --git a/src/main/java/slimeknights/mantle/data/loadable/common/FluidStackLoadable.java b/src/main/java/slimeknights/mantle/data/loadable/common/FluidStackLoadable.java index 9faa9012..f745f102 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/common/FluidStackLoadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/common/FluidStackLoadable.java @@ -81,7 +81,7 @@ public static Loadable fixedSize(int amount) { if (amount <= 0) { throw new IllegalArgumentException("Count must be positive, received " + amount); } - return Loadables.FLUID.flatMap(fluid -> makeStack(fluid, amount, null), FLUID_GETTER); + return Loadables.FLUID.flatXmap(fluid -> makeStack(fluid, amount, null), FLUID_GETTER); } /** Creates a loadable for a stack with a single item */ @@ -95,11 +95,11 @@ public static RecordLoadable fixedSizeNBT(int amount) { /** Creates a non-empty variant of the loadable */ public static Loadable notEmpty(Loadable loadable) { - return loadable.map(NOT_EMPTY, NOT_EMPTY); + return loadable.xmap(NOT_EMPTY, NOT_EMPTY); } /** Creates a non-empty variant of the loadable */ public static RecordLoadable notEmpty(RecordLoadable loadable) { - return loadable.map(NOT_EMPTY, NOT_EMPTY); + return loadable.xmap(NOT_EMPTY, NOT_EMPTY); } } diff --git a/src/main/java/slimeknights/mantle/data/loadable/common/ItemStackLoadable.java b/src/main/java/slimeknights/mantle/data/loadable/common/ItemStackLoadable.java index 3e207c01..d75cb06c 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/common/ItemStackLoadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/common/ItemStackLoadable.java @@ -47,7 +47,7 @@ private ItemStackLoadable() {} /* Optional */ /** Single item which may be empty with a count of 1 */ - public static final Loadable OPTIONAL_ITEM = Loadables.ITEM.flatMap(item -> makeStack(item, 1, null), ITEM_GETTER); + public static final Loadable OPTIONAL_ITEM = Loadables.ITEM.flatXmap(item -> makeStack(item, 1, null), ITEM_GETTER); /** Loadable for a stack that may be empty with variable count */ public static final RecordLoadable OPTIONAL_STACK = RecordLoadable.create(ITEM, COUNT, (item, count) -> makeStack(item, count, null)) .compact(OPTIONAL_ITEM, stack -> stack.getCount() == 1); @@ -83,12 +83,12 @@ private static ItemStack makeStack(Item item, int count, @Nullable CompoundTag n /** Creates a non-empty variant of the loadable */ public static Loadable notEmpty(Loadable loadable) { - return loadable.map(NOT_EMPTY, NOT_EMPTY); + return loadable.xmap(NOT_EMPTY, NOT_EMPTY); } /** Creates a non-empty variant of the loadable */ public static RecordLoadable notEmpty(RecordLoadable loadable) { - return loadable.map(NOT_EMPTY, NOT_EMPTY); + return loadable.xmap(NOT_EMPTY, NOT_EMPTY); } /** Loadable for an item stack with NBT, requires special logic due to forges share tags */ diff --git a/src/main/java/slimeknights/mantle/data/loadable/mapping/AnyCollectionLoadable.java b/src/main/java/slimeknights/mantle/data/loadable/mapping/AnyCollectionLoadable.java index e0b96eca..d040fa24 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/mapping/AnyCollectionLoadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/mapping/AnyCollectionLoadable.java @@ -41,11 +41,11 @@ protected Collection build(Builder builder) { /** Creates a map from this collection using the given getter to find keys for the map */ public Loadable> mapWithKeys(Function keyGetter) { - return flatMap(collection -> collection.stream().collect(Collectors.toUnmodifiableMap(keyGetter, Function.identity())), Map::values); + return flatXmap(collection -> collection.stream().collect(Collectors.toUnmodifiableMap(keyGetter, Function.identity())), Map::values); } /** Creates a map from this collection using the given getter to find values for the map */ public Loadable> mapWithValues(Function valueGetter) { - return flatMap(collection -> collection.stream().collect(Collectors.toUnmodifiableMap(Function.identity(), valueGetter)), Map::keySet); + return flatXmap(collection -> collection.stream().collect(Collectors.toUnmodifiableMap(Function.identity(), valueGetter)), Map::keySet); } } diff --git a/src/main/java/slimeknights/mantle/data/loadable/primitive/StringLoadable.java b/src/main/java/slimeknights/mantle/data/loadable/primitive/StringLoadable.java index bbfd2585..ff50cfcc 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/primitive/StringLoadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/primitive/StringLoadable.java @@ -77,22 +77,22 @@ default Loadable> mapWithValues(Loadable valueLoadable) { } @Override - default StringLoadable map(BiFunction from, BiFunction to) { + default StringLoadable xmap(BiFunction from, BiFunction to) { return MappedLoadable.of(this, from, to); } @Override default StringLoadable comapFlatMap(BiFunction from, Function to) { - return map(from, MappedLoadable.flatten(to)); + return xmap(from, MappedLoadable.flatten(to)); } @Override default StringLoadable flatComap(Function from, BiFunction to) { - return map(MappedLoadable.flatten(from), to); + return xmap(MappedLoadable.flatten(from), to); } @Override - default StringLoadable flatMap(Function from, Function to) { - return map(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); + default StringLoadable flatXmap(Function from, Function to) { + return xmap(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); } } diff --git a/src/main/java/slimeknights/mantle/data/loadable/record/RecordLoadable.java b/src/main/java/slimeknights/mantle/data/loadable/record/RecordLoadable.java index 4c195530..72eb2aba 100644 --- a/src/main/java/slimeknights/mantle/data/loadable/record/RecordLoadable.java +++ b/src/main/java/slimeknights/mantle/data/loadable/record/RecordLoadable.java @@ -109,23 +109,23 @@ default RecordLoadable compact(Loadable compact, Predicate condition) { /* Mapping - switches to the record version of the methods */ @Override - default RecordLoadable map(BiFunction from, BiFunction to) { + default RecordLoadable xmap(BiFunction from, BiFunction to) { return MappedLoadable.of(this, from, to); } @Override default RecordLoadable comapFlatMap(BiFunction from, Function to) { - return map(from, MappedLoadable.flatten(to)); + return xmap(from, MappedLoadable.flatten(to)); } @Override default RecordLoadable flatComap(Function from, BiFunction to) { - return map(MappedLoadable.flatten(from), to); + return xmap(MappedLoadable.flatten(from), to); } @Override - default RecordLoadable flatMap(Function from, Function to) { - return map(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); + default RecordLoadable flatXmap(Function from, Function to) { + return xmap(MappedLoadable.flatten(from), MappedLoadable.flatten(to)); } diff --git a/src/main/java/slimeknights/mantle/recipe/ingredient/EntityIngredient.java b/src/main/java/slimeknights/mantle/recipe/ingredient/EntityIngredient.java index d303bd37..f142ef8b 100644 --- a/src/main/java/slimeknights/mantle/recipe/ingredient/EntityIngredient.java +++ b/src/main/java/slimeknights/mantle/recipe/ingredient/EntityIngredient.java @@ -38,7 +38,7 @@ private static EitherLoadable.TypedBuilder loadableBuilder() { /** Loadable for a tag match */ private static final RecordLoadable TAG_MATCH = RecordLoadable.create(Loadables.ENTITY_TYPE_TAG.requiredField("tag", t -> t.tag), TagMatch::new); /** Loadable disallows nested lists, just handles nested tags and sets */ - private static final Loadable COMPOUND = EntityIngredient.loadableBuilder().build(SET_MATCH).list(2).flatMap(Compound::new, c -> c.ingredients); + private static final Loadable COMPOUND = EntityIngredient.loadableBuilder().build(SET_MATCH).list(2).flatXmap(Compound::new, c -> c.ingredients); /** Loadable for any fluid ingredient */ public static final Loadable LOADABLE = loadableBuilder().array(COMPOUND).build(SET_MATCH); diff --git a/src/main/java/slimeknights/mantle/recipe/ingredient/FluidIngredient.java b/src/main/java/slimeknights/mantle/recipe/ingredient/FluidIngredient.java index 05ae6c65..0f6e0377 100644 --- a/src/main/java/slimeknights/mantle/recipe/ingredient/FluidIngredient.java +++ b/src/main/java/slimeknights/mantle/recipe/ingredient/FluidIngredient.java @@ -40,13 +40,13 @@ private static EitherLoadable.TypedBuilder loadableBuilder() { return EitherLoadable.typed().key("fluid", FLUID_MATCH).key("tag", TAG_MATCH); } /** Loadable for network writing of fluids */ - private static final Loadable NETWORK = FluidStackLoadable.REQUIRED_STACK.list(0).flatMap(fluids -> FluidIngredient.of(fluids.stream().map(FluidIngredient::of).toList()), FluidIngredient::getFluids); + private static final Loadable NETWORK = FluidStackLoadable.REQUIRED_STACK.list(0).flatXmap(fluids -> FluidIngredient.of(fluids.stream().map(FluidIngredient::of).toList()), FluidIngredient::getFluids); /** Loadable for fluid matches */ private static final RecordLoadable FLUID_MATCH = RecordLoadable.create(Loadables.FLUID.requiredField("fluid", i -> i.fluid), IntLoadable.FROM_ONE.requiredField("amount", i -> i.amount), FluidIngredient::of); /** Loadable for tag matches */ private static final RecordLoadable TAG_MATCH = RecordLoadable.create(Loadables.FLUID_TAG.requiredField("tag", i -> i.tag), IntLoadable.FROM_ONE.requiredField("amount", i -> i.amount), FluidIngredient::of); /** Loadable for tag matches */ - private static final Loadable COMPOUND = loadableBuilder().build(NETWORK).list(2).flatMap(Compound::new, c -> c.ingredients); + private static final Loadable COMPOUND = loadableBuilder().build(NETWORK).list(2).flatXmap(Compound::new, c -> c.ingredients); /** Loadable for any fluid ingredient */ public static final Loadable LOADABLE = loadableBuilder().array(COMPOUND).build(NETWORK);