Skip to content

Commit

Permalink
feat: make tag matcher log error instead of throwing exception if tag…
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Aug 1, 2023
1 parent 98fc47d commit 06908e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.level.BlockGetter;
Expand Down Expand Up @@ -79,7 +80,8 @@ public static TagMatcher fromJson(JsonObject json) {
var parserResult = BlockStateParser.parseForTesting(Registry.BLOCK, new StringReader(finalTagString), true).right().orElseThrow();
return parserResult.tag().unwrap().left().orElseThrow();
} catch (CommandSyntaxException e) {
throw new IllegalArgumentException("Failed to parse Tag and BlockState properties from json member \"tag\" for TagMatcher.", e);
Modonomicon.LOGGER.error("Failed to parse Tag and BlockState properties from json member \"tag\" for TagMatcher: {0}. Will use \"modonomicon:bedrock\" as fallback, Exception: {1}", finalTagString, e);
return TagKey.create(Registry.BLOCK_REGISTRY, Modonomicon.loc("bedrock"));
}
});

Expand All @@ -88,7 +90,8 @@ public static TagMatcher fromJson(JsonObject json) {
var parserResult = BlockStateParser.parseForTesting(Registry.BLOCK, new StringReader(finalTagString), true).right().orElseThrow();
return parserResult.vagueProperties();
} catch (CommandSyntaxException e) {
throw new IllegalArgumentException("Failed to parse Tag and BlockState properties from json member \"tag\" for TagMatcher.", e);
Modonomicon.LOGGER.error("Failed to parse Tag and BlockState properties from json member \"tag\" for TagMatcher: {0}. Will use empty property map as fallback, Exception: {1}", finalTagString, e);
return Map.of();
}
});

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/data/modonomicon/tags/blocks/bedrock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:bedrock"
]
}

0 comments on commit 06908e9

Please sign in to comment.