Skip to content

Commit

Permalink
Registrar block method
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jan 2, 2025
1 parent 514eaca commit 14bf160
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions projects/pswg_core/src/main/java/dev/pswg/registry/Registrar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.pswg.registry;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -36,6 +37,25 @@ public static <TItem extends Item, TSettings extends Item.Settings> TItem item(I
return Registry.register(Registries.ITEM, registryKey, item);
}

/**
* Constructs and registers a block with the provided registry key
*
* @param registryKey The registry key to assign to the block
* @param constructor The constructor that will instantiate the block
* @param settings The settings that will be passed to the block
* @param <TBlock> The type of block to construct
* @param <TSettings> The type of settings to construct the block with
*
* @return A constructed block with the provided settings, given the corresponding registry key
*/
public static <TBlock extends Block, TSettings extends Block.Settings> TBlock block(Identifier registryKey, Function<TSettings, TBlock> constructor, TSettings settings)
{
// this cast to TSettings is legal since `registryKey` returns `this`
//noinspection unchecked
var block = constructor.apply((TSettings)settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, registryKey)));
return Registry.register(Registries.BLOCK, registryKey, block);
}

/**
* Constructs and registers an item with the provided registry key
*
Expand Down

0 comments on commit 14bf160

Please sign in to comment.