Package org.moddingx.libx.util.data
Class ResourceList
java.lang.Object
org.moddingx.libx.util.data.ResourceList
- All Implemented Interfaces:
Predicate<net.minecraft.resources.ResourceLocation>
public class ResourceList
extends Object
implements Predicate<net.minecraft.resources.ResourceLocation>
A
Predicate for resource locations implemented as
a list of rules that will be applied one after another. The first rule that matches
a resource location 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 inj a config. In theallowList field you can specify
whether all entries will be accepted by default or rejected.
elements is an array of rules. Each resource location that is matched against this list, will
traverse these rules from top to bottom. The first rule that matches a resource location determines its result.
Rules are resource locations, where asterisks (*) can be added to match any number of characters.
However, an asterisk can not match a colon. The nly exception to this is the single asterisk which matches
everything. When a rule is matched, it will yield the result specified in `allowList` 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
resource location.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA builder for rules.static final recordAnd entry that represents a rule in thisResourceList. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceListA resource list that accepts every item.static final ResourceListA resource list that denies every item.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.ResourceLocation rl) Tests whether the givenResourceLocationis on this resource list.toJson()Serialises this resource list to JSON.
-
Field Details
-
ALLOW_LIST
A resource list that accepts every item. -
DENY_LIST
A resource list that denies every item. -
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
Serialises 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
public boolean test(net.minecraft.resources.ResourceLocation rl) Tests whether the givenResourceLocationis on this resource list.
-