Download RandomLib — Minecraft Mods — MetaMods
RandomLib

RandomLib

Active

Downloads

1

Last update

3 years ago
Client
Libraries
Technological

RandomLib - Library for Customizable Random Pools

RandomLib is a specialized library that was originally part of the One Block Plus mod but is now available as a standalone solution. The main purpose of this library is to provide developers with a convenient tool for creating configuration files that manage weighted random generation of elements in your mods.

Developer Documentation (Work in Progress)

To start working with RandomLib, you need to perform setup during the FMLCommonSetupEvent:

<T extends ExtraData> RandomLibUtils.setup(ResourceLocation registryKey, Supplier<T> extra, Consumer<Map<String, RandomPool<T>>> afterDeserialization)

For example, if you set registryKey as oneblock:phases, your configuration files will be created in the configs/oneblock/phases/ folder.

The extra parameter is a supplier of an instance of ExtraData implementation, which allows you to save additional information about a random pool besides weighted elements.

After deserialization, configuration files are saved in a map with the file name as the key, but you can use the afterDeserialization consumer to store data in a structure more convenient for your mod.

To register commands for managing configuration files, use during the FMLServerStartingEvent:

RandomLibUtils.registerCommand(FMLServerStartingEvent event, String commandname, ResourceLocation registryKey)
RandomLibUtils.registerCommand(FMLServerStartingEvent event, String commandname, ResourceLocation registryKey, ExtraDataCommand<? extends ExtraData> extraDataCommand)

The registryKey parameter should match what is used in RandomLibUtils.setup, and extraDataCommand completes brigadier for your ExtraData implementation.

Main methods for working with random pools:

  • RandomPool#getExtra() - getting deserialized ExtraData
  • RandomPool#getRandom()#generateAndReplace(ServerWorld, BlockPos) - destroying a block and generating an element from the random pool
  • RandomPool#getRandom()#generate(ServerWorld, BlockPos) - generating an element from the random pool
  • RandomPool#getRandom()#vgenerate(RandomContainer, ServerWorld, BlockPos, ItemStack) - generating an element for an object implementing RandomContainer

User Documentation (Work in Progress)

For command help, use: / help

Help example

Project members
NaturaSpell

NaturaSpell

Created: 25 Mar 2022

ID: 36520