Skip to content

Developer Utilities

LlaGuiTo edited this page Sep 30, 2026 · 1 revision

Developer utilities

Applies to all versions. On 1.21.1 read ResourceLocation where signatures say Identifier.

A tour of the other helpers, by package (com.skd.commontoolkit.*). Read the Javadoc in the source for the details.

Networking

network.PayloadProvider<T> describes one custom payload: its type, stream codec, and handleClient / handleServer methods; optionally isOptional() and the handler thread. Register providers with PayloadHelper.registerPayload(provider) and let PayloadHelper handle RegisterPayloadHandlersEvent.

payloads.ButtonClickPayload sends a client-to-server "button pressed" with an integer id, handled by the open menu if it implements ButtonClickPayload.IButtonContainer (onButtonClick(int id)).

Registration

registry.DeferredHelper.create(modid) is a single entry point for deferred registration: block(...), item(...), blockItem(...), fluid(...), effect(...), sound(...), and registry(...) to create custom registries. It returns the usual DeferredBlock / DeferredItem / DeferredHolder.

Creative tabs

tabs.TabFillingRegistry adds items to existing creative tabs without writing an event handler: registerSimple(item, tabs...), register(tab, suppliers...), or register(filler, tabs...) for items that implement ITabFiller and want to add several stacks (for example one per variant).

Block entities

TickingBlockEntity lets a block entity hold its own serverTick(level, pos, state) / clientTick(...) methods; TickingBlockEntityType and TickingEntityBlock wire the tickers automatically.

Menus and screens

  • menu.CommonToolkitContainerMenu: base menu with a QuickMoveHandler to declare shift-click rules and addPlayerSlots(inventory, x, y).
  • menu.BlockEntityMenu + SimplerMenuProvider: menus bound to a block entity at a position.
  • Slots: FilteredSlot (only accepts items matching a filter), LockedSlot (no interaction).
  • SimpleDataSlots: lambda-based data slots for syncing integers to the screen.
  • screen.CommonToolkitContainerScreen, ScreenUtil, TickableTextList (text that appears character by character), util.DrawsOnLeft (tooltips drawn to the left of the screen).

Codecs and JSON

  • codec.CodecMap / MapBackedCodec: a registry of named codecs that is itself a codec (polymorphic data), CodecProvider for objects that know their codec, and CommonToolkitCodecs (enum codecs and other helpers).
  • json: OptionalStackCodec (item stacks that may be empty or optional), WeightedItemStack, RandomAttributeModifier (attribute modifiers with random values), ChancedEffectInstance (effects with a chance and random amplifier), JsonUtil, NBTAdapter.
  • util.RandomRange, StepFunction, LinearEquation, Offset (GUI anchors), CachedObject (objects decoded once from item data and cached).

Tasks, events and reloads

  • util.CommonToolkitTaskQueue.submitTask(id, task) / submitDelayedTask(id, delay, task): run tick-based tasks on the server; the queue is cleared when the server stops.
  • events.ResourceReloadEvent: fired when client or server resources reload (one listener for both sides).
  • events.AnvilLandEvent: fired when a falling anvil lands.
  • util.RunnableReloader: a reload listener from a lambda.

Data generation

  • datagen.DataGenBuilder: adds registry bootstraps and data providers to GatherDataEvent in one place.
  • datagen.LegacyRecipeProvider: recipe provider with a compact shaped/shapeless syntax.
  • datagen.FieldOrderingFactory + RegisterFieldOrderingsEvent: control the order of JSON fields in generated files.
  • util.data.RuntimeDatagenHelpers: write JSON files at runtime (used by /common_toolkit serialize_loot_table).

Other

  • cap.InternalItemHandler: item handler with internal insert/extract methods that bypass the public restrictions.
  • util.EnchantmentUtils, util.CommonToolkitUtil, color.GradientColor (gradient text colors).