-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port fluid ingredient and tag key serializers from tinkers
- Loading branch information
1 parent
d7d565a
commit e90673a
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/slimeknights/mantle/data/TagKeySerializer.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,34 @@ | ||
package slimeknights.mantle.data; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
import lombok.RequiredArgsConstructor; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.tags.TagKey; | ||
import slimeknights.mantle.util.JsonHelper; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Serializer for a generic tag key type | ||
*/ | ||
@RequiredArgsConstructor | ||
public class TagKeySerializer<T> implements JsonSerializer<TagKey<T>>, JsonDeserializer<TagKey<T>> { | ||
private final ResourceKey<Registry<T>> registry; | ||
|
||
@Override | ||
public TagKey<T> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
return TagKey.create(registry, JsonHelper.convertToResourceLocation(json, "tag")); | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(TagKey<T> src, Type typeOfSrc, JsonSerializationContext context) { | ||
return new JsonPrimitive(src.location().toString()); | ||
} | ||
} |
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