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
Modifier and TypeClassDescriptionclass
A builder for rules.static final record
And entry that represents a rule in thisResourceList
. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ResourceList
A resource list that accepts every item.static final ResourceList
A resource list that denies every item. -
Constructor Summary
ConstructorDescriptionResourceList
(boolean allowList, Consumer<ResourceList.RuleBuilder> rules) Creates a new resource list.ResourceList
(JsonObject json) Reads a resource list from JSON.ResourceList
(net.minecraft.network.FriendlyByteBuf buffer) Reads a resource list from aFriendlyByteBuf
. -
Method Summary
Modifier and TypeMethodDescriptiongetRules()
Gets a list ofrule entries
for this ResourceList.boolean
Gets whether this ResourceList is an allow list or a deny list.boolean
test
(net.minecraft.resources.ResourceLocation rl) Tests whether the givenResourceLocation
is on this resource list.toJson()
Serialises this resource list to JSON.void
toNetwork
(net.minecraft.network.FriendlyByteBuf buffer) Writes this resource list to aFriendlyByteBuf
.
-
Field Details
-
ALLOW_LIST
A resource list that accepts every item. -
DENY_LIST
A resource list that denies every item.
-
-
Constructor Details
-
ResourceList
Creates a new resource list.- Parameters:
allowList
- Whether this is an allow list or a deny listrules
- A consumer that gets aRuleBuilder
and should build the rules.
-
ResourceList
Reads a resource list from JSON. -
ResourceList
public ResourceList(net.minecraft.network.FriendlyByteBuf buffer) Reads a resource list from aFriendlyByteBuf
.
-
-
Method Details
-
toJson
Serialises this resource list to JSON. -
toNetwork
public void toNetwork(net.minecraft.network.FriendlyByteBuf buffer) Writes this resource list to aFriendlyByteBuf
. -
isAllowList
public boolean isAllowList()Gets whether this ResourceList is an allow list or a deny list. -
getRules
Gets a list ofrule entries
for this ResourceList. -
test
public boolean test(net.minecraft.resources.ResourceLocation rl) Tests whether the givenResourceLocation
is on this resource list.
-