Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Dec 30, 2023
1 parent 19eb838 commit 94882d9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 136 deletions.
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# Regilite (Registrate at home)
A light libary helping with registratrion and data generation
A light library helping with registration and data generation

## Content
This library provides helper functions and wrappers around for various Objects. Below we provide a list of all
functions provided.

### Translations
We provide automatic translations for objects where the `ResourceLocation` gives enough context. This can always
be changed using the `setTranslation` method.

Besides the translation of objects like blocks and items, we also provide helpers for adding automatic translations for `Components`.

### Blocks
Besides the block itself, there are also functions to automatically register the following:
- Loot tables
- Blockstates and model
- Block color (tint)
- Block Tags
- Translation
- Block item
- See `Items`

### Items
Besides the item itself, there are also functions to automatically register the following:
- Item model
- Item color (tint)
- Item Tags
- Creative tabs
- Translation

### Fluid(type)s
Besides the fluid(type) itself, there are also functions to automatically register the following:
- Flowing fluid
- Source fluid
- Fluid tag
- Translation
- Liquid block
- See `Block`
- Bucket Item
- See `Item`

### Block Entity(type)s
Besides the block entity(type) itself, it automatically registers the following:

- Block entity renderer (should we?)
- Block entity tags

This helper meanly helps by removing a lot of (constant) generic bounds from the code, and provides a shortcut to
create a block entity directly from the holder.

### Entity(type)s
Besides the entity(type) itself, it automatically registers the following:

- Entity model (should we?)
- Model layer (should we?)
- Entity tags
- Translation

This helper also removes a lot of (constant) generic bounds from the code.

### Menu(type)s
Besides the menu(type) itself, it automatically registers the following:

- Screen factory (should we?)
- Translation (should we, as we don't use it?)

This helper also removes a lot of (constant) generic bounds from the code.
4 changes: 2 additions & 2 deletions src/generated/resources/assets/examplemod/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"block.examplemod.example_block": "Example block",
"item.examplemod.example_item": "Example item"
"block.examplemod.example_block": "Test Example Block",
"item.examplemod.example_item": "Test Example Item"
}
5 changes: 5 additions & 0 deletions src/generated/resources/data/minecraft/tags/items/wool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"examplemod:example_item"
]
}
63 changes: 0 additions & 63 deletions src/main/java/com/example/examplemod/Config.java

This file was deleted.

78 changes: 8 additions & 70 deletions src/main/java/com/example/examplemod/ExampleMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.examplemod.data.EnderItemModelProvider;
import com.example.examplemod.registry.EnderBlockRegistry;
import com.example.examplemod.registry.EnderDeferredBlock;
import com.example.examplemod.registry.EnderDeferredItem;
import com.example.examplemod.registry.EnderItemRegistry;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -42,21 +43,16 @@
@Mod(ExampleMod.MODID)
public class ExampleMod
{
// Define mod id in a common place for everything to reference
public static final String MODID = "examplemod";
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
// Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
public static final EnderBlockRegistry BLOCKS = EnderBlockRegistry.createRegistry(MODID);
// Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace
public static final EnderItemRegistry ITEMS = EnderItemRegistry.createRegistry(MODID);
// Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);

// Creates a new Block with the id "examplemod:example_block", combining the namespace and path
public static final EnderDeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS
.registerBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE))
.addBlockTags(BlockTags.MUSHROOM_GROW_BLOCK, BlockTags.LOGS)
.setTranslation("Test Example Block")
.setBlockStateProvider(BlockStateProvider::simpleBlock)
.setLootTable(EnderBlockLootProvider::dropSelf)
.createBlockItem()
Expand All @@ -65,80 +61,22 @@ public class ExampleMod
.setTab(CreativeModeTabs.BUILDING_BLOCKS)
.finishBlockItem();

// Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2
public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
.alwaysEat().nutrition(1).saturationMod(2f).build()));
public static final EnderDeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
.alwaysEat().nutrition(1).saturationMod(2f).build()))
.addItemTags(ItemTags.WOOL)
.setTranslation("Test Example Item")
.setTab(null);

// Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
.withTabsBefore(CreativeModeTabs.COMBAT)
.icon(() -> EXAMPLE_ITEM.get().getDefaultInstance())
.displayItems((parameters, output) -> {
output.accept(EXAMPLE_ITEM.get()); // Add the example item to the tab. For your own tabs, this method is preferred over the event
}).build());

// The constructor for the mod class is the first code that is run when your mod is loaded.
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
public ExampleMod(IEventBus modEventBus)
{
// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);

// Register the Deferred Register to the mod event bus so blocks get registered
public ExampleMod(IEventBus modEventBus) {
BLOCKS.register(modEventBus);
// Register the Deferred Register to the mod event bus so items get registered
ITEMS.register(modEventBus);
// Register the Deferred Register to the mod event bus so tabs get registered
CREATIVE_MODE_TABS.register(modEventBus);

// Register ourselves for server and other game events we are interested in
NeoForge.EVENT_BUS.register(this);

// Register the item to a creative tab
modEventBus.addListener(this::addCreative);

// Register our mod's ModConfigSpec so that FML can create and load the config file for us
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
}

private void commonSetup(final FMLCommonSetupEvent event)
{
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");

if (Config.logDirtBlock)
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));

LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);

Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
}

// Add the example block item to the building blocks tab
private void addCreative(BuildCreativeModeTabContentsEvent event)
{
//if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS)
//event.accept(EXAMPLE_BLOCK_ITEM);
}

// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event)
{
// Do something when the server starts
LOGGER.info("HELLO from server starting");
}

// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents
{
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event)
{
// Some client setup code
LOGGER.info("HELLO FROM CLIENT SETUP");
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
}
}
}

0 comments on commit 94882d9

Please sign in to comment.