From dbdd3eb1344b837abb13538b9c55d1d99e697e54 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 22 Sep 2022 22:06:10 +0100 Subject: Allow platforms to pass extra misc metadata to the viewer --- .../spark/fabric/FabricExtraMetadataProvider.java | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java (limited to 'spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java') diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java new file mode 100644 index 0000000..9eb2694 --- /dev/null +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java @@ -0,0 +1,75 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package me.lucko.spark.fabric; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import me.lucko.spark.common.platform.MetadataProvider; + +import net.minecraft.resource.ResourcePackManager; +import net.minecraft.resource.ResourcePackProfile; +import net.minecraft.resource.ResourcePackSource; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class FabricExtraMetadataProvider implements MetadataProvider { + + private final ResourcePackManager resourcePackManager; + + public FabricExtraMetadataProvider(ResourcePackManager resourcePackManager) { + this.resourcePackManager = resourcePackManager; + } + + @Override + public Map get() { + Map metadata = new LinkedHashMap<>(); + metadata.put("datapacks", datapackMetadata()); + return metadata; + } + + private JsonElement datapackMetadata() { + JsonObject datapacks = new JsonObject(); + for (ResourcePackProfile profile : this.resourcePackManager.getEnabledProfiles()) { + JsonObject obj = new JsonObject(); + obj.addProperty("name", profile.getDisplayName().getString()); + obj.addProperty("description", profile.getDescription().getString()); + obj.addProperty("source", resourcePackSource(profile.getSource())); + datapacks.add(profile.getName(), obj); + } + return datapacks; + } + + private static String resourcePackSource(ResourcePackSource source) { + if (source == ResourcePackSource.PACK_SOURCE_NONE) { + return "none"; + } else if (source == ResourcePackSource.PACK_SOURCE_BUILTIN) { + return "builtin"; + } else if (source == ResourcePackSource.PACK_SOURCE_WORLD) { + return "world"; + } else if (source == ResourcePackSource.PACK_SOURCE_SERVER) { + return "server"; + } else { + return "unknown"; + } + } +} -- cgit From 205073cfa9fea36a85da918a0f8cc26042a33aed Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 7 Dec 2022 22:16:26 +0000 Subject: Fabric 1.19.3 --- spark-fabric/build.gradle | 8 ++++---- .../java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java') diff --git a/spark-fabric/build.gradle b/spark-fabric/build.gradle index fce859a..8b6d030 100644 --- a/spark-fabric/build.gradle +++ b/spark-fabric/build.gradle @@ -28,9 +28,9 @@ configurations { dependencies { // https://modmuss50.me/fabric.html - minecraft 'com.mojang:minecraft:1.19.2' - mappings 'net.fabricmc:yarn:1.19.2+build.1:v2' - modImplementation 'net.fabricmc:fabric-loader:0.14.9' + minecraft 'com.mojang:minecraft:1.19.3' + mappings 'net.fabricmc:yarn:1.19.3+build.2:v2' + modImplementation 'net.fabricmc:fabric-loader:0.14.11' Set apiModules = [ "fabric-api-base", @@ -40,7 +40,7 @@ dependencies { // Add each module as a dependency apiModules.forEach { - modImplementation(fabricApi.module(it, '0.59.0+1.19.2')) + modImplementation(fabricApi.module(it, '0.68.1+1.19.3')) } include(modImplementation('me.lucko:fabric-permissions-api:0.1-SNAPSHOT')) diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java index 9eb2694..22794c2 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java @@ -60,13 +60,13 @@ public class FabricExtraMetadataProvider implements MetadataProvider { } private static String resourcePackSource(ResourcePackSource source) { - if (source == ResourcePackSource.PACK_SOURCE_NONE) { + if (source == ResourcePackSource.NONE) { return "none"; - } else if (source == ResourcePackSource.PACK_SOURCE_BUILTIN) { + } else if (source == ResourcePackSource.BUILTIN) { return "builtin"; - } else if (source == ResourcePackSource.PACK_SOURCE_WORLD) { + } else if (source == ResourcePackSource.WORLD) { return "world"; - } else if (source == ResourcePackSource.PACK_SOURCE_SERVER) { + } else if (source == ResourcePackSource.SERVER) { return "server"; } else { return "unknown"; -- cgit