From ca37e18dd7aa3ac1d860b0abcbb4f6277845a6d2 Mon Sep 17 00:00:00 2001 From: Cassy-Lee <104408348+Cassy-Lee@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:58:23 -0600 Subject: [PATCH] Wthit Integration --- build.gradle | 14 +++++++++++ gradle.properties | 4 +++ .../wthit/SlimefunBlockComponentProvider.java | 25 +++++++++++++++++++ .../compat/wthit/WthitIntegration.java | 16 ++++++++++++ src/main/resources/wthit_plugins.json | 9 +++++++ 5 files changed, 68 insertions(+) create mode 100644 src/main/java/me/justahuman/slimefun_essentials/compat/wthit/SlimefunBlockComponentProvider.java create mode 100644 src/main/java/me/justahuman/slimefun_essentials/compat/wthit/WthitIntegration.java create mode 100644 src/main/resources/wthit_plugins.json diff --git a/build.gradle b/build.gradle index c216057..2c53066 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,16 @@ repositories { includeGroup "maven.modrinth" } } + + maven { + name = "WTHIT" + url = "https://maven2.bai.lol" + content { + includeGroup "lol.bai" + includeGroup "mcp.mobius.waila" + } + } + mavenCentral() } @@ -50,6 +60,10 @@ dependencies { modImplementation "curse.maven:jade-324717:${project.jade_version}" + modCompileOnly "mcp.mobius.waila:wthit-api:fabric-${project.wthit_version}" + modRuntimeOnly "mcp.mobius.waila:wthit:fabric-${project.wthit_version}" + modRuntimeOnly "lol.bai:badpackets:fabric-${project.badpackets_version}" + modImplementation ("dev.emi:emi-fabric:${project.emi_version}") { exclude(group: "net.fabricmc.fabric-api") } diff --git a/gradle.properties b/gradle.properties index 6b005a1..e944d37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,6 +31,10 @@ rei_version=16.0.788 # https://www.curseforge.com/minecraft/mc-mods/jade/files?page=1&pageSize=20&gameVersionTypeId=4 jade_version=5884237 +# https://docs.bai.lol/wthit/plugin/getting_started/ +wthit_version=12.4.3 +badpackets_version=0.8.1 + # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/ mod_menu_version=10.0.0 diff --git a/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/SlimefunBlockComponentProvider.java b/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/SlimefunBlockComponentProvider.java new file mode 100644 index 0000000..2cfd0ed --- /dev/null +++ b/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/SlimefunBlockComponentProvider.java @@ -0,0 +1,25 @@ +package me.justahuman.slimefun_essentials.compat.wthit; + +import mcp.mobius.waila.api.IBlockAccessor; +import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import me.justahuman.slimefun_essentials.client.ResourceLoader; +import me.justahuman.slimefun_essentials.client.SlimefunItemStack; +import me.justahuman.slimefun_essentials.utils.Utils; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; + +public class SlimefunBlockComponentProvider implements IBlockComponentProvider { + @Override + public void appendDataContext(IDataWriter ctx, IBlockAccessor accessor, IPluginConfig config) { + if (!Utils.shouldFunction()) return; + final BlockPos blockPos = accessor.getPosition(); + if (!ResourceLoader.isSlimefunItem(blockPos)) return; + final String id = ResourceLoader.getPlacedId(blockPos).toUpperCase(); + final SlimefunItemStack slimefunItem = ResourceLoader.getSlimefunItem(id); + if (slimefunItem == null) return; + final Text itemName = slimefunItem.itemStack().getName(); + ctx.raw().putString("customName", itemName.getString()); + } +} diff --git a/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/WthitIntegration.java b/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/WthitIntegration.java new file mode 100644 index 0000000..0894d6e --- /dev/null +++ b/src/main/java/me/justahuman/slimefun_essentials/compat/wthit/WthitIntegration.java @@ -0,0 +1,16 @@ +package me.justahuman.slimefun_essentials.compat.wthit; + +import mcp.mobius.waila.api.IClientRegistrar; +import mcp.mobius.waila.api.IWailaClientPlugin; +import me.justahuman.slimefun_essentials.config.ModConfig; + +@SuppressWarnings("unused") +class WthitIntegration implements IWailaClientPlugin { + @Override + public void register(IClientRegistrar registration) { + if (!ModConfig.blockFeatures()) { + return; + } + registration.dataContext(new SlimefunBlockComponentProvider(), SlimefunBlockComponentProvider.class); + } +} diff --git a/src/main/resources/wthit_plugins.json b/src/main/resources/wthit_plugins.json new file mode 100644 index 0000000..3bc83bc --- /dev/null +++ b/src/main/resources/wthit_plugins.json @@ -0,0 +1,9 @@ +{ + "slimefun_essentials:wthit_plugin": { + "entrypoints" : { + "client": "me.justahuman.slimefun_essentials.compat.wthit.WthitIntegration" + }, + "side": "client", + "defaultEnabled": true + } +}