Class ResourceList
java.lang.Object
org.moddingx.libx.util.data.ResourceList
- All Implemented Interfaces:
Predicate<net.minecraft.resources.Identifier>
A
Predicate for identifiers implemented as
a list of rules that will be applied one after another. The first rule that matches
a identifier determines the result.
The resource list can either be a white list or a black list. If it is an allow list,
by default a matching rule will make the test function
return true. If it's a deny list it'll return false by default for matching rules.
For allow lists if no rule matches false is returned. For deny lists it's
true.
Rules on an allow list can also make the test method false and the other
way round.
The order of the rules is important. Rules that are added first will have a higher
priority and only the first matching rule will be applied.
Resource lists are immutable.
ResourceLists in LibX configs
This explains, how a resource list is used in a config. In theallow_list field you can specify
whether all entries will be accepted by default or rejected.
elements is an array of rules. Each identifier that is matched against this list, will
traverse these rules from top to bottom. The first rule that matches a identifier determines its result.
Rules are identifiers, where asterisks (*) can be added to match any number of characters.
However, an asterisk can not match a colon. The only exception to this is the single asterisk which matches
everything. When a rule is matched, it will yield the result specified in allow_list as a result. To alter
this, add a plus (+) or a minus (-) in front of the rule. This will make it a allow or deny rule
respectively. You can also add regex rules. These are json objects with two keys: allow - a boolean that
specifies whether this is an allow or a deny rule and regex - which is a regex that must match the
identifier.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA builder for rules.static final recordAn entry that represents a rule in thisResourceList. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceListA resource list that accepts every item given.static final ResourceListA resource list that denies every item given.static final net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.FriendlyByteBuf, ResourceList> -
Constructor Summary
ConstructorsConstructorDescriptionResourceList(boolean allowList, Consumer<ResourceList.RuleBuilder> rules) Creates a new resource list.ResourceList(JsonObject json) Reads a resource list from JSON. -
Method Summary
Modifier and TypeMethodDescriptiongetRules()Gets a list ofrule entriesfor this ResourceList.booleanGets whether this ResourceList is an allow list or a deny list.booleantest(net.minecraft.resources.Identifier id) Tests whether the givenIdentifieris on this resource list.toJson()Serializes this resource list to JSON.
-
Field Details
-
ALLOW_LIST
A resource list that accepts every item given. -
DENY_LIST
A resource list that denies every item given. -
STREAM_CODEC
public static final net.minecraft.network.codec.StreamCodec<? super net.minecraft.network.FriendlyByteBuf, ResourceList> STREAM_CODEC
-
-
Constructor Details
-
ResourceList
Creates a new resource list.- Parameters:
allowList- Whether this is an allow list or a deny listrules- A consumer that gets aRuleBuilderand should build the rules.
-
ResourceList
Reads a resource list from JSON.
-
-
Method Details
-
toJson
Serializes this resource list to JSON. -
isAllowList
public boolean isAllowList()Gets whether this ResourceList is an allow list or a deny list. -
getRules
Gets a list ofrule entriesfor this ResourceList. -
test
-