mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Homogenize and/or holdersets when serializing to prevent serializing to NBT from crashing (#9048) Fixes #9043
This commit is contained in:
1 parent
94af5cc43a
commit
57fd0ecb2e
5 files changed
+115
-3
No files matched your search
@@ -5,6 +5,8 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.core.HolderSet.ListBacked;
|
||||
|
||||
public interface IForgeHolderSet<T>
|
||||
{
|
||||
/**
|
||||
@@ -23,4 +25,36 @@ public interface IForgeHolderSet<T>
|
||||
{
|
||||
// noop by default, mutable/composite holdersets must override
|
||||
}
|
||||
|
||||
/**
|
||||
* What format this holderset serializes to in json/nbt/etc
|
||||
*/
|
||||
default public SerializationType serializationType()
|
||||
{
|
||||
// handle vanilla holderset types
|
||||
return this instanceof ListBacked<T> listBacked
|
||||
? listBacked.unwrap().map(
|
||||
// serializes as tag name if this holderset is named
|
||||
tag -> SerializationType.STRING,
|
||||
list -> list.size() == 1
|
||||
// if list has exactly one element then we have to check what kind, otherwise it's a list
|
||||
? list.get(0).unwrap().map(
|
||||
// if holder has a key bound then it's serialized as that string, otherwise it's inlined as an object
|
||||
key -> key == null ? SerializationType.OBJECT : SerializationType.STRING,
|
||||
value -> SerializationType.OBJECT)
|
||||
: SerializationType.LIST)
|
||||
: SerializationType.UNKNOWN; // unsupported holderset impl, could be anything
|
||||
}
|
||||
|
||||
/**
|
||||
* What format a holderset serializes to in json/nbt/etc
|
||||
*/
|
||||
public static enum SerializationType
|
||||
{
|
||||
/** Unhandled/unsupported holderset implementation, could serialize as potentially anything **/
|
||||
UNKNOWN,
|
||||
STRING,
|
||||
LIST,
|
||||
OBJECT
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user