From 2e2046a3a0c9d6b91b064b2a2c0e7a0db0df3d08 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 27 Jan 2024 16:34:00 -0800 Subject: [PATCH] feat: support new multiple-resource-pack system --- build.gradle.kts | 2 +- gradle.properties | 2 -- gradle/libs.versions.toml | 2 +- .../menus/options/EditableOption.java | 2 +- .../modules/items/wrenches/Lifecycle.java | 8 ++------ .../items/wrenches/PlayerListener.java | 2 +- .../items/wrenches/RotationWrenches.java | 20 ++++++++++++++++--- .../modules/survival/graves/Commands.java | 2 +- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 03f50931..a90a25a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "me.machinemaker" -version = "0.4.2-SNAPSHOT" +version = "0.5.0-SNAPSHOT" description = "A replacement for the VanillaTweaks datapack" repositories { diff --git a/gradle.properties b/gradle.properties index e73a3b5d..f97ebb7d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1 @@ -mcVersion=1.20-R0.1-SNAPSHOT - org.gradle.parallel=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d010f279..ce92d6d6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -minecraft = "1.20.2" +minecraft = "1.20.4" mm-mirror = "0.1.2" mm-lectern = "0.3.0" # deprecated cloud = "1.8.4" diff --git a/src/main/java/me/machinemaker/papertweaks/menus/options/EditableOption.java b/src/main/java/me/machinemaker/papertweaks/menus/options/EditableOption.java index 4c60cecd..2c3a485c 100644 --- a/src/main/java/me/machinemaker/papertweaks/menus/options/EditableOption.java +++ b/src/main/java/me/machinemaker/papertweaks/menus/options/EditableOption.java @@ -42,7 +42,7 @@ default Component createClickComponent(final T selected, final String commandPre @Override default Component createClickHoverComponent(final T selected) { - final TranslatableComponent.Builder builder = translatable().key("commands.config.editable").color(GRAY).args(this.label().color(WHITE)); + final TranslatableComponent.Builder builder = translatable().key("commands.config.editable").color(GRAY).arguments(this.label().color(WHITE)); if (this.extendedDescription() != Component.empty()) { builder.append(newline()).append(this.extendedDescription().color(GRAY)); } diff --git a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/Lifecycle.java b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/Lifecycle.java index 5d6f49fb..b122b6f1 100644 --- a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/Lifecycle.java +++ b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/Lifecycle.java @@ -26,15 +26,11 @@ import me.machinemaker.papertweaks.modules.ModuleLifecycle; import me.machinemaker.papertweaks.modules.ModuleListener; import me.machinemaker.papertweaks.modules.ModuleRecipe; -import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import static net.kyori.adventure.text.Component.text; - class Lifecycle extends ModuleLifecycle { - static final Component PACK_PROMPT = text("This resource pack adds a texture for the Redstone Wrench"); private final Config config; @@ -48,7 +44,7 @@ class Lifecycle extends ModuleLifecycle { public void onEnable() { if (this.config.suggestResourcePack) { Bukkit.getOnlinePlayers().forEach(player -> { - player.setResourcePack(RotationWrenches.RESOURCE_PACK_URL, RotationWrenches.RESOURCE_PACK_HASH, PACK_PROMPT); + player.sendResourcePacks(RotationWrenches.PACK_REQUEST); }); } @@ -58,7 +54,7 @@ public void onEnable() { public void onReload() { if (this.config.suggestResourcePack) { Bukkit.getOnlinePlayers().forEach(player -> { - player.setResourcePack(RotationWrenches.RESOURCE_PACK_URL, RotationWrenches.RESOURCE_PACK_HASH, PACK_PROMPT); + player.sendResourcePacks(RotationWrenches.PACK_REQUEST); }); } } diff --git a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/PlayerListener.java b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/PlayerListener.java index 7849ff50..380ead16 100644 --- a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/PlayerListener.java +++ b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/PlayerListener.java @@ -39,7 +39,7 @@ class PlayerListener implements ModuleListener { private void onPlayerJoin(final PlayerJoinEvent event) { event.getPlayer().discoverRecipe(RotationWrenches.WRENCH_RECIPE_KEY); if (this.config.suggestResourcePack) { - event.getPlayer().setResourcePack(RotationWrenches.RESOURCE_PACK_URL, RotationWrenches.RESOURCE_PACK_HASH, Lifecycle.PACK_PROMPT); + event.getPlayer().sendResourcePacks(RotationWrenches.PACK_REQUEST); } } } diff --git a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/RotationWrenches.java b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/RotationWrenches.java index 77226b58..8e58352f 100644 --- a/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/RotationWrenches.java +++ b/src/main/java/me/machinemaker/papertweaks/modules/items/wrenches/RotationWrenches.java @@ -19,9 +19,10 @@ */ package me.machinemaker.papertweaks.modules.items.wrenches; -import java.math.BigInteger; +import java.net.URI; import java.util.Collection; import java.util.Set; +import java.util.UUID; import me.machinemaker.papertweaks.annotations.ModuleInfo; import me.machinemaker.papertweaks.modules.ModuleBase; import me.machinemaker.papertweaks.modules.ModuleConfig; @@ -29,6 +30,8 @@ import me.machinemaker.papertweaks.modules.ModuleListener; import me.machinemaker.papertweaks.modules.ModuleRecipe; import me.machinemaker.papertweaks.utils.Keys; +import net.kyori.adventure.resource.ResourcePackRequest; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Material; @@ -39,14 +42,25 @@ import org.bukkit.persistence.PersistentDataType; import org.checkerframework.checker.nullness.qual.Nullable; +import static net.kyori.adventure.resource.ResourcePackInfo.resourcePackInfo; +import static net.kyori.adventure.resource.ResourcePackRequest.resourcePackRequest; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.format.Style.style; @ModuleInfo(name = "RotationWrenches", configPath = "items.rotation-wrenches", description = "A wrench to rotate redstone components and/or terracotta") public class RotationWrenches extends ModuleBase { - static final String RESOURCE_PACK_URL = "https://potrebic.box.com/shared/static/uw4fvii2o8qsjuz6xuant1safwjdnrez.zip"; - static final byte[] RESOURCE_PACK_HASH = new BigInteger("1ACF79C491B3CB9EEE50816AD0CC1FC45AABA147", 16).toByteArray(); + private static final UUID RESOURCE_PACK_UUID = UUID.fromString("904f0c77-69fd-380e-b1d7-5241aa6f5637"); + private static final URI RESOURCE_PACK_URL = URI.create("https://potrebic.box.com/shared/static/uw4fvii2o8qsjuz6xuant1safwjdnrez.zip"); + private static final String RESOURCE_PACK_HASH = "1ACF79C491B3CB9EEE50816AD0CC1FC45AABA147"; + private static final Component PACK_PROMPT = text("This resource pack adds a texture for the Redstone Wrench"); + + static final ResourcePackRequest PACK_REQUEST = resourcePackRequest() + .prompt(PACK_PROMPT) + .required(true) + .packs(resourcePackInfo(RESOURCE_PACK_UUID, RESOURCE_PACK_URL, RESOURCE_PACK_HASH)) + .build(); + static final int RESOURCE_PACK_MODEL_DATA = 4321; static final NamespacedKey WRENCH_RECIPE_KEY = Keys.legacyKey("redstone_wrench"); static final ShapedRecipe WRENCH_RECIPE; diff --git a/src/main/java/me/machinemaker/papertweaks/modules/survival/graves/Commands.java b/src/main/java/me/machinemaker/papertweaks/modules/survival/graves/Commands.java index 046eb726..2fd1a640 100644 --- a/src/main/java/me/machinemaker/papertweaks/modules/survival/graves/Commands.java +++ b/src/main/java/me/machinemaker/papertweaks/modules/survival/graves/Commands.java @@ -127,7 +127,7 @@ protected void registerCommands() { } private static Component formatLocation(final Location loc, final boolean hoverAndClick) { - final TranslatableComponent.Builder builder = translatable().key("modules.graves.location-format").color(YELLOW).args(text(loc.getBlockX()), text(loc.getBlockY()), text(loc.getBlockZ())); + final TranslatableComponent.Builder builder = translatable().key("modules.graves.location-format").color(YELLOW).arguments(text(loc.getBlockX()), text(loc.getBlockY()), text(loc.getBlockZ())); if (hoverAndClick) { final String tpCommand = "/tp %s %s %s".formatted(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); return builder.hoverEvent(HoverEvent.showText(text(tpCommand))).clickEvent(ClickEvent.runCommand(tpCommand)).build();