Compare commits
5
Commits
1.20.1
...
1.4.4-1.21
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b91570a8c | ||
|
|
de04d5a2cf | ||
|
|
f9b19cff35 | ||
|
|
89132f1e54 | ||
|
|
08824ba045 |
+2
-2
@@ -43,8 +43,8 @@ subprojects {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: "fabric-loom"
|
apply plugin: "fabric-loom"
|
||||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21
|
||||||
version = project.mod_version + "+" + project.minecraft_version
|
version = project.mod_version + "-" + project.minecraft_version
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
|
|||||||
+5
-4
@@ -3,15 +3,16 @@ org.gradle.jvmargs=-Xmx2G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/versions.html
|
# check these on https://fabricmc.net/versions.html
|
||||||
minecraft_version=1.20.1
|
|
||||||
yarn_mappings=1.20.1+build.10
|
minecraft_version=1.21
|
||||||
|
yarn_mappings=1.21+build.2
|
||||||
loader_version=0.15.11
|
loader_version=0.15.11
|
||||||
|
|
||||||
# Fabric API
|
# Fabric API
|
||||||
fabric_version=0.92.2+1.20.1
|
fabric_version=0.100.2+1.21
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.4.1
|
mod_version=1.4.4
|
||||||
maven_group=dev.draylar
|
maven_group=dev.draylar
|
||||||
archives_base_name=omega-config
|
archives_base_name=omega-config
|
||||||
modmenu_version=7.1.0
|
modmenu_version=7.1.0
|
||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
jdk:
|
jdk:
|
||||||
- openjdk17
|
- openjdk21
|
||||||
before_install:
|
before_install:
|
||||||
- sdk install java 17.0.1-open
|
- sdk install java 21.0.3-open
|
||||||
- sdk use java 17.0.1-open
|
- sdk use java 21.0.3-open
|
||||||
@@ -5,14 +5,16 @@ import com.google.gson.GsonBuilder;
|
|||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtList;
|
import net.minecraft.nbt.NbtList;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
|
import net.minecraft.network.codec.PacketCodecs;
|
||||||
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -24,45 +26,15 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class OmegaConfig implements ModInitializer {
|
public class OmegaConfig implements ModInitializer {
|
||||||
|
|
||||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
|
||||||
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
||||||
public static final Logger LOGGER = LogManager.getLogger();
|
public static final Logger LOGGER = LogManager.getLogger();
|
||||||
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInitialize() {
|
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> server.execute(() -> {
|
|
||||||
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
|
|
||||||
|
|
||||||
// list of configurations that are synced
|
|
||||||
NbtCompound root = new NbtCompound();
|
|
||||||
NbtList configurations = new NbtList();
|
|
||||||
|
|
||||||
// Iterate over each configuration.
|
|
||||||
// Find values that should be synced and send the value over.
|
|
||||||
OmegaConfig.getRegisteredConfigurations().forEach(config -> {
|
|
||||||
if (config.hasAnySyncable()) {
|
|
||||||
configurations.add(config.writeSyncingTag());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// save to packet and send to user
|
|
||||||
root.put("Configurations", configurations);
|
|
||||||
packet.writeNbt(root);
|
|
||||||
handler.sendPacket(ServerPlayNetworking.createS2CPacket(CONFIG_SYNC_PACKET, packet));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends Config> T register(Class<T> configClass) {
|
public static <T extends Config> T register(Class<T> configClass) {
|
||||||
try {
|
try {
|
||||||
// Attempt to instantiate a new instance of this class.
|
// Attempt to instantiate a new instance of this class.
|
||||||
@@ -96,7 +68,8 @@ public class OmegaConfig implements ModInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
|
InvocationTargetException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
throw new RuntimeException("No valid constructor found for: " + configClass.getName());
|
throw new RuntimeException("No valid constructor found for: " + configClass.getName());
|
||||||
}
|
}
|
||||||
@@ -179,12 +152,10 @@ public class OmegaConfig implements ModInitializer {
|
|||||||
|
|
||||||
Class<?>[] classes = aClass.getDeclaredClasses();
|
Class<?>[] classes = aClass.getDeclaredClasses();
|
||||||
|
|
||||||
if (classes.length != 0) {
|
|
||||||
for (Class<?> clazz : classes) {
|
for (Class<?> clazz : classes) {
|
||||||
populateRecursively(list, clazz);
|
populateRecursively(list, clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void addFieldComments(Field field, Map<String, String> keyToComments) {
|
private static void addFieldComments(Field field, Map<String, String> keyToComments) {
|
||||||
String fieldName = field.getName();
|
String fieldName = field.getName();
|
||||||
@@ -241,4 +212,38 @@ public class OmegaConfig implements ModInitializer {
|
|||||||
public static List<Config> getRegisteredConfigurations() {
|
public static List<Config> getRegisteredConfigurations() {
|
||||||
return REGISTERED_CONFIGURATIONS;
|
return REGISTERED_CONFIGURATIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
PayloadTypeRegistry.playS2C().register(OmegaConfig.SyncConfigPayload.ID, OmegaConfig.SyncConfigPayload.CODEC);
|
||||||
|
|
||||||
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> server.execute(() -> {
|
||||||
|
// list of configurations that are synced
|
||||||
|
NbtCompound root = new NbtCompound();
|
||||||
|
NbtList configurations = new NbtList();
|
||||||
|
|
||||||
|
// Iterate over each configuration.
|
||||||
|
// Find values that should be synced and send the value over.
|
||||||
|
OmegaConfig.getRegisteredConfigurations().forEach(config -> {
|
||||||
|
if (config.hasAnySyncable()) {
|
||||||
|
configurations.add(config.writeSyncingTag());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// save to packet and send to user
|
||||||
|
root.put("Configurations", configurations);
|
||||||
|
sender.sendPacket(new SyncConfigPayload(root));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record SyncConfigPayload(NbtCompound nbtCompound) implements CustomPayload {
|
||||||
|
public static final Identifier CONFIG_SYNC_PACKET = Identifier.of("omegaconfig", "sync");
|
||||||
|
public static final CustomPayload.Id<SyncConfigPayload> ID = new Id<>(CONFIG_SYNC_PACKET);
|
||||||
|
public static final PacketCodec<PacketByteBuf, SyncConfigPayload> CODEC = PacketCodecs.NBT_COMPOUND.xmap(SyncConfigPayload::new, SyncConfigPayload::nbtCompound).cast();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Id<? extends CustomPayload> getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,12 @@ public class ClientMixin {
|
|||||||
method = "<init>",
|
method = "<init>",
|
||||||
at = @At("RETURN"))
|
at = @At("RETURN"))
|
||||||
private void onReturn(RunArgs args, CallbackInfo ci) {
|
private void onReturn(RunArgs args, CallbackInfo ci) {
|
||||||
ClientPlayNetworking.registerGlobalReceiver(OmegaConfig.CONFIG_SYNC_PACKET, (client, handler, buf, responseSender) -> {
|
ClientPlayNetworking.registerGlobalReceiver(OmegaConfig.SyncConfigPayload.ID, (payload, context) -> {
|
||||||
NbtCompound tag = buf.readNbt();
|
|
||||||
|
NbtCompound tag = payload.nbtCompound();
|
||||||
savedClientConfig.clear();
|
savedClientConfig.clear();
|
||||||
|
|
||||||
client.execute(() -> {
|
context.client().execute(() -> {
|
||||||
if (tag != null && tag.contains("Configurations")) {
|
if (tag != null && tag.contains("Configurations")) {
|
||||||
NbtList list = tag.getList("Configurations", NbtType.COMPOUND);
|
NbtList list = tag.getList("Configurations", NbtType.COMPOUND);
|
||||||
list.forEach(compound -> {
|
list.forEach(compound -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user