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 the allowList 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.
  • Field Details

    • ALLOW_LIST

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

      public static final ResourceList DENY_LIST
      A resource list that denies every item.
  • 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.
    • ResourceList

      public ResourceList(net.minecraft.network.FriendlyByteBuf buffer)
      Reads a resource list from a FriendlyByteBuf.
  • Method Details

    • toJson

      public JsonObject toJson()
      Serialises this resource list to JSON.
    • toNetwork

      public void toNetwork(net.minecraft.network.FriendlyByteBuf buffer)
      Writes this resource list to a FriendlyByteBuf.
    • 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.ResourceLocation rl)
      Tests whether the given ResourceLocation is on this resource list.
      Specified by:
      test in interface Predicate<net.minecraft.resources.ResourceLocation>