Skip to content

Commit 59440bc

Browse files
committed
Fix conflicting resource conditions
Fixes #154 Fixes #129
1 parent ba60825 commit 59440bc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

fabric-recipe-api-v1/src/main/java/org/sinytra/fabric/recipe_api/FabricRecipeApiV1.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static MapCodec<Ingredient> makeIngredientMapCodec(MapCodec<Ingredient> o
3737
CustomIngredientImpl.CODEC,
3838
CustomIngredient::getSerializer,
3939
s -> s.getCodec(true),
40-
original
40+
original,
41+
"type" // NeoForge ingredient type spec
4142
)
4243
.xmap(
4344
e -> e.map(c -> new NeoCustomIngredientWrapper(c).toVanilla(), Function.identity()),
@@ -46,7 +47,7 @@ public static MapCodec<Ingredient> makeIngredientMapCodec(MapCodec<Ingredient> o
4647
}
4748

4849
// Stolen from NeoForgeExtraCodecs because they don't support custom type keys
49-
public static <A, E, B> MapCodec<Either<E, B>> dispatchMapOrElse(String typeKey, Codec<A> typeCodec, Function<? super E, ? extends A> type, Function<? super A, ? extends MapCodec<? extends E>> codec, MapCodec<B> fallbackCodec) {
50+
public static <A, E, B> MapCodec<Either<E, B>> dispatchMapOrElse(String typeKey, Codec<A> typeCodec, Function<? super E, ? extends A> type, Function<? super A, ? extends MapCodec<? extends E>> codec, MapCodec<B> fallbackCodec, String ignoreKey) {
5051
var dispatchCodec = typeCodec.dispatchMap(typeKey, type, codec);
5152
return new MapCodec<>() {
5253
@Override
@@ -56,7 +57,7 @@ public <T> Stream<T> keys(DynamicOps<T> ops) {
5657

5758
@Override
5859
public <T> DataResult<Either<E, B>> decode(DynamicOps<T> ops, MapLike<T> input) {
59-
if (input.get(typeKey) != null) {
60+
if (input.get(typeKey) != null && input.get(ignoreKey) == null) {
6061
return dispatchCodec.decode(ops, input).map(Either::left);
6162
} else {
6263
return fallbackCodec.decode(ops, input).map(Either::right);

fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.gson.JsonObject;
2727
import com.mojang.serialization.DataResult;
2828
import com.mojang.serialization.JsonOps;
29+
import net.neoforged.neoforge.common.conditions.ConditionalOps;
2930
import org.apache.commons.lang3.mutable.MutableBoolean;
3031
import org.jetbrains.annotations.Nullable;
3132
import org.slf4j.Logger;
@@ -62,7 +63,7 @@ public void onInitialize() {
6263
public static boolean applyResourceConditions(JsonObject obj, String dataType, ResourceLocation key, @Nullable HolderLookup.Provider registryLookup) {
6364
boolean debugLogEnabled = ResourceConditionsImpl.LOGGER.isDebugEnabled();
6465

65-
if (obj.has(ResourceConditions.CONDITIONS_KEY)) {
66+
if (obj.has(ResourceConditions.CONDITIONS_KEY) && !obj.has(ConditionalOps.DEFAULT_CONDITIONS_KEY)) {
6667
DataResult<ResourceCondition> conditions = ResourceCondition.CONDITION_CODEC.parse(JsonOps.INSTANCE, obj.get(ResourceConditions.CONDITIONS_KEY));
6768

6869
if (conditions.isSuccess()) {

0 commit comments

Comments
 (0)