Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
compileOnly(libs.jetbrains.annotations)

testJarJar(testApi(libs.testframework.get()))
testImplementation(libs.testframework.get())

// Recipe Viewers
compileOnly(forge.bundles.jei)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel = true
org.gradle.caching = true

# Mod Info
mod_id = synceddata
mod_id = synced
mod_name = SyncedData
mod_version = 0.0.2
mod_description =
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
minecraft = "1.26.1.1"
neoForge = "26.1.0.19-beta"
neoForge = "26.1.1.15-beta"
loader = "4"
shadow = "9.4.0"
spotless = "8.4.0"
Expand Down
2 changes: 2 additions & 0 deletions gradle/scripts/moddevgradle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ neoForge {
sourceSet = sourceSets.clientExtra
ideName = "Client"


gameDirectory.set(file('run/client'))
systemProperty('neoforge.enabledGameTestNamespaces', project.mod_id)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spotless {
targetExclude 'src/generated/resources/**'
biome()
trimTrailingWhitespace()
leadingSpacesToTabs(2)
leadingSpacesToTabs()
endWithNewline()
}
}
159 changes: 159 additions & 0 deletions src/main/java/com/modularmc/synceddata/SyncedData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package com.modularmc.synceddata;

import com.modularmc.synceddata.utils.FormattingUtil;

import net.minecraft.client.Minecraft;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.data.loading.DatagenModLoader;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

import com.mojang.serialization.Codec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.file.Path;

@Mod(SyncedData.MOD_ID)
public class SyncedData {

public static final String MOD_ID = "synced";
public static final String MOD_NAME = "SyncedData";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final Codec<Identifier> GTCEU_ID = Codec.STRING.comapFlatMap(
str -> Identifier.read(appendIdString(str)),
s -> s.getNamespace().equals(MOD_ID) ? s.getPath() : s.toString());
public static final Path SYNCED_FOLDER = getGameDir().resolve("synced");
private static final Identifier TEMPLATE_LOCATION = Identifier.fromNamespaceAndPath(MOD_ID, "");

public static Identifier id(String path) {
if (path.isBlank()) {
return TEMPLATE_LOCATION;
}

int i = path.indexOf(':');
if (i > 0) {
return Identifier.tryParse(path);
} else if (i == 0) {
path = path.substring(i + 1);
}
// only convert it to camel_case if it has any uppercase to begin with
if (FormattingUtil.hasUpperCase(path)) {
path = FormattingUtil.toLowerCaseUnderscore(path);
}
return TEMPLATE_LOCATION.withPath(path);
}

public static String appendIdString(String id) {
int i = id.indexOf(':');
if (i > 0) {
return id;
} else if (i == 0) {
return MOD_ID + id;
} else {
return MOD_ID + ":" + id;
}
}

/**
* 是否在生产环境中运行
*
* @return if we're running in a production environment
*/
public static boolean isProd() {
return FMLEnvironment.isProduction();
}

/**
* 是否不在生产环境中运行
*
* @return if we're not running in a production environment
*/
public static boolean isDev() {
return !isProd() || isDataGen();
}

/**
* 是否正在运行数据生成
*
* @return if we're running data generation
*/
public static boolean isDataGen() {
return DatagenModLoader.isRunningDataGen();
}

/**
* 一个友好的提醒:服务器实例仅在服务器端填充,因此请进行空/端检查!
* A friendly reminder that the server instance is populated on the server side only, so null/side check it!
*
* @return 当前的Minecraft服务器实例 the current minecraft server instance
*/
public static MinecraftServer getMinecraftServer() {
return ServerLifecycleHooks.getCurrentServer();
}

/**
* 检查指定mod是否已加载
*
* @param modId 要检查的mod ID the mod id to check for
* @return 指定ID的mod是否已加载 if the mod whose id is {@code modId} is loaded or not
*/
public static boolean isModLoaded(String modId) {
return ModList.get().isLoaded(modId);
}

/**
* 对于异步操作使用此方法,否则使用 {@link SyncedData isClientSide}
* For async stuff use this, otherwise use {@link SyncedData isClientSide}
*
* @return 当前线程是否为客户端线程 if the current thread is the client thread
*/
public static boolean isClientThread() {
return isClientSide() && Minecraft.getInstance().isSameThread();
}

/**
* 游戏是否为<strong>物理</strong>客户端,例如不是专用服务器
*
* @return if the game is the <strong>PHYSICAL</strong> client, e.g. not a dedicated server.
* @apiNote 不要使用此方法来检查你是否在服务器线程上执行端特定操作!它<strong>不</strong>适用于此。请使用 {@link #isClientThread()} 代替。
* Do not use this to check if you're currently on the server thread for side-specific actions!
* It does <strong>NOT</strong> work for that. Use {@link #isClientThread()} instead.
* @see #isClientThread()
*/
public static boolean isClientSide() {
return FMLEnvironment.getDist().isClient();
}

/**
* 此检查在客户端和服务器上并不相同!
* This check isn't the same for client and server!
*
* @return 在客户端上访问当前实例{@link net.minecraft.world.level.Level Level}是否安全,或者在服务器上访问任何level是否安全。
* if it's safe to access the current instance {@link net.minecraft.world.level.Level Level} on client or if
* it's safe to access any level on server.
*/
public static boolean canGetServerLevel() {
if (isClientSide()) {
return Minecraft.getInstance().level != null;
}
var server = getMinecraftServer();
return server != null &&
!(server.isStopped() || server.isShutdown() || !server.isRunning() || server.isCurrentlySaving());
}

/**
* 获取Minecraft实例目录的路径
*
* @return Minecraft实例目录的路径 the path to the minecraft instance directory
*/
public static Path getGameDir() {
return FMLPaths.GAMEDIR.get();
}

public static class Mods {}
}
42 changes: 0 additions & 42 deletions src/main/java/com/modularmc/synceddata/Synceddata.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.modularmc.synceddata.core.mixins;

public class SyncedMixinPlugin {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.modularmc.synceddata.utils;

public class FormattingUtil {

/**
* Check if {@code string} has any uppercase characters.
*
* @param string the string to check
* @return if the string has any uppercase characters.
*/
public static boolean hasUpperCase(String string) {
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if (Character.isUpperCase(ch)) return true;
}
return false;
}

/**
* Does almost the same thing as {@code UPPER_CAMEL.to(LOWER_UNDERSCORE, string)},
* but it also inserts underscores between words and numbers.
*
* @param string Any string with ASCII characters.
* @return A string that is all lowercase, with underscores inserted before word/number boundaries:
*
* <pre>
* <br>{@code "maragingSteel300" -> "maraging_steel_300"}
* <br>{@code "gtceu:maraging_steel_300" -> "gtceu:maraging_steel_300"}
* <br>{@code "maragingSteel_300" -> "maraging_steel_300"}
* <br>{@code "maragingSTEEL_300" -> "maraging_steel_300"}
* <br>{@code "MARAGING_STEEL_300" -> "maraging_steel_300"}
* </pre>
*/
public static String toLowerCaseUnderscore(String string) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < string.length(); i++) {
char curChar = string.charAt(i);
result.append(Character.toLowerCase(curChar));
if (i == string.length() - 1) break;

char nextChar = string.charAt(i + 1);
if (curChar == '_' || nextChar == '_') continue;
boolean nextIsUpper = Character.isUpperCase(nextChar);
if (Character.isUpperCase(curChar) && nextIsUpper) continue;
if (nextIsUpper || Character.isDigit(curChar) ^ Character.isDigit(nextChar)) result.append('_');
}
return result.toString();
}
}
3 changes: 1 addition & 2 deletions src/main/resources/META-INF/enum_extensions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"entries": [
]
"entries": []
}
6 changes: 3 additions & 3 deletions src/main/resources/assets/synceddata/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"itemGroup.synceddata": "Example Mod Tab",
"block.synceddata.example_block": "Example Block",
"item.synceddata.example_item": "Example Item"
"itemGroup.synceddata": "Example Mod Tab",
"block.synceddata.example_block": "Example Block",
"item.synceddata.example_item": "Example Item"
}
14 changes: 14 additions & 0 deletions src/main/resources/synced.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.modularmc.synceddata.core.mixins",
"compatibilityLevel": "JAVA_25",
"mixins": [],
"client": [],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"requireAnnotations": true
}
}
16 changes: 0 additions & 16 deletions src/main/resources/synceddata.mixins.json

This file was deleted.

Loading