Class ResourceList

java.lang.Object
org.moddingx.libx.util.data.ResourceList
All Implemented Interfaces:
Predicate<net.minecraft.resources.Identifier>

public class ResourceList extends Object implements 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 the allow_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.
  • Field Details

    • ALLOW_LIST

      public static final ResourceList ALLOW_LIST
      A resource list that accepts every item given.
    • DENY_LIST

      public static final ResourceList 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

      public ResourceList(boolean allowList, Consumer<ResourceList.RuleBuilder> rules)
      Creates a new resource list.
      Parameters:
      allowList - Whether this is an allow list or a deny list
      rules - A consumer that gets a RuleBuilder and should build the rules.
    • ResourceList

      public ResourceList(JsonObject json)
      Reads a resource list from JSON.
  • Method Details

    • toJson

      public JsonObject toJson()
      Serializes this resource list to JSON.
    • isAllowList

      public boolean isAllowList()
      Gets whether this ResourceList is an allow list or a deny list.
    • getRules

      public List<ResourceList.RuleEntry> getRules()
      Gets a list of rule entries for this ResourceList.
    • test

      public boolean test(net.minecraft.resources.Identifier id)
      Tests whether the given Identifier is on this resource list.
      Specified by:
      test in interface Predicate<net.minecraft.resources.Identifier>