developer-wiki icon indicating copy to clipboard operation
developer-wiki copied to clipboard

Example Mods & source code linking system

Open anonymous123-code opened this issue 2 years ago • 1 comments

What would you like the wiki to cover?

Add a Remark Plugin that enables linking code blocks to real code files. Code blocks should include which example mod is to be linked, the relative path to example mod code, and (optionally) a label of the span which is included. In the source files, comments should specify the specific ranges for each labels. Leading whitespace that all lines of an embed have in common should be trimmed. https://github.com/kevin940726/remark-code-import might work as a baseline, but the span is defined in the code block, not in the source code, which is not ideal.

Why should this be added to the wiki?

Currently one of the main issues with the wiki is that it is difficult to see to which file a code block actually belongs. This would fix the issue (See #67 ). Additionally, it would enable us to write example mods without the danger of source code and markdown getting out of sync.

Example

For example, for this code block:

​```ItemsExampleMod:src/main/java/com/example/ExampleMod.java@AddToItemGroup
​```

Would result in the following markdown:

Extract from file [src/main/java/com/example/ExampleMod.java](${link to github source code}):
```java
ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> {
	entries.addItem(EXAMPLE_ITEM);
});
```​

With the content of ExampleMod.java being:

package com.example.example_mod;

import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExampleMod implements ModInitializer {
	// @start CreateItem
	public static final Item EXAMPLE_ITEM = new Item(new QuiltItemSettings());
	// @end CreateItem

	@Override
	public void onInitialize(ModContainer mod) {
		LOGGER.info("Hello Quilt world from {}!", mod.metadata().name());

		// @start RegisterItem
		Registry.register(Registries.ITEM, new Identifier(mod.metadata().id(), "example_item"), EXAMPLE_ITEM);
		// @end RegisterItem
		// @start AddToItemGroup
		ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> {
			entries.addItem(EXAMPLE_ITEM);
		});
		// @end AddToItemGroup
	}
}

anonymous123-code avatar Dec 02 '23 11:12 anonymous123-code

I'll be working on this! I've got a few implementation ideas and I'll try to get a prototype out soon.

pyrox0 avatar Mar 18 '24 21:03 pyrox0