Skip to content

Commit

Permalink
Merged 3.3.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz authored Mar 9, 2023
2 parents e69a542 + 331986a commit 06510b2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = '3.2.0'
version = '3.3.0'
group = 'com.mlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'majrusz-library-1.19.3'

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mlib/data/DataEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -46,7 +46,7 @@ private Type toEnum( String name ) {
}

private String toString( Type value ) {
return value.toString();
return value.name();
}

@FunctionalInterface
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/mlib/data/JsonListener.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/Majrusz/MajruszLibrary/issues"

[[mods]]
modId="mlib"
version="3.2.0"
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"
Expand Down

0 comments on commit 06510b2

Please sign in to comment.