generated from Crystal-Nest/cobweb-mod-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c4d0bb
commit ca34176
Showing
53 changed files
with
491 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../cobweb_mod_template/CommonModLoader.java → ...t/crystalnest/cobweb/CommonModLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
common/src/main/java/it/crystalnest/cobweb/api/block/BlockUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/it/crystalnest/cobweb/api/config/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
common/src/main/java/it/crystalnest/cobweb/api/config/CobwebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/it/crystalnest/cobweb/api/config/CommonConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/it/crystalnest/cobweb/api/config/ConfigType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/it/crystalnest/cobweb/api/config/ServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
common/src/main/java/it/crystalnest/cobweb/api/item/ItemUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...obweb_mod_template/platform/Services.java → ...crystalnest/cobweb/platform/Services.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._template/platform/model/Environment.java → ...st/cobweb/platform/model/Environment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mod_template/platform/model/Platform.java → ...lnest/cobweb/platform/model/Platform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.