forked from FabricMC/fabric
Support loading a single resource condition instead of array (#3749)
* Support loading a single condition instead of array
* Remove extra space
* Use LIST_CODEC field instead of CODEC.listOf()
Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>
---------
Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>
(cherry picked from commit 83154f1bcb
)
This commit is contained in:
parent
1c4a86e83a
commit
690fe0d575
3 changed files with 9 additions and 10 deletions
fabric-resource-conditions-api-v1/src
main/java/net/fabricmc/fabric
testmod/resources/data/fabric-resource-conditions-api-v1-testmod/predicates
|
@ -38,6 +38,10 @@ public interface ResourceCondition {
|
|||
* A codec for a list of conditions.
|
||||
*/
|
||||
Codec<List<ResourceCondition>> LIST_CODEC = CODEC.listOf();
|
||||
/**
|
||||
* A codec for parsing load conditions. Can either be an array of conditions or a single condition.
|
||||
*/
|
||||
Codec<ResourceCondition> CONDITION_CODEC = Codec.withAlternative(CODEC, LIST_CODEC, conditions -> ResourceConditions.and(conditions.toArray(new ResourceCondition[0])));
|
||||
|
||||
/**
|
||||
* @return the type of the condition
|
||||
|
|
|
@ -65,10 +65,10 @@ public final class ResourceConditionsImpl implements ModInitializer {
|
|||
boolean debugLogEnabled = ResourceConditionsImpl.LOGGER.isDebugEnabled();
|
||||
|
||||
if (obj.has(ResourceConditions.CONDITIONS_KEY)) {
|
||||
DataResult<List<ResourceCondition>> conditions = ResourceCondition.LIST_CODEC.parse(JsonOps.INSTANCE, obj.get(ResourceConditions.CONDITIONS_KEY));
|
||||
DataResult<ResourceCondition> conditions = ResourceCondition.CONDITION_CODEC.parse(JsonOps.INSTANCE, obj.get(ResourceConditions.CONDITIONS_KEY));
|
||||
|
||||
if (conditions.isSuccess()) {
|
||||
boolean matched = ResourceConditionsImpl.conditionsMet(conditions.getOrThrow(), registryLookup, true);
|
||||
boolean matched = conditions.getOrThrow().test(registryLookup);
|
||||
|
||||
if (debugLogEnabled) {
|
||||
String verdict = matched ? "Allowed" : "Rejected";
|
||||
|
|
|
@ -4,12 +4,7 @@
|
|||
"predicate": {
|
||||
"type": "minecraft:pig"
|
||||
},
|
||||
"fabric:load_conditions": [
|
||||
{
|
||||
"condition": "fabric:all_mods_loaded",
|
||||
"values": [
|
||||
"fabric-resource-conditions-api-v1"
|
||||
]
|
||||
}
|
||||
]
|
||||
"fabric:load_conditions": {
|
||||
"condition": "fabric:true"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue