Skip to content

Commit

Permalink
feat: support new multiple-resource-pack system
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jan 28, 2024
1 parent b4d32b7 commit 2e2046a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
mcVersion=1.20-R0.1-SNAPSHOT

org.gradle.parallel=true
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
});
}

Expand All @@ -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);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
*/
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;
import me.machinemaker.papertweaks.modules.ModuleLifecycle;
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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2e2046a

Please sign in to comment.