From 6e8131f2bb0e66975922c701a89dc120c261964c Mon Sep 17 00:00:00 2001 From: Majrusz Date: Wed, 8 Mar 2023 12:47:26 +0100 Subject: [PATCH 1/4] Updated verison name --- README.md | 2 +- build.gradle | 2 +- src/main/resources/META-INF/mods.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3fde1c4a..5c893a8c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - [Modrinth](https://modrinth.com/mod/majrusz-library) ## Current Library Releases (Source Code) -- [v3.2.0 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszLibrary/tree/1.19.X) +- [v3.3.0 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszLibrary/tree/1.19.X) - [v2.7.3 for Minecraft 1.18.2](https://github.com/Majrusz/MajruszLibrary/tree/1.18.X) *(not supported anymore)* - [v2.6.0 for Minecraft 1.17.1](https://github.com/Majrusz/MajruszLibrary/tree/1.17.1) *(not supported anymore)* - [v2.0.1 for Minecraft 1.16.5](https://github.com/Majrusz/MajruszLibrary/tree/1.16.4) *(not supported anymore)* diff --git a/build.gradle b/build.gradle index 1abf1cb1..6eca5cf9 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: 'org.spongepowered.mixin' -version = '3.2.0' +version = '3.3.0-unfinished' group = 'com.mlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'majrusz-library-1.19.3' diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index a40ed8cb..375c11d5 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/Majrusz/MajruszLibrary/issues" [[mods]] modId="mlib" - version="3.2.0" + version="3.3.0-unfinished" displayName="Majrusz Library" updateJSONURL="https://raw.githubusercontent.com/Majrusz/MinecraftCommon/main/Library/update.json" displayURL="https://www.curseforge.com/minecraft/mc-mods/majrusz-library" From 30b2fd3f710158c58c5ec2dc1bedf6c1a9c5f653 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Wed, 8 Mar 2023 12:48:32 +0100 Subject: [PATCH 2/4] Fixed enum serialization --- src/main/java/com/mlib/data/DataEnum.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mlib/data/DataEnum.java b/src/main/java/com/mlib/data/DataEnum.java index 309cb175..29307159 100644 --- a/src/main/java/com/mlib/data/DataEnum.java +++ b/src/main/java/com/mlib/data/DataEnum.java @@ -37,7 +37,7 @@ protected TagReader< Type > getTagReader() { private Type toEnum( String name ) { Type[] values = this.values.get(); for( Type value : values ) { - if( name.equalsIgnoreCase( value.toString() ) ) { + if( name.equalsIgnoreCase( value.name() ) ) { return value; } } @@ -46,7 +46,7 @@ private Type toEnum( String name ) { } private String toString( Type value ) { - return value.toString(); + return value.name(); } @FunctionalInterface From 52fd22440b2831ccf9a3121b4682cedced39bc09 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Wed, 8 Mar 2023 12:55:41 +0100 Subject: [PATCH 3/4] Added json listener --- src/main/java/com/mlib/data/JsonListener.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/mlib/data/JsonListener.java diff --git a/src/main/java/com/mlib/data/JsonListener.java b/src/main/java/com/mlib/data/JsonListener.java new file mode 100644 index 00000000..82c62637 --- /dev/null +++ b/src/main/java/com/mlib/data/JsonListener.java @@ -0,0 +1,44 @@ +package com.mlib.data; + +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.storage.loot.Deserializers; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.AddReloadListenerEvent; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +public class JsonListener { + final static List< SerializableStructure > STRUCTURES = Collections.synchronizedList( new ArrayList<>() ); + + public static < Type extends SerializableStructure > Supplier< Type > add( String data, ResourceLocation location, Class< Type > clazz, + Supplier< Type > newInstance + ) { + int idx = STRUCTURES.size(); + STRUCTURES.add( null ); + var gson = Deserializers.createFunctionSerializer() + .registerTypeAdapter( clazz, ( JsonDeserializer< Type > )( element, type, context )->{ + Type messages = newInstance.get(); + messages.read( element ); + + return messages; + } ).create(); + var listener = new SimpleJsonResourceReloadListener( gson, data ) { + @Override + protected void apply( Map< ResourceLocation, JsonElement > elements, ResourceManager manager, ProfilerFiller filler ) { + STRUCTURES.set( idx, gson.fromJson( elements.get( location ), clazz ) ); + } + }; + MinecraftForge.EVENT_BUS.addListener( ( AddReloadListenerEvent event )->event.addListener( listener ) ); + + return ()->( Type )STRUCTURES.get( idx ); + } +} From 331986a197532eb71b3e6a52e7bbfa048cf00eb7 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Thu, 9 Mar 2023 11:37:00 +0100 Subject: [PATCH 4/4] Removed unfinished tag --- build.gradle | 2 +- src/main/resources/META-INF/mods.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6eca5cf9..ea979f48 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: 'org.spongepowered.mixin' -version = '3.3.0-unfinished' +version = '3.3.0' group = 'com.mlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'majrusz-library-1.19.3' diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 375c11d5..be8d90dd 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/Majrusz/MajruszLibrary/issues" [[mods]] modId="mlib" - version="3.3.0-unfinished" + version="3.3.0" displayName="Majrusz Library" updateJSONURL="https://raw.githubusercontent.com/Majrusz/MinecraftCommon/main/Library/update.json" displayURL="https://www.curseforge.com/minecraft/mc-mods/majrusz-library"