35 lines
1.4 KiB
Java
35 lines
1.4 KiB
Java
package land.chipmunk.chipmunkmod.util.configurate;
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
import net.minecraft.util.math.BlockBox;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import org.spongepowered.configurate.ConfigurationNode;
|
|
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
|
import org.spongepowered.configurate.serialize.SerializationException;
|
|
import org.spongepowered.configurate.serialize.TypeSerializerCollection;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public final class ConfigurateUtilities {
|
|
private static final TypeSerializerCollection CUSTOM_SERIALIZER_COLLECTION = TypeSerializerCollection.builder()
|
|
.registerAll(GsonConfigurationLoader.gsonSerializers())
|
|
.register(BlockPos.class, BlockPosTypeSerializer.INSTANCE)
|
|
.register(BlockBox.class, BlockBoxTypeSerializer.INSTANCE)
|
|
.register(Component.class, ComponentTypeSerializer.INSTANCE)
|
|
.build();
|
|
|
|
private ConfigurateUtilities() {
|
|
}
|
|
|
|
public static TypeSerializerCollection customSerializers() {
|
|
return CUSTOM_SERIALIZER_COLLECTION;
|
|
}
|
|
|
|
public static ConfigurationNode getNodeOrThrow(final ConfigurationNode source, final Object... path) throws SerializationException {
|
|
if (!source.hasChild(path)) {
|
|
throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node");
|
|
}
|
|
|
|
return source.node(path);
|
|
}
|
|
}
|