Skip to content

Utilities

Maksym Uimanov edited this page Jan 30, 2026 · 3 revisions

I'll examine the utilities directory to understand the available utility classes and create comprehensive documentation.

Utilities

The Temporal API provides a comprehensive set of utility classes that streamline common operations in Minecraft mod development. These utilities handle resource management, reflection, registry operations, and world generation tasks, reducing boilerplate code and providing consistent patterns across the framework.

Responsibilities / Purpose

The utility classes serve as foundational helpers for:

  • Resource location management - parsing and creating ResourceLocation objects
  • Registry operations - accessing and manipulating Minecraft registries
  • Reflection utilities - dynamic class inspection and method invocation
  • Tag management - creating and organizing tag keys
  • Map operations - specialized map manipulation methods
  • World generation - placement modifiers and feature registration
  • Enum extensions - supporting dynamic enum-like structures

How it works

Each utility class focuses on a specific domain and provides static methods for common operations. The utilities are designed to be stateless and thread-safe, using only their input parameters and returning new objects or primitives without maintaining internal state.

Core Architecture

  • ResourceUtils: Handles resource location parsing, creation, and mapping
  • RegistryUtils: Provides typed access to Minecraft registries
  • ReflectionUtils: Offers safe reflection operations with proper exception handling
  • TagUtils: Creates and manages tag keys for various registry types
  • MapUtils: Supplies specialized map manipulation methods
  • WorldGenerationUtils: Simplifies world generation feature setup
  • EnumExtensionUtils: Supports dynamic enum-like data structures

How to use / Configure

Resource Management

// Parse resource locations
ResourceLocation mclocation = ResourceUtils.parse("minecraft:example");
ResourceLocation modLocation = ResourceUtils.parse("yourmodid:example"); // or just "example" without mod id

// Create resource keys
ResourceKey<Item> itemKey = ResourceUtils.createKey(Registries.ITEM, "my_item");

Registry Operations

// Get registry objects
Block stoneBlock = RegistryUtils.getBlock("minecraft:stone");
Item diamondItem = RegistryUtils.getItem("minecraft:diamond");
SoundEvent sound = RegistryUtils.getSoundEvent("minecraft:ambient.cave");

// Filter registry objects
Stream<Block> allBlocks = RegistryUtils.getObjectsByCondition(
    BuiltInRegistries.BLOCK, 
    block -> block.defaultBlockState().isAir()
);

// Get object IDs
String blockId = RegistryUtils.getObjectId(BuiltInRegistries.BLOCK, stoneBlock);

Tag Management

// Create tag keys
TagKey<Block> blockTag = TagUtils.createBlock("custom_blocks");
TagKey<Item> itemTag = TagUtils.createItem("custom_items");
TagKey<Biome> biomeTag = TagUtils.createBiome("spawn_biomes");

// Generic tag creation
TagKey<EntityType<?>> entityTag = TagUtils.createTag(Registries.ENTITY_TYPE, "entities");

### World Generation

```java
// Ore placement
List<PlacementModifier> commonOre = WorldGenerationUtils.createCommonOrePlacement(
    8, 
    HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(64))
);

List<PlacementModifier> rareOre = WorldGenerationUtils.createRareOrePlacement(
    4, 
    HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(32))
);

// Custom placement
List<PlacementModifier> customPlacement = WorldGenerationUtils.createOrePlacement(
    CountPlacement.of(10),
    HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.top())
);

// Register features
WorldGenerationUtils.registerFeature(
    context, 
    featureKey, 
    Feature.ORE, 
    new OreConfiguration(targetStates, size)
);

When to use

  • Resource location parsing - Always use ResourceUtils instead of manual string splitting
  • Registry access - Prefer RegistryUtils for type-safe registry operations
  • Tag creation - Use TagUtils for consistent tag key creation
  • World generation setup - Use WorldGenerationUtils for standard placement patterns

The utilities are designed to reduce boilerplate and provide consistency, but should not replace standard Java operations when they are more appropriate for the specific use case.

For more, check the util package!

Clone this wiki locally