Final step of the MCreator purge. The MODID (custom_ore_gen) and all registry names are unchanged, so existing worlds/saves are unaffected: data JSONs reference the MODID, never the Java package. Updated the mixin config package and the OresCommandTest package assertion.
6.0 KiB
Custom Ore Gem - Developer Guide for Agents
This repository is a Minecraft NeoForge 1.21.1 mod. It was originally scaffolded with MCreator but is now fully hand-maintained — all files are safe to edit. Agents must follow these guidelines to ensure build stability.
1. Build & Test Commands
Use the Gradle wrapper for all operations. Ensure you are using Java 21 (NeoForge 1.21.1 requirement).
-
Build Mod:
./gradlew build- Generates the mod JAR in
build/libs/. - Always run this after making changes to verify compilation.
- Generates the mod JAR in
-
Run Client:
./gradlew runClient -
Run Server:
./gradlew runServer -
Run Data Generation:
./gradlew runData- This generates resources (blockstates, models, loot tables) into
src/generated/resources.
- This generates resources (blockstates, models, loot tables) into
-
Run All Tests:
./gradlew test -
Run Single Test Class:
./gradlew test --tests "com.aulyrius.customoregen.OresCommandTest" -
Run Single Test Method:
./gradlew test --tests "com.aulyrius.customoregen.OresCommandTest.testCommandRegistration_ShouldRegisterOresCommand" -
Clean Project:
./gradlew clean
2. Code Ownership
The project was originally generated by MCreator but is no longer maintained with it (MCreator is not installed anymore; the build is plain Gradle + NeoForge ModDev).
- Every file in
src/main/javaandsrc/test/javais hand-maintained and safe to edit. - The historical "user code block" markers were removed; there is no regeneration step.
- Keep MCreator-era naming quirks (e.g.
SharddiamondpickaxeItem) unless a rename is explicitly requested, to keep diffs readable.
3. Code Style & Conventions
Formatting
- Indentation:
- Source Code (
src/main): Use TABS (default MCreator style). - Tests (
src/test): Use 4 SPACES (typical for JUnit tests). - Consistency: Always check the current file's indentation before editing.
- Source Code (
- Encoding: UTF-8.
Naming
- Classes: PascalCase (e.g.,
CustomOreGenMod). - Methods: camelCase (e.g.,
queueServerWork). - Constants: UPPER_SNAKE_CASE (e.g.,
MODID,COLD_BIOMES_TAG). - Fields: camelCase (e.g.,
workQueue,oreGenConfig). - Packages:
com.aulyrius.customoregen(lowercase).
Imports
- Group imports in this specific order:
- Java/Standard Libraries (
java.*,javax.*) - Third-party Libraries (e.g.,
org.apache.logging.log4j.*) - Minecraft/NeoForge (
net.minecraft.*,net.neoforged.*) - Project Classes (
com.aulyrius.customoregen.*)
- Java/Standard Libraries (
- Avoid
import *unless there are many imports from the same package (e.g.,java.util.*is acceptable if heavily used, but explicit imports are preferred for clarity).
Logging
- Use
LogManager.getLogger(Class.class)for loggers. - Field name:
LOGGER. - Log levels: Use
debugfor dev info,infofor general status,errorfor exceptions.
4. Architecture & Patterns
-
Framework: NeoForge 1.21.1 (Java 21).
-
Registries: Use
DeferredRegisterfor all registries (Blocks, Items, Tabs, SoundEvents).- Example:
public static final DeferredRegister.Blocks REGISTRY = DeferredRegister.createBlocks(CustomOreGenMod.MODID);
- Example:
-
Event Bus:
- The
@Modclass registers theIEventBus. - Use
@SubscribeEventfor event handling. - Event handlers often reside in
com.aulyrius.customoregen.eventor static inner classes annotated with@EventBusSubscriber.
- The
-
Configuration:
- Located in
com.aulyrius.customoregen.config.ModConfigs. - Uses
ModConfig.Type.COMMONbuilt withModConfigSpec. - Access configs via the public static fields (e.g.,
ModConfigs.ORE_GEN.shardDiamondOreCount.get()).
- Located in
-
Commands:
- Registered via
RegisterCommandsEvent. - Use Brigadier (
CommandDispatcher,CommandContext). - See
OresCommand.javafor the reference implementation.
- Registered via
5. Testing Guidelines
- Framework: JUnit 5 (Jupiter) + Mockito.
- Location:
src/test/java. - Mocking Strategy:
- Since a full Minecraft environment is not available in unit tests, you MUST mock Minecraft classes.
- Use
@ExtendWith(MockitoExtension.class). - Mock critical classes:
@Mock ServerPlayer player,@Mock Level level,@Mock BlockPos pos. - Stub methods:
when(level.getBiome(pos)).thenReturn(biomeHolder);.
- Assertions: Use
org.junit.jupiter.api.Assertions(e.g.,assertEquals,assertDoesNotThrow).
6. Common Tasks
-
Adding a New Ore:
- Create Block & Item (MCreator/Manual).
- Add JSONs: Loot Table, Configured Feature, Placed Feature, Biome Modifier.
- Register in
CustomOreGenModBlocksandCustomOreGenModItems. - Update
OresCommand.javalists (e.g.,COLD_ORES,HOT_ORES) to make it discoverable. - Update
OreBreakEventHandler.javaif it has custom drops logic. - Add to
ModConfigs.javafor generation parameters (vein size, count, etc.).
-
Modifying Logic:
- Check
procedures/for game logic (often MCreator generated). - Check
event/for event-driven logic. - Always verify if logic changes need a corresponding test update.
- Check
7. Safety & Verification
- Backups: If you are unsure about MCreator regeneration, backup the file before editing.
- Verification:
- Always run
./gradlew buildafter changes to ensure no compilation errors. - If you touch config files, ensure
ModConfigsTeststill passes. - If you touch commands, ensure
OresCommandTeststill passes.
- Always run
8. Directory Structure
src/
├── main/
│ ├── java/net/mcreator/customoregen/
│ │ ├── block/ # Block definitions
│ │ ├── config/ # Configuration classes
│ │ ├── event/ # Event handlers
│ │ ├── init/ # Registration (Blocks, Items, Tabs)
│ │ ├── item/ # Item definitions
│ │ └── procedures/ # Game logic procedures
│ └── resources/ # Assets and data (textures, models, lang)
└── test/
└── java/net/mcreator/customoregen/ # Unit tests