Skip to content

Commit

Permalink
Initialization and some APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Apr 18, 2024
1 parent 1c4d0bb commit ca34176
Show file tree
Hide file tree
Showing 53 changed files with 491 additions and 228 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/close_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ on:

jobs:
call-analyze-workflow:
permissions:
issues: write
pull-requests: write
uses: crystal-nest/.github/.github/workflows/close_issue.yml@main
secrets: inherit
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

All notable changes to the "cobweb-mod-template" Minecraft mod will be documented in this file.
All notable changes to the "cobweb" Minecraft mod will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Forge Semantic Versioning](https://mcforge.readthedocs.io/en/latest/gettingstarted/versioning/#versioning).
Expand All @@ -13,5 +13,5 @@ and this project adheres to [Forge Semantic Versioning](https://mcforge.readthed

- Release notes...

[Unreleased]: https://github.com/crystal-nest/cobweb-mod-template
[README]: https://github.com/crystal-nest/cobweb-mod-template#readme
[Unreleased]: https://github.com/crystal-nest/cobweb
[README]: https://github.com/crystal-nest/cobweb#readme
44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
![Cobweb Mod Template banner](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/cobweb-mod-template/banner.png "Cobweb Mod Template banner")
![Cobweb banner](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/cobweb/banner.png "Cobweb banner")

---

![Minecraft](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/minecraft.svg "Minecraft")[![1.20.4](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-20-4.svg "1.20.4")](https://modrinth.com/mod/cobweb-mod-template/versions?g=1.20.4)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.20.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-20-2.svg "1.20.2")](https://modrinth.com/mod/cobweb-mod-template/versions?g=1.20.2)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.19.4](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-19-4.svg "1.19.4")](https://modrinth.com/mod/cobweb-mod-template/versions?g=1.19.4)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.19.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-19-2.svg "1.19.2")](https://modrinth.com/mod/cobweb-mod-template/versions?g=1.19.2)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.18.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-18-2.svg "1.18.2")](https://modrinth.com/mod/cobweb-mod-template/versions?g=1.18.2)
![Minecraft](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/minecraft.svg "Minecraft")[![1.20.4](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-20-4.svg "1.20.4")](https://modrinth.com/mod/cobweb/versions?g=1.20.4)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.20.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-20-2.svg "1.20.2")](https://modrinth.com/mod/cobweb/versions?g=1.20.2)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.19.4](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-19-4.svg "1.19.4")](https://modrinth.com/mod/cobweb/versions?g=1.19.4)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.19.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-19-2.svg "1.19.2")](https://modrinth.com/mod/cobweb/versions?g=1.19.2)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![1.18.2](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/minecraft/1-18-2.svg "1.18.2")](https://modrinth.com/mod/cobweb/versions?g=1.18.2)

![Loader](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/loader.svg "Loader")[![NeoForge](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/neoforge.svg "NeoForge")](https://modrinth.com/mod/cobweb-mod-template/versions?l=neoforge)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![Forge](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/forge.svg "Forge")](https://modrinth.com/mod/cobweb-mod-template/versions?l=forge)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![Fabric](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/fabric.svg "Fabric")](https://modrinth.com/mod/cobweb-mod-template/versions?l=fabric)
![Loader](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/loader.svg "Loader")[![NeoForge](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/neoforge.svg "NeoForge")](https://modrinth.com/mod/cobweb/versions?l=neoforge)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![Forge](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/forge.svg "Forge")](https://modrinth.com/mod/cobweb/versions?l=forge)![Separator](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/separator.svg)[![Fabric](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/loader/fabric.svg "Fabric")](https://modrinth.com/mod/cobweb/versions?l=fabric)

![Overlay](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/side/client-server.svg)

![Issues](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/github/issues.svg "Issues")[![GitHub](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/github/github.svg "GitHub")](https://github.com/crystal-nest/cobweb-mod-template/issues)
![Issues](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/github/issues.svg "Issues")[![GitHub](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/github/github.svg "GitHub")](https://github.com/crystal-nest/cobweb/issues)

---

## **Description**

Multiloader skeleton for Minecraft mods!
Built on [Jared's MultiLoaderTemplate](https://github.com/jaredlll08/MultiLoader-Template), with the addition of:
Shared mod API across Crystal Nest projects.

- Tasks to publish on GitHub, Modrinth, and CurseForge.
- [Cobweb](https://modrinth.com/mod/cobweb) API dependency.
- A little bit more Javadoc.
- Code style changes.
## **Features**

## **Setup completion**
### Common features:

To complete the setup:
- Easier way to retrieve in-game IDs.
- Unified configuration system.

- Change the [Support us](#support-us) section and the banner link.
- Add your project CurseForge ID in the `gradle.properties`.
- Replace the placeholder values in `api-keys.properties`.
- Update the changelog with proper release notes.
- Run the task `common > Tasks > vanilla gradle > decompile`
- Run the task `forge > Tasks > forgegradle runs > genIntellijRuns`
### Fabric only features:

## Removing Platforms and Loaders
- Eased custom registering system.

While this template includes support for Fabric, Forge, and NeoForge, you can easily remove support for the ones you don't need.
This can be done by deleting the subproject folder and then removing it from the associated `include` in the `settings.gradle` file.
### Forge only features:

The same thing applies for the different publishing platforms, GitHub, Modrinth, and CurseForge.
To remove support for the ones you don't need just remove the plugin declaration and use in the root `build.gradle`.
Currently none.

### NeoForge only features:

Currently none.

## **License and right of use**

Feel free to use this mod template for any mod, just be sure to give credit and possibly link [here](https://github.com/crystal-nest/cobweb-mod-template#readme).
This project is published under the [GNU General Public License v3.0](https://github.com/crystal-nest/cobweb-mod-template/blob/master/LICENSE).
Feel free to use this mod for any modpack or video, just be sure to give credit and possibly link [here](https://github.com/crystal-nest/cobweb#readme).
This project is published under the [GNU General Public License v3.0](https://github.com/crystal-nest/cobweb/blob/master/LICENSE).

## **Support us**

Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ subprojects { subproject ->
name = "Crystal Nest"
url = "https://maven.crystalnest.it"
}
maven {
name = "Fuzs Mod Resources"
url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/"
}
}

tasks.withType(JavaCompile).configureEach {
Expand Down Expand Up @@ -91,6 +95,7 @@ subprojects { subproject ->
"forge_loader_version_range" : forge_loader_version_range,
"neoforge_version" : neoforge_version,
"neoforge_loader_version_range": neoforge_loader_version_range,
"fcap_version" : fcap_version,
]

filesMatching(["pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml", "*.mixins.json"]) {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ minecraft {

dependencies {
compileOnly group: "org.spongepowered", name: "mixin", version: "0.8.5"
compileOnly "fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:${fcap_version}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.crystalnest.cobweb_mod_template;
package it.crystalnest.cobweb;

/**
* Common mod loader.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package it.crystalnest.cobweb_mod_template;
package it.crystalnest.cobweb;

import it.crystalnest.cobweb_mod_template.platform.Services;
import it.crystalnest.cobweb_mod_template.platform.services.PlatformHelper;
import it.crystalnest.cobweb.platform.Services;
import it.crystalnest.cobweb.platform.services.ConfigHelper;
import it.crystalnest.cobweb.platform.services.PlatformHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,7 +15,7 @@ private Constants() {}
/**
* Mod id.
*/
public static final String MOD_ID = "cobweb_mod_template";
public static final String MOD_ID = "cobweb";

/**
* Mod logger.
Expand All @@ -25,4 +26,9 @@ private Constants() {}
* Provides information about what platform the mod is running on.
*/
public static final PlatformHelper PLATFORM = Services.load(PlatformHelper.class);

/**
* Provides registration for configuration specs.
*/
public static final ConfigHelper CONFIG = Services.load(ConfigHelper.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.crystalnest.cobweb.api.block;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;

public final class BlockUtils {
private BlockUtils() {}

/**
* Returns the in-game {@link ResourceLocation} of the block passed as parameter.
*
* @param block
* @return {@link ResourceLocation} of the given block.
*/
public static ResourceLocation getKey(Block block) {
return BuiltInRegistries.BLOCK.getKey(block);
}

/**
* Returns the in-game ID of the block passed as parameter.
*
* @param block
* @return in-game ID of the given block.
*/
public static String getStringKey(Block block) {
return BlockUtils.getKey(block).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.crystalnest.cobweb.api.config;

import it.crystalnest.cobweb.Constants;
import net.neoforged.neoforge.common.ModConfigSpec;

import java.util.function.Function;

public abstract class ClientConfig extends CobwebConfig {
protected ClientConfig(ModConfigSpec.Builder builder) {
super(builder);
}

protected static <T extends ClientConfig> T register(String modId, Function<ModConfigSpec.Builder, CobwebConfig> constructor) {
register(modId, ConfigType.CLIENT, constructor);
Constants.CONFIG.registerClientConfig(getId(modId, ConfigType.CLIENT), getSpec(modId));
return getConfig(modId);
}

protected static <T extends CobwebConfig> T getConfig(String modId) {
return getConfig(modId, ConfigType.CLIENT);
}

protected static ModConfigSpec getSpec(String modId) {
return getSpec(modId, ConfigType.CLIENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package it.crystalnest.cobweb.api.config;

import net.neoforged.neoforge.common.ModConfigSpec;
import org.apache.commons.lang3.tuple.Pair;

import java.util.HashMap;
import java.util.function.Function;

public abstract class CobwebConfig {
private static final HashMap<String, Pair<CobwebConfig, ModConfigSpec>> CONFIGS = new HashMap<>();

protected CobwebConfig(ModConfigSpec.Builder builder) {
this.define(builder);
builder.build();
}

protected static void register(String modId, ConfigType type, Function<ModConfigSpec.Builder, CobwebConfig> constructor) {
CONFIGS.put(getId(modId, type), configure(constructor));
}

@SuppressWarnings("unchecked")
protected static <T extends CobwebConfig> T getConfig(String modId, ConfigType type) {
return (T) CONFIGS.get(getId(modId, type)).getLeft();
}

protected static ModConfigSpec getSpec(String modId, ConfigType type) {
return CONFIGS.get(getId(modId, type)).getRight();
}

protected static String getId(String modId, ConfigType type) {
return modId + "_" + type;
}

private static Pair<CobwebConfig, ModConfigSpec> configure(Function<ModConfigSpec.Builder, CobwebConfig> constructor) {
return new ModConfigSpec.Builder().configure(constructor);
}

/**
* Utility method to actually load the class and register the config. <br/>
* Generally, it can be empty and do nothing. <br/>
* Needs to be called in your mod loader.
*/
public void register() {
// Empty on purpose.
}

protected abstract void define(ModConfigSpec.Builder builder);

protected boolean stringListValidator(Object element) {
return element instanceof String && !((String) element).isBlank();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.crystalnest.cobweb.api.config;

import it.crystalnest.cobweb.Constants;
import net.neoforged.neoforge.common.ModConfigSpec;

import java.util.function.Function;

public abstract class CommonConfig extends CobwebConfig {
protected CommonConfig(ModConfigSpec.Builder builder) {
super(builder);
}

protected static <T extends CommonConfig> T register(String modId, Function<ModConfigSpec.Builder, CobwebConfig> constructor) {
register(modId, ConfigType.COMMON, constructor);
Constants.CONFIG.registerCommonConfig(modId, getSpec(modId));
return getConfig(modId);
}

protected static <T extends CobwebConfig> T getConfig(String modId) {
return getConfig(modId, ConfigType.COMMON);
}

protected static ModConfigSpec getSpec(String modId) {
return getSpec(modId, ConfigType.COMMON);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.crystalnest.cobweb.api.config;

public enum ConfigType {
SERVER,
CLIENT,
COMMON;

@Override
public String toString() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.crystalnest.cobweb.api.config;

import it.crystalnest.cobweb.Constants;
import net.neoforged.neoforge.common.ModConfigSpec;

import java.util.function.Function;

public abstract class ServerConfig extends CobwebConfig {
protected ServerConfig(ModConfigSpec.Builder builder) {
super(builder);
}

protected static <T extends ServerConfig> T register(String modId, Function<ModConfigSpec.Builder, CobwebConfig> constructor) {
register(modId, ConfigType.SERVER, constructor);
Constants.CONFIG.registerServerConfig(getId(modId, ConfigType.SERVER), getSpec(modId));
return getConfig(modId);
}

protected static <T extends CobwebConfig> T getConfig(String modId) {
return getConfig(modId, ConfigType.SERVER);
}

protected static ModConfigSpec getSpec(String modId) {
return getSpec(modId, ConfigType.SERVER);
}
}
29 changes: 29 additions & 0 deletions common/src/main/java/it/crystalnest/cobweb/api/item/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.crystalnest.cobweb.api.item;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;

public final class ItemUtils {
private ItemUtils() {}

/**
* Returns the in-game {@link ResourceLocation} of the item passed as parameter.
*
* @param item
* @return {@link ResourceLocation} of the given item.
*/
public static ResourceLocation getKey(Item item) {
return BuiltInRegistries.ITEM.getKey(item);
}

/**
* Returns the in-game ID of the item passed as parameter.
*
* @param item
* @return in-game ID of the given item.
*/
public static String getStringKey(Item item) {
return ItemUtils.getKey(item).toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.crystalnest.cobweb_mod_template.platform;
package it.crystalnest.cobweb.platform;

import it.crystalnest.cobweb_mod_template.Constants;
import it.crystalnest.cobweb.Constants;

import java.util.ServiceLoader;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.crystalnest.cobweb_mod_template.platform.model;
package it.crystalnest.cobweb.platform.model;

/**
* Environment.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.crystalnest.cobweb_mod_template.platform.model;
package it.crystalnest.cobweb.platform.model;

/**
* Platform.
Expand Down
Loading

0 comments on commit ca34176

Please sign in to comment.