codebook icon indicating copy to clipboard operation
codebook copied to clipboard

Registry-related get methods

Open Machine-Maker opened this issue 2 years ago • 0 comments

A lot of the methods on Registry, HolderGetter, HolderLookup, RegistryAccess take ResourceKey as the sole parameter returning something. A lot of the time, those ResourceKey arguments are obtained from static final fields somewhere which makes choosing the name for the local var very easy.

Something like

Holder<Structure> structure1 = registry.getHolder(BuiltinStructures.NETHER_FOSSIL);

can be changed to

Holder<Structure> netherForsilStructure = registry.getHolder(BuiltinStructures.NETHER_FOSSIL);

This is similar to #10 and how the various is and has methods are handled, by looking at the field used in the parameter.

A non-exhaustive list of methods that this could apply to are:

TagKey

  • TagKey#create(ResourceKey, ResourceLocation)

ResourceKey

  • ResourceKey#create(ResourceKey, ResourceLocation)

Registry

  • Registry#get(ResourceKey)
  • Registry#getHolder(ResourceKey)
  • Registry#getOptional(ResourceKey)
  • Registry#getOrThrow(ResourceKey)
  • Registry#containsKey(ResourceKey)
  • Registry#getHolder(ResourceKey)
  • Registry#getTag(TagKey)
  • Registry#getTagOrEmpty(TagKey)
  • Registry#getOrCreateTag(TagKey)

RegistryAccess, RegistryAccess$Frozen, HolderLookup$Provider

  • RegistryAccess#lookup(ResourceKey)
  • RegistryAccess#lookupOrThrow(ResourceKey)
  • RegistryAccess#registry(ResourceKey)
  • RegistryAccess#registryOrThrow(ResourceKey)

HolderGetter, HolderLookup

  • HolderGetter#get(ResourceKey)
  • HolderGetter#getOrThrow(ResourceKey)
  • HolderGetter#get(TagKey)
  • HolderGetter#getOrThrow(TagKey)

BootstapContext

(yes there is a typo in Bootstap in the vanilla source)

  • Bootstap#register(ResourceKey, Object, Lifecycle)
  • Bootstap#register(ResourceKey, Object)
  • Bootstap#lookup(ResourceKey)

Machine-Maker avatar Jul 27 '23 03:07 Machine-Maker