-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codec metadata section serializer and manually update due to acti…
…on failure <log>Added codec metadata section serializer</log>
- Loading branch information
1 parent
67c9bfb
commit 4345649
Showing
5 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
29 changes: 29 additions & 0 deletions
29
.../java/com/teamresourceful/resourcefullib/client/utils/CodecMetadataSectionSerializer.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,29 @@ | ||
package com.teamresourceful.resourcefullib.client.utils; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.DataResult; | ||
import com.mojang.serialization.JsonOps; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.metadata.MetadataSectionSerializer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record CodecMetadataSectionSerializer<T>(Codec<T> codec, ResourceLocation id) implements MetadataSectionSerializer<T> { | ||
|
||
@Override | ||
public @NotNull String getMetadataSectionName() { | ||
return id.toString(); | ||
} | ||
|
||
@Override | ||
public @NotNull T fromJson(JsonObject json) { | ||
DataResult<T> result = codec.parse(JsonOps.INSTANCE, json); | ||
if (result.error().isPresent()) { | ||
throw new IllegalStateException("Failed to parse " + id + " metadata section: " + result.error().get()); | ||
} | ||
if (result.result().isEmpty()) { | ||
throw new IllegalStateException("Failed to parse " + id + " metadata section: Empty result"); | ||
} | ||
return result.result().get(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
patch=14 | ||
patch=15 | ||
buildTime=0 | ||
build=0 | ||
releaseType=release | ||
currentMCVersion=1.20.1 | ||
initialMCVersion=1.19.1 | ||
version=2.1.14 | ||
version=2.1.15 |