From b2846a44bdae67361dd38a2395c4faa45da667f7 Mon Sep 17 00:00:00 2001 From: deirn Date: Tue, 13 Aug 2024 01:49:09 +0700 Subject: [PATCH] split off into common and client sided plugin entrypoint --- .../waila/fabric/FabricCommonService.java | 8 +- .../waila/fabric/FabricPluginLoader.java | 16 +- .../src/main/resources/waila_plugins.json | 29 +- .../plugin/fabric/FabricClientPlugin.java | 7 + .../plugin/fabric/FabricCommonPlugin.java | 6 + .../plugin/fabric/WailaPluginFabric.java | 7 - .../mcp/mobius/waila/api/WailaPlugin.java | 2 +- .../waila/forge/ForgeCommonService.java | 8 +- .../mobius/waila/forge/ForgePluginLoader.java | 13 +- .../src/main/resources/waila_plugins.json | 25 +- ...luginForge.java => ForgeClientPlugin.java} | 15 +- .../waila/plugin/forge/ForgeCommonPlugin.java | 19 + .../mobius/waila/neo/NeoCommonService.java | 8 +- .../neo/src/main/resources/waila_plugins.json | 25 +- ...ilaPluginNeo.java => NeoClientPlugin.java} | 15 +- .../waila/plugin/neo/NeoCommonPlugin.java | 19 + ...nTextile.java => TextileClientPlugin.java} | 13 +- .../plugin/textile/TextileCommonPlugin.java | 17 + ...java => TeamRebornEnergyCommonPlugin.java} | 8 +- .../waila/api/IBlockComponentProvider.java | 20 +- .../mobius/waila/api/IClientRegistrar.java | 262 ++++++++ .../mobius/waila/api/ICommonRegistrar.java | 446 +++++++++++++ src/api/java/mcp/mobius/waila/api/IData.java | 2 +- .../mcp/mobius/waila/api/IDataProvider.java | 7 +- .../waila/api/IEntityComponentProvider.java | 20 +- .../mcp/mobius/waila/api/IEventListener.java | 4 +- .../mcp/mobius/waila/api/IPluginInfo.java | 5 + .../waila/api/IRayCastVectorProvider.java | 2 +- .../java/mcp/mobius/waila/api/IRegistrar.java | 592 ++---------------- .../mobius/waila/api/IWailaClientPlugin.java | 15 + .../mobius/waila/api/IWailaCommonPlugin.java | 12 + .../mcp/mobius/waila/api/IWailaPlugin.java | 41 +- .../mcp/mobius/waila/api/WailaConstants.java | 6 +- .../waila/api/data/BlockingDataProvider.java | 4 +- .../mcp/mobius/waila/api/data/EnergyData.java | 4 +- .../mcp/mobius/waila/api/package-info.java | 45 +- src/main/java/mcp/mobius/waila/Waila.java | 4 +- .../mobius/waila/command/CommonCommand.java | 6 +- .../common/s2c/PluginSyncCommonS2CPacket.java | 5 +- .../mcp/mobius/waila/plugin/PluginInfo.java | 128 +++- .../mcp/mobius/waila/plugin/PluginLoader.java | 60 +- .../mcp/mobius/waila/plugin/PluginSide.java | 20 + .../mcp/mobius/waila/registry/Registrar.java | 5 +- .../mcp/mobius/waila/service/ApiService.java | 6 +- .../mobius/waila/service/ICommonService.java | 4 +- src/main/java/mcp/mobius/waila/util/Log.java | 1 + ...aPluginCore.java => CoreClientPlugin.java} | 20 +- .../waila/plugin/core/CoreCommonPlugin.java | 26 + .../plugin/core/provider/BlockProvider.java | 17 +- .../data/NameableBlockDataProvider.java | 24 + .../waila/plugin/extra/ExtraPlugin.java | 36 ++ .../waila/plugin/extra/WailaPluginExtra.java | 20 - .../plugin/extra/provider/DataProvider.java | 19 +- .../plugin/extra/provider/EnergyProvider.java | 4 +- .../plugin/extra/provider/FluidProvider.java | 9 +- .../plugin/extra/provider/ItemProvider.java | 4 +- .../plugin/harvest/HarvestClientPlugin.java | 17 + ...nHarvest.java => HarvestCommonPlugin.java} | 13 +- .../waila/plugin/test/WailaPluginTest.java | 2 +- ...nVanilla.java => VanillaClientPlugin.java} | 118 +--- .../plugin/vanilla/VanillaCommonPlugin.java | 154 +++++ .../vanilla/provider/BeaconProvider.java | 54 +- .../plugin/vanilla/provider/BeeProvider.java | 40 +- .../vanilla/provider/BeehiveProvider.java | 79 +-- .../provider/ChiseledBookShelfProvider.java | 47 +- .../provider/EntityAttributesProvider.java | 15 +- .../vanilla/provider/JukeboxProvider.java | 20 +- .../vanilla/provider/MobEffectProvider.java | 46 +- .../vanilla/provider/MobTimerProvider.java | 12 +- .../vanilla/provider/PetOwnerProvider.java | 14 +- .../BaseContainerDataProvider.java} | 4 +- .../provider/data/BeaconDataProvider.java | 51 ++ .../provider/data/BeeDataProvider.java | 43 ++ .../provider/data/BeehiveDataProvider.java | 72 +++ .../data/ChiseledBookShelfDataProvider.java | 51 ++ .../ContainerEntityDataProvider.java} | 4 +- .../EnderChestDataProvider.java} | 4 +- .../data/EntityAttributesDataProvider.java | 24 + .../FurnaceDataProvider.java} | 4 +- .../HopperContainerDataProvider.java} | 4 +- .../provider/data/JukeboxDataProvider.java | 29 + .../provider/data/MobEffectDataProvider.java | 49 ++ .../provider/data/MobTimerDataProvider.java | 19 + .../provider/data/PetOwnerDataProvider.java | 23 + .../RandomizableContainerDataProvider.java} | 4 +- 85 files changed, 1958 insertions(+), 1223 deletions(-) create mode 100644 platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricClientPlugin.java create mode 100644 platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricCommonPlugin.java delete mode 100644 platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/WailaPluginFabric.java rename platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/{WailaPluginForge.java => ForgeClientPlugin.java} (77%) create mode 100644 platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeCommonPlugin.java rename platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/{WailaPluginNeo.java => NeoClientPlugin.java} (77%) create mode 100644 platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java rename platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/{WailaPluginTextile.java => TextileClientPlugin.java} (81%) create mode 100644 platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileCommonPlugin.java rename platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/{WailaPluginTeamRebornEnergy.java => TeamRebornEnergyCommonPlugin.java} (56%) create mode 100644 src/api/java/mcp/mobius/waila/api/IClientRegistrar.java create mode 100644 src/api/java/mcp/mobius/waila/api/ICommonRegistrar.java create mode 100644 src/api/java/mcp/mobius/waila/api/IWailaClientPlugin.java create mode 100644 src/api/java/mcp/mobius/waila/api/IWailaCommonPlugin.java create mode 100644 src/main/java/mcp/mobius/waila/plugin/PluginSide.java rename src/pluginCore/java/mcp/mobius/waila/plugin/core/{WailaPluginCore.java => CoreClientPlugin.java} (70%) create mode 100644 src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreCommonPlugin.java create mode 100644 src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/data/NameableBlockDataProvider.java create mode 100644 src/pluginExtra/java/mcp/mobius/waila/plugin/extra/ExtraPlugin.java delete mode 100644 src/pluginExtra/java/mcp/mobius/waila/plugin/extra/WailaPluginExtra.java create mode 100644 src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/HarvestClientPlugin.java rename src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/{WailaPluginHarvest.java => HarvestCommonPlugin.java} (52%) rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/{WailaPluginVanilla.java => VanillaClientPlugin.java} (57%) create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/VanillaCommonPlugin.java rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{BaseContainerProvider.java => data/BaseContainerDataProvider.java} (83%) create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeaconDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeeDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeehiveDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ChiseledBookShelfDataProvider.java rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{ContainerEntityProvider.java => data/ContainerEntityDataProvider.java} (86%) rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{EnderChestProvider.java => data/EnderChestDataProvider.java} (80%) create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EntityAttributesDataProvider.java rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{FurnaceProvider.java => data/FurnaceDataProvider.java} (88%) rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{HopperContainerProvider.java => data/HopperContainerDataProvider.java} (84%) create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobEffectDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobTimerDataProvider.java create mode 100644 src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/PetOwnerDataProvider.java rename src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/{RandomizableContainerProvider.java => data/RandomizableContainerDataProvider.java} (81%) diff --git a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricCommonService.java b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricCommonService.java index 801f8f892..1d405a9fd 100644 --- a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricCommonService.java +++ b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricCommonService.java @@ -3,8 +3,8 @@ import java.nio.file.Path; import java.util.Optional; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.WailaConstants; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.service.ICommonService; import mcp.mobius.waila.util.ModInfo; import net.fabricmc.loader.api.FabricLoader; @@ -40,10 +40,10 @@ public boolean isDev() { } @Override - public IPluginInfo.Side getSide() { + public PluginSide getSide() { return switch (FabricLoader.getInstance().getEnvironmentType()) { - case CLIENT -> IPluginInfo.Side.CLIENT; - case SERVER -> IPluginInfo.Side.SERVER; + case CLIENT -> PluginSide.CLIENT; + case SERVER -> PluginSide.DEDICATED_SERVER; }; } diff --git a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricPluginLoader.java b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricPluginLoader.java index 2b4a45b7e..b35ab8a21 100644 --- a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricPluginLoader.java +++ b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricPluginLoader.java @@ -6,9 +6,9 @@ import com.google.common.collect.Streams; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.plugin.PluginInfo; import mcp.mobius.waila.plugin.PluginLoader; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.util.Log; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; @@ -81,26 +81,26 @@ protected void gatherPlugins() { var initializer = plugin.get("initializer").getAsString(); var sideStr = plugin.containsKey("environment") ? plugin.get("environment").getAsString() : "both"; - IPluginInfo.Side side; + PluginSide side; switch (sideStr) { - case "client" -> side = IPluginInfo.Side.CLIENT; - case "server" -> side = IPluginInfo.Side.SERVER; - case "both" -> side = IPluginInfo.Side.BOTH; + case "client" -> side = PluginSide.CLIENT; + case "server" -> side = PluginSide.DEDICATED_SERVER; + case "both" -> side = PluginSide.COMMON; default -> { LOG.error("Environment for plugin {} is not valid, must be one of [client, server, both].", id); continue; } } - if (side == IPluginInfo.Side.CLIENT && FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) { + if (side == PluginSide.CLIENT && FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) { continue; } - if (side == IPluginInfo.Side.SERVER && FabricLoader.getInstance().getEnvironmentType() != EnvType.SERVER) { + if (side == PluginSide.DEDICATED_SERVER && FabricLoader.getInstance().getEnvironmentType() != EnvType.SERVER) { continue; } - PluginInfo.register(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true, true); + PluginInfo.registerDeprecated(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true, true); } } } diff --git a/platform/fabric/src/main/resources/waila_plugins.json b/platform/fabric/src/main/resources/waila_plugins.json index 043905e95..7c5040f43 100644 --- a/platform/fabric/src/main/resources/waila_plugins.json +++ b/platform/fabric/src/main/resources/waila_plugins.json @@ -1,36 +1,53 @@ { "waila:core" : { - "initializer": "mcp.mobius.waila.plugin.core.WailaPluginCore", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.core.CoreCommonPlugin", + "client": "mcp.mobius.waila.plugin.core.CoreClientPlugin" + }, "side" : "*", "required" : [] }, "waila:vanilla" : { - "initializer": "mcp.mobius.waila.plugin.vanilla.WailaPluginVanilla", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.vanilla.VanillaCommonPlugin", + "client": "mcp.mobius.waila.plugin.vanilla.VanillaClientPlugin" + }, "side" : "*", "required" : ["minecraft"] }, "waila:harvest" : { - "initializer": "mcp.mobius.waila.plugin.harvest.WailaPluginHarvest", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.harvest.HarvestCommonPlugin", + "client": "mcp.mobius.waila.plugin.harvest.HarvestClientPlugin" + }, "side" : "*", "required" : [] }, "waila:extra" : { - "initializer": "mcp.mobius.waila.plugin.extra.WailaPluginExtra", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.extra.ExtraPlugin", + "client": "mcp.mobius.waila.plugin.extra.ExtraPlugin" + }, "side" : "*", "required" : [] }, "waila:fabric" : { - "initializer": "mcp.mobius.waila.plugin.fabric.WailaPluginFabric", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.fabric.FabricCommonPlugin", + "client": "mcp.mobius.waila.plugin.fabric.FabricClientPlugin" + }, "side" : "*", "required" : ["fabric-api"] }, "waila:team_reborn_energy": { - "initializer": "mcp.mobius.waila.plugin.trenergy.WailaPluginTeamRebornEnergy", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.trenergy.TeamRebornCommonPlugin" + }, "side" : "*", "required" : ["team_reborn_energy"] } diff --git a/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricClientPlugin.java b/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricClientPlugin.java new file mode 100644 index 000000000..bb01f0921 --- /dev/null +++ b/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricClientPlugin.java @@ -0,0 +1,7 @@ +package mcp.mobius.waila.plugin.fabric; + +import mcp.mobius.waila.plugin.textile.TextileClientPlugin; + +public class FabricClientPlugin extends TextileClientPlugin { + +} diff --git a/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricCommonPlugin.java b/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricCommonPlugin.java new file mode 100644 index 000000000..3b1c329f9 --- /dev/null +++ b/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/FabricCommonPlugin.java @@ -0,0 +1,6 @@ +package mcp.mobius.waila.plugin.fabric; + +import mcp.mobius.waila.plugin.textile.TextileCommonPlugin; + +public class FabricCommonPlugin extends TextileCommonPlugin { +} diff --git a/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/WailaPluginFabric.java b/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/WailaPluginFabric.java deleted file mode 100644 index 5b5519ddc..000000000 --- a/platform/fabric/src/plugin/java/mcp/mobius/waila/plugin/fabric/WailaPluginFabric.java +++ /dev/null @@ -1,7 +0,0 @@ -package mcp.mobius.waila.plugin.fabric; - -import mcp.mobius.waila.plugin.textile.WailaPluginTextile; - -public class WailaPluginFabric extends WailaPluginTextile { - -} diff --git a/platform/forge/src/api/java/mcp/mobius/waila/api/WailaPlugin.java b/platform/forge/src/api/java/mcp/mobius/waila/api/WailaPlugin.java index 46a971537..008bc04b2 100644 --- a/platform/forge/src/api/java/mcp/mobius/waila/api/WailaPlugin.java +++ b/platform/forge/src/api/java/mcp/mobius/waila/api/WailaPlugin.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.ApiStatus; /** - * @deprecated use {@code waila_plugins.json} file, see {@link IWailaPlugin} javadocs for more info. + * @deprecated use {@code waila_plugins.json} file, see {@link mcp.mobius.waila.api} javadocs for more info. */ @Deprecated @Documented diff --git a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeCommonService.java b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeCommonService.java index d11d81e39..e86880bd9 100644 --- a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeCommonService.java +++ b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeCommonService.java @@ -3,8 +3,8 @@ import java.nio.file.Path; import java.util.Optional; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.WailaConstants; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.service.ICommonService; import mcp.mobius.waila.util.ModInfo; import net.minecraftforge.fml.ModContainer; @@ -43,10 +43,10 @@ public boolean isDev() { } @Override - public IPluginInfo.Side getSide() { + public PluginSide getSide() { return switch (FMLLoader.getDist()) { - case CLIENT -> IPluginInfo.Side.CLIENT; - case DEDICATED_SERVER -> IPluginInfo.Side.SERVER; + case CLIENT -> PluginSide.CLIENT; + case DEDICATED_SERVER -> PluginSide.DEDICATED_SERVER; }; } diff --git a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java index c4c5e720d..b65946403 100644 --- a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java +++ b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java @@ -7,6 +7,7 @@ import mcp.mobius.waila.api.WailaPlugin; import mcp.mobius.waila.plugin.PluginInfo; import mcp.mobius.waila.plugin.PluginLoader; +import mcp.mobius.waila.plugin.PluginSide; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.loading.FMLLoader; @@ -30,23 +31,27 @@ protected void gatherPlugins() { if (annotation.annotationType().getClassName().equals(WAILA_PLUGIN)) { var id = (String) annotation.annotationData().get("id"); var required = (String[]) annotation.annotationData().getOrDefault("required", new String[0]); - var side = (IPluginInfo.Side) annotation.annotationData().get("side"); + var side = switch ((IPluginInfo.Side) annotation.annotationData().get("side")) { + case CLIENT -> PluginSide.CLIENT; + case SERVER -> PluginSide.DEDICATED_SERVER; + case BOTH -> PluginSide.COMMON; + }; var satisfied = true; for (var dep : required) { satisfied = satisfied && ModList.get().isLoaded(dep); } - if (side == IPluginInfo.Side.CLIENT && FMLLoader.getDist() != Dist.CLIENT) { + if (side == PluginSide.CLIENT && FMLLoader.getDist() != Dist.CLIENT) { satisfied = false; } - if (side == IPluginInfo.Side.SERVER && FMLLoader.getDist() != Dist.DEDICATED_SERVER) { + if (side == PluginSide.DEDICATED_SERVER && FMLLoader.getDist() != Dist.DEDICATED_SERVER) { satisfied = false; } if (satisfied) { - PluginInfo.register(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true, true); + PluginInfo.registerDeprecated(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true, true); } } } diff --git a/platform/forge/src/main/resources/waila_plugins.json b/platform/forge/src/main/resources/waila_plugins.json index d3cfe65b7..e75d68a24 100644 --- a/platform/forge/src/main/resources/waila_plugins.json +++ b/platform/forge/src/main/resources/waila_plugins.json @@ -1,30 +1,45 @@ { "waila:core" : { - "initializer": "mcp.mobius.waila.plugin.core.WailaPluginCore", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.core.CoreCommonPlugin", + "client": "mcp.mobius.waila.plugin.core.CoreClientPlugin" + }, "side" : "*", "required" : [] }, "waila:vanilla": { - "initializer": "mcp.mobius.waila.plugin.vanilla.WailaPluginVanilla", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.vanilla.VanillaCommonPlugin", + "client": "mcp.mobius.waila.plugin.vanilla.VanillaClientPlugin" + }, "side" : "*", "required" : ["minecraft"] }, "waila:harvest": { - "initializer": "mcp.mobius.waila.plugin.harvest.WailaPluginHarvest", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.harvest.HarvestCommonPlugin", + "client": "mcp.mobius.waila.plugin.harvest.HarvestClientPlugin" + }, "side" : "*", "required" : [] }, "waila:extra" : { - "initializer": "mcp.mobius.waila.plugin.extra.WailaPluginExtra", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.extra.ExtraPlugin", + "client": "mcp.mobius.waila.plugin.extra.ExtraPlugin" + }, "side" : "*", "required" : [] }, "waila:forge" : { - "initializer": "mcp.mobius.waila.plugin.forge.WailaPluginForge", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.forge.ForgeCommonPlugin", + "client": "mcp.mobius.waila.plugin.forge.ForgeClientPlugin" + }, "side" : "*", "required" : ["forge"] } diff --git a/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/WailaPluginForge.java b/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeClientPlugin.java similarity index 77% rename from platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/WailaPluginForge.java rename to platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeClientPlugin.java index 4b2480c18..9249ed6ed 100644 --- a/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/WailaPluginForge.java +++ b/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeClientPlugin.java @@ -1,30 +1,23 @@ package mcp.mobius.waila.plugin.forge; -import mcp.mobius.waila.api.IRegistrar; +import mcp.mobius.waila.api.IClientRegistrar; import mcp.mobius.waila.api.IToolType; -import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.IWailaClientPlugin; import mcp.mobius.waila.api.data.FluidData; import mcp.mobius.waila.plugin.forge.fluid.ForgeFluidDescriptor; -import mcp.mobius.waila.plugin.forge.provider.EnergyCapabilityProvider; -import mcp.mobius.waila.plugin.forge.provider.FluidCapabilityProvider; -import mcp.mobius.waila.plugin.forge.provider.ItemCapabilityProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.DoublePlantBlock; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; import net.minecraftforge.common.IForgeShearable; import net.minecraftforge.common.ToolActions; -public class WailaPluginForge implements IWailaPlugin { +public class ForgeClientPlugin implements IWailaClientPlugin { @Override - public void register(IRegistrar registrar) { + public void register(IClientRegistrar registrar) { FluidData.describeFluid(Fluid.class, ForgeFluidDescriptor.INSTANCE); - registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000); registrar.addToolType(ResourceLocation.withDefaultNamespace("pickaxe"), IToolType.builder() .lowestTierItem(Items.WOODEN_PICKAXE) diff --git a/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeCommonPlugin.java b/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeCommonPlugin.java new file mode 100644 index 000000000..db5aec990 --- /dev/null +++ b/platform/forge/src/plugin/java/mcp/mobius/waila/plugin/forge/ForgeCommonPlugin.java @@ -0,0 +1,19 @@ +package mcp.mobius.waila.plugin.forge; + +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaCommonPlugin; +import mcp.mobius.waila.plugin.forge.provider.EnergyCapabilityProvider; +import mcp.mobius.waila.plugin.forge.provider.FluidCapabilityProvider; +import mcp.mobius.waila.plugin.forge.provider.ItemCapabilityProvider; +import net.minecraft.world.level.block.entity.BlockEntity; + +public class ForgeCommonPlugin implements IWailaCommonPlugin { + + @Override + public void register(ICommonRegistrar registrar) { + registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + } + +} diff --git a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoCommonService.java b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoCommonService.java index d30c41293..4d005d176 100644 --- a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoCommonService.java +++ b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoCommonService.java @@ -3,8 +3,8 @@ import java.nio.file.Path; import java.util.Optional; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.WailaConstants; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.service.ICommonService; import mcp.mobius.waila.util.ModInfo; import net.neoforged.fml.ModContainer; @@ -43,10 +43,10 @@ public boolean isDev() { } @Override - public IPluginInfo.Side getSide() { + public PluginSide getSide() { return switch (FMLLoader.getDist()) { - case CLIENT -> IPluginInfo.Side.CLIENT; - case DEDICATED_SERVER -> IPluginInfo.Side.SERVER; + case CLIENT -> PluginSide.CLIENT; + case DEDICATED_SERVER -> PluginSide.DEDICATED_SERVER; }; } diff --git a/platform/neo/src/main/resources/waila_plugins.json b/platform/neo/src/main/resources/waila_plugins.json index 6b469b6ca..b4fd99d15 100644 --- a/platform/neo/src/main/resources/waila_plugins.json +++ b/platform/neo/src/main/resources/waila_plugins.json @@ -1,30 +1,45 @@ { "waila:core" : { - "initializer": "mcp.mobius.waila.plugin.core.WailaPluginCore", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.core.CoreCommonPlugin", + "client": "mcp.mobius.waila.plugin.core.CoreClientPlugin" + }, "side" : "*", "required" : [] }, "waila:vanilla": { - "initializer": "mcp.mobius.waila.plugin.vanilla.WailaPluginVanilla", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.vanilla.VanillaCommonPlugin", + "client": "mcp.mobius.waila.plugin.vanilla.VanillaClientPlugin" + }, "side" : "*", "required" : ["minecraft"] }, "waila:harvest": { - "initializer": "mcp.mobius.waila.plugin.harvest.WailaPluginHarvest", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.harvest.HarvestCommonPlugin", + "client": "mcp.mobius.waila.plugin.harvest.HarvestClientPlugin" + }, "side" : "*", "required" : [] }, "waila:extra" : { - "initializer": "mcp.mobius.waila.plugin.extra.WailaPluginExtra", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.extra.ExtraPlugin", + "client": "mcp.mobius.waila.plugin.extra.ExtraPlugin" + }, "side" : "*", "required" : [] }, "waila:neo" : { - "initializer": "mcp.mobius.waila.plugin.neo.WailaPluginNeo", + "entrypoints": { + "common": "mcp.mobius.waila.plugin.neo.NeoCommonPlugin", + "client": "mcp.mobius.waila.plugin.neo.NeoClientPlugin" + }, "side" : "*", "required" : ["neoforge"] } diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/WailaPluginNeo.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoClientPlugin.java similarity index 77% rename from platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/WailaPluginNeo.java rename to platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoClientPlugin.java index 6b1278e00..be8640e28 100644 --- a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/WailaPluginNeo.java +++ b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoClientPlugin.java @@ -1,30 +1,23 @@ package mcp.mobius.waila.plugin.neo; -import mcp.mobius.waila.api.IRegistrar; +import mcp.mobius.waila.api.IClientRegistrar; import mcp.mobius.waila.api.IToolType; -import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.IWailaClientPlugin; import mcp.mobius.waila.api.data.FluidData; import mcp.mobius.waila.plugin.neo.fluid.NeoFluidDescriptor; -import mcp.mobius.waila.plugin.neo.provider.EnergyCapabilityProvider; -import mcp.mobius.waila.plugin.neo.provider.FluidCapabilityProvider; -import mcp.mobius.waila.plugin.neo.provider.ItemCapabilityProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.DoublePlantBlock; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; import net.neoforged.neoforge.common.IShearable; import net.neoforged.neoforge.common.ItemAbilities; -public class WailaPluginNeo implements IWailaPlugin { +public class NeoClientPlugin implements IWailaClientPlugin { @Override - public void register(IRegistrar registrar) { + public void register(IClientRegistrar registrar) { FluidData.describeFluid(Fluid.class, NeoFluidDescriptor.INSTANCE); - registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000); registrar.addToolType(ResourceLocation.withDefaultNamespace("pickaxe"), IToolType.builder() .lowestTierItem(Items.WOODEN_PICKAXE) diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java new file mode 100644 index 000000000..75bd4486f --- /dev/null +++ b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java @@ -0,0 +1,19 @@ +package mcp.mobius.waila.plugin.neo; + +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaCommonPlugin; +import mcp.mobius.waila.plugin.neo.provider.EnergyCapabilityProvider; +import mcp.mobius.waila.plugin.neo.provider.FluidCapabilityProvider; +import mcp.mobius.waila.plugin.neo.provider.ItemCapabilityProvider; +import net.minecraft.world.level.block.entity.BlockEntity; + +public class NeoCommonPlugin implements IWailaCommonPlugin { + + @Override + public void register(ICommonRegistrar registrar) { + registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000); + } + +} diff --git a/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/WailaPluginTextile.java b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileClientPlugin.java similarity index 81% rename from platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/WailaPluginTextile.java rename to platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileClientPlugin.java index b91eccc18..9924e9d66 100644 --- a/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/WailaPluginTextile.java +++ b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileClientPlugin.java @@ -1,13 +1,11 @@ package mcp.mobius.waila.plugin.textile; -import mcp.mobius.waila.api.IRegistrar; +import mcp.mobius.waila.api.IClientRegistrar; import mcp.mobius.waila.api.IToolType; -import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.IWailaClientPlugin; import mcp.mobius.waila.api.data.FluidData; import mcp.mobius.waila.mixed.IShearable; import mcp.mobius.waila.plugin.textile.fluid.TextileFluidDescriptor; -import mcp.mobius.waila.plugin.textile.provider.FluidStorageProvider; -import mcp.mobius.waila.plugin.textile.provider.ItemStorageProvider; import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; @@ -15,17 +13,14 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.DoublePlantBlock; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; -public abstract class WailaPluginTextile implements IWailaPlugin { +public abstract class TextileClientPlugin implements IWailaClientPlugin { @Override - public void register(IRegistrar registrar) { + public void register(IClientRegistrar registrar) { FluidData.describeFluid(Fluid.class, TextileFluidDescriptor.INSTANCE); FluidData.describeCauldron(Block.class, TextileFluidDescriptor.INSTANCE); - registrar.addBlockData(ItemStorageProvider.INSTANCE, BlockEntity.class, 2000); - registrar.addBlockData(FluidStorageProvider.INSTANCE, BlockEntity.class, 2000); registrar.addToolType(ResourceLocation.withDefaultNamespace("pickaxe"), IToolType.builder() .lowestTierItem(Items.WOODEN_PICKAXE) diff --git a/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileCommonPlugin.java b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileCommonPlugin.java new file mode 100644 index 000000000..a0252ec5b --- /dev/null +++ b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/textile/TextileCommonPlugin.java @@ -0,0 +1,17 @@ +package mcp.mobius.waila.plugin.textile; + +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaCommonPlugin; +import mcp.mobius.waila.plugin.textile.provider.FluidStorageProvider; +import mcp.mobius.waila.plugin.textile.provider.ItemStorageProvider; +import net.minecraft.world.level.block.entity.BlockEntity; + +public abstract class TextileCommonPlugin implements IWailaCommonPlugin { + + @Override + public void register(ICommonRegistrar registrar) { + registrar.addBlockData(ItemStorageProvider.INSTANCE, BlockEntity.class, 2000); + registrar.addBlockData(FluidStorageProvider.INSTANCE, BlockEntity.class, 2000); + } + +} diff --git a/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/WailaPluginTeamRebornEnergy.java b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/TeamRebornEnergyCommonPlugin.java similarity index 56% rename from platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/WailaPluginTeamRebornEnergy.java rename to platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/TeamRebornEnergyCommonPlugin.java index b0fa8f7db..64cb4c8c1 100644 --- a/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/WailaPluginTeamRebornEnergy.java +++ b/platform/textile/src/plugin/java/mcp/mobius/waila/plugin/trenergy/TeamRebornEnergyCommonPlugin.java @@ -1,14 +1,14 @@ package mcp.mobius.waila.plugin.trenergy; -import mcp.mobius.waila.api.IRegistrar; -import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaCommonPlugin; import mcp.mobius.waila.plugin.trenergy.provider.EnergyStorageProvider; import net.minecraft.world.level.block.entity.BlockEntity; -public class WailaPluginTeamRebornEnergy implements IWailaPlugin { +public class TeamRebornEnergyCommonPlugin implements IWailaCommonPlugin { @Override - public void register(IRegistrar registrar) { + public void register(ICommonRegistrar registrar) { registrar.addBlockData(EnergyStorageProvider.INSTANCE, BlockEntity.class, 2000); } diff --git a/src/api/java/mcp/mobius/waila/api/IBlockComponentProvider.java b/src/api/java/mcp/mobius/waila/api/IBlockComponentProvider.java index f98e8b6f3..8ab64ccca 100644 --- a/src/api/java/mcp/mobius/waila/api/IBlockComponentProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IBlockComponentProvider.java @@ -12,10 +12,10 @@ * Used to provide {@link Block}/{@link BlockEntity} tooltip information to Waila. *

* All methods in this interface shouldn't to be called by the implementing mod. - * An instance of the class is to be registered via the {@link IRegistrar} instance provided in {@link IWailaPlugin}. + * An instance of the class is to be registered via the {@link IClientRegistrar} instance provided in {@link IWailaClientPlugin}. * - * @see IWailaPlugin - * @see IRegistrar + * @see IWailaClientPlugin + * @see IClientRegistrar */ @ApiSide.ClientOnly @ApiStatus.OverrideOnly @@ -39,7 +39,7 @@ public interface IBlockComponentProvider { * @return {@code null} if this method doesn't redirect to anything, * any result from one of {@link ITargetRedirector}'s methods otherwise * - * @see IRegistrar#addRedirect(IBlockComponentProvider, Class) + * @see IClientRegistrar#addRedirect(IBlockComponentProvider, Class) */ @Nullable @ApiStatus.Experimental @@ -55,7 +55,7 @@ default ITargetRedirector.Result redirect(ITargetRedirector redirect, IBlockAcce * Note that {@link IBlockAccessor#getData()} will always be empty at this time * @param config current plugin configuration * - * @see IRegistrar#addDataContext(IBlockComponentProvider, Class) + * @see IClientRegistrar#addDataContext(IBlockComponentProvider, Class) */ default void appendDataContext(IDataWriter ctx, IBlockAccessor accessor, IPluginConfig config) { } @@ -73,7 +73,7 @@ default void appendDataContext(IDataWriter ctx, IBlockAccessor accessor, IPlugin * * @return {@code null} if override is not required, a {@link BlockState} otherwise * - * @see IRegistrar#addOverride(IBlockComponentProvider, Class, int) + * @see IClientRegistrar#addOverride(IBlockComponentProvider, Class, int) * @see #EMPTY_BLOCK_STATE */ @Nullable @@ -94,7 +94,7 @@ default BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) { * * @return the component to render or {@code null} if this provider doesn't decide it * - * @see IRegistrar#addIcon(IEntityComponentProvider, Class, int) + * @see IClientRegistrar#addIcon(IEntityComponentProvider, Class, int) */ @Nullable default ITooltipComponent getIcon(IBlockAccessor accessor, IPluginConfig config) { @@ -114,7 +114,7 @@ default ITooltipComponent getIcon(IBlockAccessor accessor, IPluginConfig config) * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) */ default void appendHead(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { } @@ -132,7 +132,7 @@ default void appendHead(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) */ default void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { } @@ -150,7 +150,7 @@ default void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IBlockComponentProvider, TooltipPosition, Class, int) */ default void appendTail(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { } diff --git a/src/api/java/mcp/mobius/waila/api/IClientRegistrar.java b/src/api/java/mcp/mobius/waila/api/IClientRegistrar.java new file mode 100644 index 000000000..b860d587c --- /dev/null +++ b/src/api/java/mcp/mobius/waila/api/IClientRegistrar.java @@ -0,0 +1,262 @@ +package mcp.mobius.waila.api; + +import lol.bai.badpackets.impl.marker.ApiSide; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntity; +import org.jetbrains.annotations.ApiStatus; + +@ApiSide.ClientOnly +@ApiStatus.NonExtendable +public interface IClientRegistrar { + + /** + * Adds an event listener + */ + void addEventListener(IEventListener listener, int priority); + + /** + * Adds an event listener + */ + void addEventListener(IEventListener listener); + + /** + * Registers an {@link IBlockComponentProvider} instance to allow redirecting the object being displayed. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiStatus.Experimental + void addRedirect(IBlockComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IBlockComponentProvider} instance to allow redirecting the object being displayed. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiStatus.Experimental + void addRedirect(IBlockComponentProvider provider, Class clazz); + + /** + * Registers an {@link IBlockComponentProvider} instance to allow overriding the block being displayed. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addOverride(IBlockComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IBlockComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} to allow overriding the block being displayed. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addOverride(IBlockComponentProvider provider, Class clazz); + + /** + * Registers an {@link IBlockComponentProvider} instance to allow overriding the displayed icon for a block via the + * {@link IBlockComponentProvider#getIcon(IBlockAccessor, IPluginConfig)} method. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addIcon(IBlockComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IBlockComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} to allow overriding the displayed icon for a block via the + * {@link IBlockComponentProvider#getIcon(IBlockAccessor, IPluginConfig)} method. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + void addIcon(IBlockComponentProvider provider, Class clazz); + + /** + * Registers an {@link IBlockComponentProvider} instance for appending {@link Component} to the tooltip. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param position the position on the tooltip this applies to + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class clazz, int priority); + + /** + * Registers an {@link IBlockComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} for appending {@link Component} to the tooltip. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param position the position on the tooltip this applies to + * @param clazz the highest level class to apply to + */ + void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class clazz); + + /** + * Registers an {@link IBlockComponentProvider} instance for appending data context that get sent to the server. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + void addDataContext(IBlockComponentProvider provider, Class clazz); + + /** + * Registers an {@link IEntityComponentProvider} instance to allow redirecting the object being displayed. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiStatus.Experimental + void addRedirect(IEntityComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IEntityComponentProvider} instance to allow redirecting the object being displayed. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiStatus.Experimental + void addRedirect(IEntityComponentProvider provider, Class clazz); + + /** + * Registers an {@link IEntityComponentProvider} instance to allow overriding the entity being displayed. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addOverride(IEntityComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IEntityComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} to allow overriding the entity being displayed. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addOverride(IEntityComponentProvider provider, Class clazz); + + /** + * Registers an {@link IEntityComponentProvider} instance to allow displaying an icon via the + * {@link IEntityComponentProvider#getIcon(IEntityAccessor, IPluginConfig)} method. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addIcon(IEntityComponentProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IEntityComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} to allow displaying an icon via the + * {@link IEntityComponentProvider#getIcon(IEntityAccessor, IPluginConfig)} method. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + void addIcon(IEntityComponentProvider provider, Class clazz); + + /** + * Registers an {@link IEntityComponentProvider} instance for appending {@link Component} to the tooltip. + * + * @param provider the data provider instance + * @param position the position on the tooltip this applies to + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class clazz, int priority); + + /** + * Registers an {@link IEntityComponentProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} for appending {@link Component} to the tooltip. + * + * @param provider the data provider instance + * @param position the position on the tooltip this applies to + * @param clazz the highest level class to apply to + */ + void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class clazz); + + /** + * Registers an {@link IEntityComponentProvider} instance for appending data context that get sent to the server. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + void addDataContext(IEntityComponentProvider provider, Class clazz); + + /** + * Registers an {@link IThemeType} instance. + * + * @param id the theme type id + * @param type the theme type + */ + @ApiStatus.Experimental + void addThemeType(ResourceLocation id, IThemeType type); + + /** + * Registers an {@link IRayCastVectorProvider} instance + * + * @param provider the vector provider + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + */ + @ApiStatus.Experimental + void addRayCastVector(IRayCastVectorProvider provider, int priority); + + /** + * Registers an {@link IRayCastVectorProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} + * + * @param provider the vector provider + */ + @ApiStatus.Experimental + void addRayCastVector(IRayCastVectorProvider provider); + + /** + * Registers a tool type, to be used for the harvestability tooltip. + * + * @param id the tool type id, also used as the translation key as {@code tooltip.waila.harvest.tool.[namespace].[path]} + * @param toolType the tool type + */ + @ApiStatus.Experimental + void addToolType(ResourceLocation id, IToolType toolType); + +} diff --git a/src/api/java/mcp/mobius/waila/api/ICommonRegistrar.java b/src/api/java/mcp/mobius/waila/api/ICommonRegistrar.java new file mode 100644 index 000000000..c7447cf1b --- /dev/null +++ b/src/api/java/mcp/mobius/waila/api/ICommonRegistrar.java @@ -0,0 +1,446 @@ +package mcp.mobius.waila.api; + +import java.nio.file.Path; + +import mcp.mobius.waila.api.__internal__.ApiSide; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.NonExtendable +public interface ICommonRegistrar { + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + */ + void addConfig(ResourceLocation key, boolean defaultValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param format used for formatting text box in plugin config screen + */ + void addConfig(ResourceLocation key, int defaultValue, IntFormat format); + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + */ + default void addConfig(ResourceLocation key, int defaultValue) { + addConfig(key, defaultValue, IntFormat.DECIMAL); + } + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + */ + void addConfig(ResourceLocation key, double defaultValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + */ + void addConfig(ResourceLocation key, String defaultValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + */ + > void addConfig(ResourceLocation key, T defaultValue); + + /** + * Adds an entry to the config screen to open a file with external editor. + *

+ * Does NOT handle file parsing, and will NOT available from {@link IPluginConfig}. + * Needs to be handled by the user manually. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param path the path to the file + * + * @see IJsonConfig + */ + void addConfig(ResourceLocation key, Path path); + + /** + * Registers a namespaced config key to be accessed within data providers. + *

+ * The main purpose of this method is for toggling feature that enabled by default. + * This method allows server to disable the option remotely for all connected clients, + * the clients can then toggle the option for their own side only if it is enabled on the server. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key to be used with {@link IPluginConfig#getBoolean(ResourceLocation)} + * @param clientOnly whether the feature available on client-only, e.g. not using {@linkplain IDataProvider server data} + */ + void addFeatureConfig(ResourceLocation key, boolean clientOnly); + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + */ + void addSyncedConfig(ResourceLocation key, boolean defaultValue, boolean clientOnlyValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + * @param format used for formatting text box in plugin config screen + */ + void addSyncedConfig(ResourceLocation key, int defaultValue, int clientOnlyValue, IntFormat format); + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + */ + default void addSyncedConfig(ResourceLocation key, int defaultValue, int clientOnlyValue) { + addSyncedConfig(key, defaultValue, clientOnlyValue, IntFormat.DECIMAL); + } + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + */ + void addSyncedConfig(ResourceLocation key, double defaultValue, double clientOnlyValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + */ + void addSyncedConfig(ResourceLocation key, String defaultValue, String clientOnlyValue); + + /** + * Registers a namespaced config key to be accessed within data providers. + * These values are sent from the server to the client upon connection. + *

+ * These translation keys will be used on the plugin config screen:

+ *

+ * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], + * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
+ * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name + * for it to be visible in the config screen. + * + * @param key the namespaced key + * @param defaultValue the default value + * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed + */ + > void addSyncedConfig(ResourceLocation key, T defaultValue, T clientOnlyValue); + + /** + * Registers config key aliases that will be migrated gracefully to the actual key. + *

+ * Also sync the value using aliased keys, so outdated client can still get the correct value. + */ + void addConfigAlias(ResourceLocation actual, ResourceLocation... aliases); + + /** + * Adds the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void addBlacklist(int priority, Block... blocks); + + /** + * Adds the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void addBlacklist(int priority, BlockEntityType... blockEntityTypes); + + /** + * Adds the specified entity types to the default blacklist. + */ + default void addBlacklist(Block... blocks) { + addBlacklist(WailaConstants.DEFAULT_PRIORITY, blocks); + } + + /** + * Adds the specified entity types to the default blacklist. + */ + default void addBlacklist(BlockEntityType... blockEntityTypes) { + addBlacklist(WailaConstants.DEFAULT_PRIORITY, blockEntityTypes); + } + + /** + * Removes the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void removeBlacklist(int priority, Block... blocks); + + /** + * Removes the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void removeBlacklist(int priority, BlockEntityType... blockEntityTypes); + + /** + * Removes the specified entity types to the default blacklist. + */ + default void removeBlacklist(Block... blocks) { + removeBlacklist(WailaConstants.DEFAULT_PRIORITY, blocks); + } + + /** + * Removes the specified entity types to the default blacklist. + */ + default void removeBlacklist(BlockEntityType... blockEntityTypes) { + removeBlacklist(WailaConstants.DEFAULT_PRIORITY, blockEntityTypes); + } + + /** + * Registers an {@link IDataProvider} instance for data syncing purposes. A {@link BlockEntity} + * is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiSide.ServerOnly + void addBlockData(IDataProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IDataProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} for data syncing purposes. + * A {@link BlockEntity} is also an acceptable class type. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + default void addBlockData(IDataProvider provider, Class clazz) { + addBlockData(provider, clazz, WailaConstants.DEFAULT_PRIORITY); + } + + /** + * Adds the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void addBlacklist(int priority, EntityType... entityTypes); + + /** + * Adds the specified entity types to the default blacklist. + */ + default void addBlacklist(EntityType... entityTypes) { + addBlacklist(WailaConstants.DEFAULT_PRIORITY, entityTypes); + } + + /** + * Removes the specified entity types to the default blacklist. + * + * @param priority the modifier priority, lower number will be called last + */ + void removeBlacklist(int priority, EntityType... entityTypes); + + /** + * Removes the specified entity types to the default blacklist. + */ + default void removeBlacklist(EntityType... entityTypes) { + removeBlacklist(WailaConstants.DEFAULT_PRIORITY, entityTypes); + } + + /** + * Registers an {@link IDataProvider} instance for data syncing purposes. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + * @param priority the priority of this provider 0 is the minimum, lower number will be called first + * + * @see WailaConstants#DEFAULT_PRIORITY + */ + @ApiSide.ServerOnly + void addEntityData(IDataProvider provider, Class clazz, int priority); + + /** + * Registers an {@link IDataProvider} instance with + * {@linkplain WailaConstants#DEFAULT_PRIORITY default priority} for data syncing purposes. + * + * @param provider the data provider instance + * @param clazz the highest level class to apply to + */ + default void addEntityData(IDataProvider provider, Class clazz) { + addEntityData(provider, clazz, WailaConstants.DEFAULT_PRIORITY); + } + + /** + * Registers a data type used for syncing data from server to client. + * + * @param type the data type + * @param codec the data-to-buffer codec + */ + void addDataType(IData.Type type, StreamCodec codec); + + +} diff --git a/src/api/java/mcp/mobius/waila/api/IData.java b/src/api/java/mcp/mobius/waila/api/IData.java index e6adb10a9..6e439bd32 100644 --- a/src/api/java/mcp/mobius/waila/api/IData.java +++ b/src/api/java/mcp/mobius/waila/api/IData.java @@ -7,7 +7,7 @@ /** * A typed data for syncing complex data. *

- * Register data types with {@link IRegistrar#addDataType} + * Register data types with {@link ICommonRegistrar#addDataType} *

* For simple data, consider using {@linkplain IDataWriter#raw() raw NBT data} instead, * as it is easier to do and enough for most purpose. diff --git a/src/api/java/mcp/mobius/waila/api/IDataProvider.java b/src/api/java/mcp/mobius/waila/api/IDataProvider.java index c3501c755..d07c35cd5 100644 --- a/src/api/java/mcp/mobius/waila/api/IDataProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IDataProvider.java @@ -16,10 +16,11 @@ public interface IDataProvider { * @param data current synchronization data * @param accessor contains the relevant context of the environment * @param config current plugin configurations, - * values could be different from the requesting client unless it was registered via {@link IRegistrar#addSyncedConfig} + * values could be different from the requesting client unless it was registered via + * {@link ICommonRegistrar#addSyncedConfig} * - * @see IRegistrar#addBlockData(IDataProvider, Class, int) - * @see IRegistrar#addEntityData(IDataProvider, Class) + * @see ICommonRegistrar#addBlockData(IDataProvider, Class, int) + * @see ICommonRegistrar#addEntityData(IDataProvider, Class) * @see IBlockComponentProvider#appendDataContext(IDataWriter, IBlockAccessor, IPluginConfig) * @see IEntityComponentProvider#appendDataContext(IDataWriter, IEntityAccessor, IPluginConfig) */ diff --git a/src/api/java/mcp/mobius/waila/api/IEntityComponentProvider.java b/src/api/java/mcp/mobius/waila/api/IEntityComponentProvider.java index ac68e4d1d..604b31470 100644 --- a/src/api/java/mcp/mobius/waila/api/IEntityComponentProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IEntityComponentProvider.java @@ -11,10 +11,10 @@ * Used to provide {@link Entity} tooltip information to Waila. *

* All methods in this interface shouldn't to be called by the implementing mod. - * An instance of the class is to be registered via the {@link IRegistrar} instance provided in {@link IWailaPlugin}. + * An instance of the class is to be registered via the {@link IClientRegistrar} instance provided in {@link IWailaClientPlugin}. * - * @see IWailaPlugin - * @see IRegistrar + * @see IWailaClientPlugin + * @see IClientRegistrar */ @ApiSide.ClientOnly @ApiStatus.OverrideOnly @@ -38,7 +38,7 @@ public interface IEntityComponentProvider { * @return {@code null} if this method doesn't redirect to anything, * any result from one of {@link ITargetRedirector}'s methods otherwise * - * @see IRegistrar#addRedirect(IEntityComponentProvider, Class) + * @see IClientRegistrar#addRedirect(IEntityComponentProvider, Class) */ @Nullable @ApiStatus.Experimental @@ -54,7 +54,7 @@ default ITargetRedirector.Result redirect(ITargetRedirector redirect, IEntityAcc * Note that {@link IEntityAccessor#getData()} will always be empty at this time * @param config current plugin configuration * - * @see IRegistrar#addDataContext(IEntityComponentProvider, Class) + * @see IClientRegistrar#addDataContext(IEntityComponentProvider, Class) */ default void appendDataContext(IDataWriter ctx, IEntityAccessor accessor, IPluginConfig config) { } @@ -67,7 +67,7 @@ default void appendDataContext(IDataWriter ctx, IEntityAccessor accessor, IPlugi * * @return {@code null} if override is not required, an {@link Entity} otherwise * - * @see IRegistrar#addOverride(IEntityComponentProvider, Class, int) + * @see IClientRegistrar#addOverride(IEntityComponentProvider, Class, int) * @see #EMPTY_ENTITY */ @Nullable @@ -88,7 +88,7 @@ default Entity getOverride(IEntityAccessor accessor, IPluginConfig config) { * * @return the component to render or {@code null} if this provider doesn't decide it * - * @see IRegistrar#addIcon(IEntityComponentProvider, Class, int) + * @see IClientRegistrar#addIcon(IEntityComponentProvider, Class, int) */ @Nullable default ITooltipComponent getIcon(IEntityAccessor accessor, IPluginConfig config) { @@ -108,7 +108,7 @@ default ITooltipComponent getIcon(IEntityAccessor accessor, IPluginConfig config * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) */ default void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { } @@ -126,7 +126,7 @@ default void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfi * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) */ default void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { } @@ -144,7 +144,7 @@ default void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfi * @param accessor contains most of the relevant information about the current environment * @param config current plugin configuration * - * @see IRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) + * @see IClientRegistrar#addComponent(IEntityComponentProvider, TooltipPosition, Class, int) */ default void appendTail(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { } diff --git a/src/api/java/mcp/mobius/waila/api/IEventListener.java b/src/api/java/mcp/mobius/waila/api/IEventListener.java index e8ffabb03..995ba1f89 100644 --- a/src/api/java/mcp/mobius/waila/api/IEventListener.java +++ b/src/api/java/mcp/mobius/waila/api/IEventListener.java @@ -9,8 +9,8 @@ /** * Used to listen to generic Waila events. - * - * Register implementations with {@link IRegistrar#addEventListener} + *

+ * Register implementations with {@link IClientRegistrar#addEventListener} */ @ApiStatus.OverrideOnly public interface IEventListener { diff --git a/src/api/java/mcp/mobius/waila/api/IPluginInfo.java b/src/api/java/mcp/mobius/waila/api/IPluginInfo.java index 5ee244ef6..50f6a92ef 100644 --- a/src/api/java/mcp/mobius/waila/api/IPluginInfo.java +++ b/src/api/java/mcp/mobius/waila/api/IPluginInfo.java @@ -7,6 +7,10 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; +/** + * @deprecated no replacement. In practice, plugin should never require this. + */ +@Deprecated @ApiStatus.NonExtendable public interface IPluginInfo { @@ -28,6 +32,7 @@ static Collection getAll() { Side getSide(); + @Deprecated IWailaPlugin getInitializer(); List getRequiredModIds(); diff --git a/src/api/java/mcp/mobius/waila/api/IRayCastVectorProvider.java b/src/api/java/mcp/mobius/waila/api/IRayCastVectorProvider.java index 468c5c5b6..a70421bd8 100644 --- a/src/api/java/mcp/mobius/waila/api/IRayCastVectorProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IRayCastVectorProvider.java @@ -8,7 +8,7 @@ /** * Decides where Waila will start ray casting for objects. * - * @see IRegistrar#addRayCastVector(IRayCastVectorProvider, int) + * @see IClientRegistrar#addRayCastVector(IRayCastVectorProvider, int) */ @ApiSide.ClientOnly @ApiStatus.Experimental diff --git a/src/api/java/mcp/mobius/waila/api/IRegistrar.java b/src/api/java/mcp/mobius/waila/api/IRegistrar.java index 14df0e229..ff7df2211 100644 --- a/src/api/java/mcp/mobius/waila/api/IRegistrar.java +++ b/src/api/java/mcp/mobius/waila/api/IRegistrar.java @@ -5,7 +5,6 @@ import mcp.mobius.waila.api.__internal__.ApiSide; import mcp.mobius.waila.api.__internal__.IHarvestService; import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.chat.Component; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; @@ -15,712 +14,245 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.ApiStatus; +/** + * @deprecated use {@link ICommonRegistrar} or {@link IClientRegistrar} instead. + */ +@Deprecated @ApiStatus.NonExtendable -public interface IRegistrar { +public interface IRegistrar extends ICommonRegistrar, IClientRegistrar { - /** - * The default priority for all component and data provider. - */ - int DEFAULT_PRIORITY = 1000; + int DEFAULT_PRIORITY = WailaConstants.DEFAULT_PRIORITY; - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - */ + @Override void addConfig(ResourceLocation key, boolean defaultValue); - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param format used for formatting text box in plugin config screen - */ + @Override void addConfig(ResourceLocation key, int defaultValue, IntFormat format); - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - */ + @Override default void addConfig(ResourceLocation key, int defaultValue) { addConfig(key, defaultValue, IntFormat.DECIMAL); } - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - */ + @Override void addConfig(ResourceLocation key, double defaultValue); - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - */ + @Override void addConfig(ResourceLocation key, String defaultValue); - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - */ + @Override > void addConfig(ResourceLocation key, T defaultValue); - /** - * Adds an entry to the config screen to open a file with external editor. - *

- * Does NOT handle file parsing, and will NOT available from {@link IPluginConfig}. - * Needs to be handled by the user manually. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param path the path to the file - * - * @see IJsonConfig - */ + @Override void addConfig(ResourceLocation key, Path path); - /** - * Registers a namespaced config key to be accessed within data providers. - *

- * The main purpose of this method is for toggling feature that enabled by default. - * This method allows server to disable the option remotely for all connected clients, - * the clients can then toggle the option for their own side only if it is enabled on the server. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key to be used with {@link IPluginConfig#getBoolean(ResourceLocation)} - * @param clientOnly whether the feature available on client-only, e.g. not using {@linkplain IDataProvider server data} - */ + @Override void addFeatureConfig(ResourceLocation key, boolean clientOnly); - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - */ + @Override void addSyncedConfig(ResourceLocation key, boolean defaultValue, boolean clientOnlyValue); - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - * @param format used for formatting text box in plugin config screen - */ + @Override void addSyncedConfig(ResourceLocation key, int defaultValue, int clientOnlyValue, IntFormat format); - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - */ + @Override default void addSyncedConfig(ResourceLocation key, int defaultValue, int clientOnlyValue) { addSyncedConfig(key, defaultValue, clientOnlyValue, IntFormat.DECIMAL); } - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - */ + @Override void addSyncedConfig(ResourceLocation key, double defaultValue, double clientOnlyValue); - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - */ + @Override void addSyncedConfig(ResourceLocation key, String defaultValue, String clientOnlyValue); - /** - * Registers a namespaced config key to be accessed within data providers. - * These values are sent from the server to the client upon connection. - *

- * These translation keys will be used on the plugin config screen:

- *

- * Config options can also be grouped with the same prefix on its path followed by a period [{@code .}], - * e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.
- * Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name - * for it to be visible in the config screen. - * - * @param key the namespaced key - * @param defaultValue the default value - * @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed - */ + @Override > void addSyncedConfig(ResourceLocation key, T defaultValue, T clientOnlyValue); - /** - * Registers config key aliases that will be migrated gracefully to the actual key. - *

- * Also sync the value using aliased keys, so outdated client can still get the correct value. - */ + @Override void addConfigAlias(ResourceLocation actual, ResourceLocation... aliases); - /** - * Adds an event listener - */ + @Override void addEventListener(IEventListener listener, int priority); - /** - * Adds an event listener - */ + @Override default void addEventListener(IEventListener listener) { addEventListener(listener, DEFAULT_PRIORITY); } - /** - * Adds the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void addBlacklist(int priority, Block... blocks); - /** - * Adds the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void addBlacklist(int priority, BlockEntityType... blockEntityTypes); - /** - * Adds the specified entity types to the default blacklist. - */ + @Override default void addBlacklist(Block... blocks) { addBlacklist(DEFAULT_PRIORITY, blocks); } - /** - * Adds the specified entity types to the default blacklist. - */ + @Override default void addBlacklist(BlockEntityType... blockEntityTypes) { addBlacklist(DEFAULT_PRIORITY, blockEntityTypes); } - /** - * Removes the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void removeBlacklist(int priority, Block... blocks); - /** - * Removes the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void removeBlacklist(int priority, BlockEntityType... blockEntityTypes); - /** - * Removes the specified entity types to the default blacklist. - */ + @Override default void removeBlacklist(Block... blocks) { removeBlacklist(DEFAULT_PRIORITY, blocks); } - /** - * Removes the specified entity types to the default blacklist. - */ + @Override default void removeBlacklist(BlockEntityType... blockEntityTypes) { removeBlacklist(DEFAULT_PRIORITY, blockEntityTypes); } - /** - * Registers an {@link IBlockComponentProvider} instance to allow redirecting the object being displayed. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiStatus.Experimental void addRedirect(IBlockComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IBlockComponentProvider} instance to allow redirecting the object being displayed. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiStatus.Experimental default void addRedirect(IBlockComponentProvider provider, Class clazz) { addRedirect(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IBlockComponentProvider} instance to allow overriding the block being displayed. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addOverride(IBlockComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IBlockComponentProvider} instance with {@link #DEFAULT_PRIORITY} to allow overriding the block being displayed. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly default void addOverride(IBlockComponentProvider provider, Class clazz) { addOverride(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IBlockComponentProvider} instance to allow overriding the displayed icon for a block via the - * {@link IBlockComponentProvider#getIcon(IBlockAccessor, IPluginConfig)} method. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addIcon(IBlockComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IBlockComponentProvider} instance with {@link #DEFAULT_PRIORITY} to allow overriding the displayed icon for a block via the - * {@link IBlockComponentProvider#getIcon(IBlockAccessor, IPluginConfig)} method. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override @ApiSide.ClientOnly default void addIcon(IBlockComponentProvider provider, Class clazz) { addIcon(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IBlockComponentProvider} instance for appending {@link Component} to the tooltip. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param position the position on the tooltip this applies to - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class clazz, int priority); - /** - * Registers an {@link IBlockComponentProvider} instance with {@link #DEFAULT_PRIORITY} for appending {@link Component} to the tooltip. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param position the position on the tooltip this applies to - * @param clazz the highest level class to apply to - */ + @Override @ApiSide.ClientOnly default void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class clazz) { addComponent(provider, position, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IBlockComponentProvider} instance for appending data context that get sent to the server. - * A {@link BlockEntity} is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override void addDataContext(IBlockComponentProvider provider, Class clazz); - /** - * Registers an {@link IDataProvider} instance for data syncing purposes. A {@link BlockEntity} - * is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ServerOnly void addBlockData(IDataProvider provider, Class clazz, int priority); - /** - * Registers an {@link IDataProvider} instance with {@link #DEFAULT_PRIORITY} for data syncing purposes. A {@link BlockEntity} - * is also an acceptable class type. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override default void addBlockData(IDataProvider provider, Class clazz) { addBlockData(provider, clazz, DEFAULT_PRIORITY); } - /** - * Adds the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void addBlacklist(int priority, EntityType... entityTypes); - /** - * Adds the specified entity types to the default blacklist. - */ + @Override default void addBlacklist(EntityType... entityTypes) { addBlacklist(DEFAULT_PRIORITY, entityTypes); } - /** - * Removes the specified entity types to the default blacklist. - * - * @param priority the modifier priority, lower number will be called last - */ + @Override void removeBlacklist(int priority, EntityType... entityTypes); - /** - * Removes the specified entity types to the default blacklist. - */ + @Override default void removeBlacklist(EntityType... entityTypes) { removeBlacklist(DEFAULT_PRIORITY, entityTypes); } - /** - * Registers an {@link IEntityComponentProvider} instance to allow redirecting the object being displayed. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiStatus.Experimental void addRedirect(IEntityComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IEntityComponentProvider} instance to allow redirecting the object being displayed. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiStatus.Experimental default void addRedirect(IEntityComponentProvider provider, Class clazz) { addRedirect(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IEntityComponentProvider} instance to allow overriding the entity being displayed. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addOverride(IEntityComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IEntityComponentProvider} instance with {@link #DEFAULT_PRIORITY} to allow overriding the entity being displayed. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly default void addOverride(IEntityComponentProvider provider, Class clazz) { addOverride(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IEntityComponentProvider} instance to allow displaying an icon via the - * {@link IEntityComponentProvider#getIcon(IEntityAccessor, IPluginConfig)} method. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addIcon(IEntityComponentProvider provider, Class clazz, int priority); - /** - * Registers an {@link IEntityComponentProvider} instance with {@link #DEFAULT_PRIORITY} to allow displaying an icon via the - * {@link IEntityComponentProvider#getIcon(IEntityAccessor, IPluginConfig)} method. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override @ApiSide.ClientOnly default void addIcon(IEntityComponentProvider provider, Class clazz) { addIcon(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IEntityComponentProvider} instance for appending {@link Component} to the tooltip. - * - * @param provider the data provider instance - * @param position the position on the tooltip this applies to - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ClientOnly void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class clazz, int priority); - /** - * Registers an {@link IEntityComponentProvider} instance with {@link #DEFAULT_PRIORITY} for appending {@link Component} to the tooltip. - * - * @param provider the data provider instance - * @param position the position on the tooltip this applies to - * @param clazz the highest level class to apply to - */ + @Override @ApiSide.ClientOnly default void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class clazz) { addComponent(provider, position, clazz, DEFAULT_PRIORITY); } - /** - * Registers an {@link IEntityComponentProvider} instance for appending data context that get sent to the server. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override void addDataContext(IEntityComponentProvider provider, Class clazz); - /** - * Registers an {@link IDataProvider} instance for data syncing purposes. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - * - * @see #DEFAULT_PRIORITY - */ + @Override @ApiSide.ServerOnly void addEntityData(IDataProvider provider, Class clazz, int priority); - /** - * Registers an {@link IDataProvider} instance eith {@link #DEFAULT_PRIORITY} for data syncing purposes. - * - * @param provider the data provider instance - * @param clazz the highest level class to apply to - */ + @Override default void addEntityData(IDataProvider provider, Class clazz) { addEntityData(provider, clazz, DEFAULT_PRIORITY); } - /** - * Registers a data type used for syncing data from server to client. - * - * @param type the data type - * @param codec the data-to-buffer codec - */ + @Override void addDataType(IData.Type type, StreamCodec codec); - /** - * Registers an {@link IThemeType} instance. - * - * @param id the theme type id - * @param type the theme type - */ + @Override @ApiSide.ClientOnly @ApiStatus.Experimental void addThemeType(ResourceLocation id, IThemeType type); - /** - * Registers an {@link IRayCastVectorProvider} instance - * - * @param provider the vector provider - * @param priority the priority of this provider 0 is the minimum, lower number will be called first - */ + @Override @ApiSide.ClientOnly @ApiStatus.Experimental void addRayCastVector(IRayCastVectorProvider provider, int priority); - /** - * Registers an {@link IRayCastVectorProvider} instance with {@link #DEFAULT_PRIORITY} - * - * @param provider the vector provider - */ + @Override @ApiSide.ClientOnly @ApiStatus.Experimental default void addRayCastVector(IRayCastVectorProvider provider) { addRayCastVector(provider, DEFAULT_PRIORITY); } - /** - * Registers a tool type, to be used for the harvestability tooltip. - * - * @param id the tool type id, also used as the translation key as {@code tooltip.waila.harvest.tool.[namespace].[path]} - * @param toolType the tool type - */ + @Override @ApiSide.ClientOnly @ApiStatus.Experimental default void addToolType(ResourceLocation id, IToolType toolType) { diff --git a/src/api/java/mcp/mobius/waila/api/IWailaClientPlugin.java b/src/api/java/mcp/mobius/waila/api/IWailaClientPlugin.java new file mode 100644 index 000000000..dc8b32544 --- /dev/null +++ b/src/api/java/mcp/mobius/waila/api/IWailaClientPlugin.java @@ -0,0 +1,15 @@ +package mcp.mobius.waila.api; + +import lol.bai.badpackets.impl.marker.ApiSide; + +/** + * The client side entrypoint for Waila plugins. + *

+ * See {@linkplain mcp.mobius.waila.api package documentation} for more info. + */ +@ApiSide.ClientOnly +public interface IWailaClientPlugin { + + void register(IClientRegistrar registrar); + +} diff --git a/src/api/java/mcp/mobius/waila/api/IWailaCommonPlugin.java b/src/api/java/mcp/mobius/waila/api/IWailaCommonPlugin.java new file mode 100644 index 000000000..0feea034e --- /dev/null +++ b/src/api/java/mcp/mobius/waila/api/IWailaCommonPlugin.java @@ -0,0 +1,12 @@ +package mcp.mobius.waila.api; + +/** + * The common side entrypoint for Waila plugins. + *

+ * See {@linkplain mcp.mobius.waila.api package documentation} for mor info. + */ +public interface IWailaCommonPlugin { + + void register(ICommonRegistrar registrar); + +} diff --git a/src/api/java/mcp/mobius/waila/api/IWailaPlugin.java b/src/api/java/mcp/mobius/waila/api/IWailaPlugin.java index 978087460..fc20e000d 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaPlugin.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaPlugin.java @@ -3,46 +3,9 @@ import org.jetbrains.annotations.ApiStatus; /** - * Main interface used for Waila plugins. Provides a valid instance of {@link IRegistrar}. - *

- *

Plugin Definitions

- *

- * To register the plugin instance, create a file called {@code waila_plugins.json} or {@code wthit_plugins.json} in the root of your mod.


- * {
- *   // the plugin identifier, [namespace:path]
- *   "yourmodid:plugin": {
- *      // the path to the implementation class
- *      "initializer": "package.YourWailaPlugin",
- *
- *      // optional, decide the environment the plugin will loaded, options:
- *      // client    load plugin only on client and integrated server
- *      // server    load plugin only on dedicated server
- *      // *         load plugin on both client and dedicated server
- *      "side": "*",
- *
- *      // optional, the required mods that this plugin needs
- *      "required": {
- *          "othermodid": "*",    // match any version
- *          "another_one": ">1.2" // match versions newer than 1.2, see below for more details
- *      },
- *
- *      // optional, whether the plugin is enabled by default. defaults to true
- *      "defaultEnabled": true
- *   }
- *
- *   // register multiple plugins!
- *   "yourmodid:another": {...}
- * }
- * 
- * - *

- *

Version Ranges

- *

- * Waila only implements primitive operator ({@code <, <=, >, >=, =}) alongside logical and ({@code &&}) and or ({@code ||}) - * for its version ranges. - * - * @see FlexVer project + * @deprecated use {@link IWailaCommonPlugin} or {@link IWailaClientPlugin} instead. */ +@Deprecated @ApiStatus.OverrideOnly public interface IWailaPlugin { diff --git a/src/api/java/mcp/mobius/waila/api/WailaConstants.java b/src/api/java/mcp/mobius/waila/api/WailaConstants.java index d86175f12..b263d0882 100644 --- a/src/api/java/mcp/mobius/waila/api/WailaConstants.java +++ b/src/api/java/mcp/mobius/waila/api/WailaConstants.java @@ -1,6 +1,5 @@ package mcp.mobius.waila.api; -import com.google.common.base.Preconditions; import net.minecraft.resources.ResourceLocation; public class WailaConstants { @@ -18,6 +17,11 @@ public class WailaConstants { */ public static final int CONFIG_VERSION = 1; + /** + * The default priority for all component and data provider. + */ + public static final int DEFAULT_PRIORITY = 1000; + /** * Tooltip tag for block, fluid, and entity name line. * diff --git a/src/api/java/mcp/mobius/waila/api/data/BlockingDataProvider.java b/src/api/java/mcp/mobius/waila/api/data/BlockingDataProvider.java index f437e4a57..3e340def5 100644 --- a/src/api/java/mcp/mobius/waila/api/data/BlockingDataProvider.java +++ b/src/api/java/mcp/mobius/waila/api/data/BlockingDataProvider.java @@ -4,14 +4,14 @@ import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IRegistrar; import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.WailaConstants; /** * Implementation of {@link IDataProvider} that blocks specified data types. *

* Usage of this class should probably be accompanied by a higher (lower number) - * priority than the {@linkplain IRegistrar#DEFAULT_PRIORITY default}. + * priority than the {@linkplain WailaConstants#DEFAULT_PRIORITY default}. */ public final class BlockingDataProvider implements IDataProvider { diff --git a/src/api/java/mcp/mobius/waila/api/data/EnergyData.java b/src/api/java/mcp/mobius/waila/api/data/EnergyData.java index d090d46e9..c7b2b2e76 100644 --- a/src/api/java/mcp/mobius/waila/api/data/EnergyData.java +++ b/src/api/java/mcp/mobius/waila/api/data/EnergyData.java @@ -2,7 +2,7 @@ import mcp.mobius.waila.api.IData; import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IRegistrar; +import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.api.__internal__.ApiSide; import mcp.mobius.waila.api.__internal__.IApiService; import mcp.mobius.waila.api.__internal__.IExtraService; @@ -48,7 +48,7 @@ public abstract class EnergyData implements IData { /** * Creates a {@linkplain IDataProvider data provider} that always returns infinite energy data. *

- * Should probably be used with a higher (lower number) priority than the {@linkplain IRegistrar#DEFAULT_PRIORITY default}. + * Should probably be used with a higher (lower number) priority than the {@linkplain WailaConstants#DEFAULT_PRIORITY default}. *

* Along with this method, Waila also provides {@code waila:extra/infinite_energy} * tag that can be used for marking blocks, block entity types, or entity types to contain infinite energy. diff --git a/src/api/java/mcp/mobius/waila/api/package-info.java b/src/api/java/mcp/mobius/waila/api/package-info.java index 286839306..1aadc1b05 100644 --- a/src/api/java/mcp/mobius/waila/api/package-info.java +++ b/src/api/java/mcp/mobius/waila/api/package-info.java @@ -1,6 +1,49 @@ /** * The WTHIT API. * - * @see mcp.mobius.waila.api.IWailaPlugin + *

Plugin Definitions

+ *

+ * To register the plugin instance, create a file called {@code waila_plugins.json} or {@code wthit_plugins.json} in the root of your mod.


+ * {
+ *   // the plugin identifier, [namespace:path]
+ *   "yourmodid:plugin": {
+ *      "entrypoints" : {
+ *        // common entrypoint, will always get called
+ *        "common": "package.YourWailaCommonPlugin",
+ *
+ *        // client entrypoint, only called on client side
+ *        "client": "package.YourWailaClientPlugin"
+ *      },
+ *
+ *      // optional, decide the environment the plugin will loaded, options:
+ *      // client    load plugin only on client and integrated server
+ *      // server    load plugin only on dedicated server
+ *      // *         load plugin on both client and dedicated server
+ *      "side": "*",
+ *
+ *      // optional, the required mods that this plugin needs
+ *      "required": {
+ *          "othermodid": "*",    // match any version
+ *          "another_one": ">1.2" // match versions newer than 1.2, see below for more details
+ *      },
+ *
+ *      // optional, whether the plugin is enabled by default. defaults to true
+ *      "defaultEnabled": true
+ *   }
+ *
+ *   // register multiple plugins!
+ *   "yourmodid:another": {...}
+ * }
+ * 
+ * + *

+ *

Version Ranges

+ *

+ * Waila only implements primitive operator ({@code <, <=, >, >=, =}) alongside logical and ({@code &&}) and or ({@code ||}) + * for its version ranges. + * + * @see FlexVer project + * @see mcp.mobius.waila.api.IWailaCommonPlugin + * @see mcp.mobius.waila.api.IWailaClientPlugin */ package mcp.mobius.waila.api; diff --git a/src/main/java/mcp/mobius/waila/Waila.java b/src/main/java/mcp/mobius/waila/Waila.java index 5fd4e7de3..0a6c51a4f 100644 --- a/src/main/java/mcp/mobius/waila/Waila.java +++ b/src/main/java/mcp/mobius/waila/Waila.java @@ -4,13 +4,13 @@ import com.google.gson.GsonBuilder; import mcp.mobius.waila.api.IJsonConfig; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.api.__internal__.IHarvestService; import mcp.mobius.waila.config.BlacklistConfig; import mcp.mobius.waila.config.DebugConfig; import mcp.mobius.waila.config.WailaConfig; import mcp.mobius.waila.gui.hud.theme.ThemeDefinition; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.registry.RegistryFilter; import mcp.mobius.waila.service.ICommonService; import mcp.mobius.waila.util.Log; @@ -22,7 +22,7 @@ public abstract class Waila { private static final Log LOG = Log.create(); public static final boolean DEV = ICommonService.INSTANCE.isDev(); - public static final boolean CLIENT_SIDE = ICommonService.INSTANCE.getSide().matches(IPluginInfo.Side.CLIENT); + public static final boolean CLIENT_SIDE = ICommonService.INSTANCE.getSide().matches(PluginSide.CLIENT); public static final boolean ENABLE_DEBUG_COMMAND = DEV || Boolean.getBoolean("waila.debugCommands"); public static final String ISSUE_URL = ICommonService.INSTANCE.getIssueUrl(); diff --git a/src/main/java/mcp/mobius/waila/command/CommonCommand.java b/src/main/java/mcp/mobius/waila/command/CommonCommand.java index eb9740716..12dce8991 100644 --- a/src/main/java/mcp/mobius/waila/command/CommonCommand.java +++ b/src/main/java/mcp/mobius/waila/command/CommonCommand.java @@ -10,7 +10,6 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.SuggestionProvider; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.buildconst.Tl; import mcp.mobius.waila.plugin.PluginInfo; import net.minecraft.ChatFormatting; @@ -99,7 +98,7 @@ public final void register(CommandDispatcher dispatcher) { .register(dispatcher); } - private Stream getPlugins(boolean enabled) { + private Stream getPlugins(boolean enabled) { return PluginInfo.getAll().stream().filter(it -> enabled == it.isEnabled()); } @@ -121,9 +120,8 @@ else success(source, () -> Component.translatable( private SuggestionProvider suggestPlugins(boolean enabled) { return (context, builder) -> suggestResource(getPlugins(enabled) - .map(it -> (PluginInfo) it) .filter(it -> !it.isLocked() && !isPluginDisabledOnServer(it)) - .map(IPluginInfo::getPluginId), builder); + .map(PluginInfo::getPluginId), builder); } private int modifyPlugin(CommandContext context, boolean enable) { diff --git a/src/main/java/mcp/mobius/waila/network/common/s2c/PluginSyncCommonS2CPacket.java b/src/main/java/mcp/mobius/waila/network/common/s2c/PluginSyncCommonS2CPacket.java index b0b9320e9..1aa9e7cdc 100644 --- a/src/main/java/mcp/mobius/waila/network/common/s2c/PluginSyncCommonS2CPacket.java +++ b/src/main/java/mcp/mobius/waila/network/common/s2c/PluginSyncCommonS2CPacket.java @@ -6,7 +6,6 @@ import lol.bai.badpackets.api.config.ConfigPackets; import lol.bai.badpackets.api.play.PlayPackets; import mcp.mobius.waila.Waila; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.network.Packet; import mcp.mobius.waila.plugin.PluginInfo; import mcp.mobius.waila.plugin.PluginLoader; @@ -39,7 +38,7 @@ private static void receive(Payload payload) { PluginInfo.refresh(); for (var plugin : payload.plugins) { - ((PluginInfo) IPluginInfo.get(plugin)).setDisabledOnServer(true); + PluginInfo.get(plugin).setDisabledOnServer(true); } PluginLoader.INSTANCE.loadPlugins(); @@ -52,7 +51,7 @@ public record Payload( public Payload() { this(PluginInfo.getAll().stream() .filter(it -> !it.isEnabled()) - .map(IPluginInfo::getPluginId) + .map(PluginInfo::getPluginId) .toList()); } diff --git a/src/main/java/mcp/mobius/waila/plugin/PluginInfo.java b/src/main/java/mcp/mobius/waila/plugin/PluginInfo.java index 65485a12a..1e56a1f7e 100644 --- a/src/main/java/mcp/mobius/waila/plugin/PluginInfo.java +++ b/src/main/java/mcp/mobius/waila/plugin/PluginInfo.java @@ -4,21 +4,27 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Collectors; +import com.google.common.base.Suppliers; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import mcp.mobius.waila.Waila; import mcp.mobius.waila.api.IJsonConfig; import mcp.mobius.waila.api.IModInfo; import mcp.mobius.waila.api.IPluginInfo; +import mcp.mobius.waila.api.IWailaClientPlugin; +import mcp.mobius.waila.api.IWailaCommonPlugin; import mcp.mobius.waila.api.IWailaPlugin; import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.util.CachedSupplier; import mcp.mobius.waila.util.Log; import mcp.mobius.waila.util.ModInfo; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; +@SuppressWarnings("deprecation") public class PluginInfo implements IPluginInfo { private static final Log LOG = Log.create(); @@ -34,57 +40,125 @@ public class PluginInfo implements IPluginInfo { .create()) .build(); - private static final Map PLUGIN_ID_TO_PLUGIN_INFO = new LinkedHashMap<>(); - private static final CachedSupplier>> MOD_ID_TO_PLUGIN_INFOS = new CachedSupplier<>(() -> + private static final Map PLUGIN_ID_TO_PLUGIN_INFO = new LinkedHashMap<>(); + private static final CachedSupplier>> MOD_ID_TO_PLUGIN_INFOS = new CachedSupplier<>(() -> PLUGIN_ID_TO_PLUGIN_INFO.values().stream().collect(Collectors.groupingBy(p -> p.getModInfo().getId()))); + private static final IWailaPlugin EMPTY_INIT = registrar -> {}; + private final ModInfo modInfo; private final ResourceLocation pluginId; - private final Side side; - private final IWailaPlugin initializer; + private final PluginSide side; private final List requiredModIds; private final boolean legacy; + private final @Nullable IWailaPlugin deprecatedInit; + + private final @Nullable Supplier<@Nullable IWailaCommonPlugin> common; + private final @Nullable Supplier<@Nullable IWailaClientPlugin> client; + private boolean disabledOnServer; - private PluginInfo(ModInfo modInfo, ResourceLocation pluginId, Side side, IWailaPlugin initializer, List requiredModIds, boolean legacy) { + private PluginInfo( + ModInfo modInfo, + ResourceLocation pluginId, + PluginSide side, + @Nullable IWailaPlugin deprecatedInit, + List requiredModIds, + boolean legacy, + @Nullable Supplier<@Nullable IWailaCommonPlugin> common, + @Nullable Supplier<@Nullable IWailaClientPlugin> client + ) { this.modInfo = modInfo; this.pluginId = pluginId; this.side = side; - this.initializer = initializer; + this.deprecatedInit = deprecatedInit; this.requiredModIds = requiredModIds; this.legacy = legacy; + this.common = common; + this.client = client; } - public static void register(String modId, String pluginIdStr, Side side, String initializerStr, List required, boolean defaultEnabled, boolean legacy) { + private static boolean isDuplicate(ResourceLocation rl) { + if (PLUGIN_ID_TO_PLUGIN_INFO.containsKey(rl)) { + LOG.error("Duplicate plugin id " + rl); + return true; + } + return false; + } + + public static void register( + String modId, + String pluginIdStr, + PluginSide side, + @Nullable String commonCls, + @Nullable String clientCls, + List required, + boolean defaultEnabled + ) { + var rl = ResourceLocation.parse(pluginIdStr); + if (isDuplicate(rl)) return; + + if (rl.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) { + LOG.warn("Plugin " + commonCls + " is using the default namespace " + rl); + } + + var common = commonCls == null ? null : Suppliers.memoize(() -> { + try { + return (IWailaCommonPlugin) Class.forName(commonCls).getConstructor().newInstance(); + } catch (Throwable t) { + LOG.error("Error creating instance of plugin " + pluginIdStr, t); + } + return null; + }); + + var client = clientCls == null ? null : Suppliers.memoize(() -> { + try { + return (IWailaClientPlugin) Class.forName(clientCls).getConstructor().newInstance(); + } catch (Throwable t) { + LOG.error("Error creating instance of plugin " + pluginIdStr, t); + } + return null; + }); + + PLUGIN_ID_TO_PLUGIN_INFO.put(rl, new PluginInfo(ModInfo.get(modId), rl, side, null, required, false, common, client)); + TOGGLE.get().put(rl, defaultEnabled); + } + + public static void registerDeprecated( + String modId, + String pluginIdStr, + PluginSide side, + String initializerStr, + List required, + boolean defaultEnabled, + boolean legacy + ) { try { var rl = ResourceLocation.parse(pluginIdStr); - if (PLUGIN_ID_TO_PLUGIN_INFO.containsKey(rl)) { - LOG.error("Duplicate plugin id " + rl); - return; - } + if (isDuplicate(rl)) return; if (rl.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) { LOG.warn("Plugin " + initializerStr + " is using the default namespace " + rl); } var initializer = (IWailaPlugin) Class.forName(initializerStr).getConstructor().newInstance(); - PLUGIN_ID_TO_PLUGIN_INFO.put(rl, new PluginInfo(ModInfo.get(modId), rl, side, initializer, required, legacy)); + PLUGIN_ID_TO_PLUGIN_INFO.put(rl, new PluginInfo(ModInfo.get(modId), rl, side, initializer, required, legacy, null, null)); TOGGLE.get().putIfAbsent(rl, defaultEnabled); } catch (Throwable t) { LOG.error("Error creating instance of plugin " + pluginIdStr, t); } } - public static IPluginInfo get(ResourceLocation pluginId) { + public static PluginInfo get(ResourceLocation pluginId) { return PLUGIN_ID_TO_PLUGIN_INFO.get(pluginId); } - public static Collection getAllFromMod(String modId) { + public static Collection getAllFromMod(String modId) { return MOD_ID_TO_PLUGIN_INFOS.get().get(modId); } - public static Collection getAll() { + public static Collection getAll() { return PLUGIN_ID_TO_PLUGIN_INFO.values(); } @@ -100,12 +174,30 @@ public ResourceLocation getPluginId() { @Override public Side getSide() { - return side; + return side.toDeprecated(); } @Override + @SuppressWarnings("deprecation") public IWailaPlugin getInitializer() { - return initializer; + if (deprecatedInit == null) return EMPTY_INIT; + return deprecatedInit; + } + + @SuppressWarnings("deprecation") + public @Nullable IWailaPlugin getDeprecatedInit() { + return deprecatedInit; + } + + public @Nullable IWailaCommonPlugin getCommon() { + if (common == null) return null; + return common.get(); + } + + public @Nullable IWailaClientPlugin getClient() { + if (client == null) return null; + if (!Waila.CLIENT_SIDE) return null; + return client.get(); } @Override @@ -141,7 +233,7 @@ public void setEnabled(boolean enabled) { public static void refresh() { TOGGLE.invalidate(); - getAll().forEach(it -> ((PluginInfo) it).disabledOnServer = false); + getAll().forEach(it -> it.disabledOnServer = false); } public static void saveToggleConfig() { diff --git a/src/main/java/mcp/mobius/waila/plugin/PluginLoader.java b/src/main/java/mcp/mobius/waila/plugin/PluginLoader.java index ffc20e8fb..2834eeb24 100644 --- a/src/main/java/mcp/mobius/waila/plugin/PluginLoader.java +++ b/src/main/java/mcp/mobius/waila/plugin/PluginLoader.java @@ -13,7 +13,6 @@ import com.google.gson.JsonParser; import lol.bai.badpackets.api.PacketSender; import mcp.mobius.waila.Waila; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.api.__internal__.Internals; import mcp.mobius.waila.config.JsonConfig; @@ -41,15 +40,18 @@ public abstract class PluginLoader { "wthit_plugins.json" }; + protected static final String KEY_ENTRYPOINTS = "entrypoints"; + protected static final String KEY_ENTRYPOINT_COMMON = "common"; + protected static final String KEY_ENTRYPOINT_CLIENT = "client"; protected static final String KEY_INITIALIZER = "initializer"; protected static final String KEY_SIDE = "side"; protected static final String KEY_REQUIRED = "required"; protected static final String KEY_DEFAULT_ENABLED = "defaultEnabled"; - protected static final Map SIDES = Map.of( - "client", IPluginInfo.Side.CLIENT, - "server", IPluginInfo.Side.SERVER, - "both", IPluginInfo.Side.BOTH, - "*", IPluginInfo.Side.BOTH + protected static final Map SIDES = Map.of( + "client", PluginSide.CLIENT, + "server", PluginSide.DEDICATED_SERVER, + "both", PluginSide.COMMON, + "*", PluginSide.COMMON ); private boolean gathered = false; @@ -90,10 +92,12 @@ protected void readPluginsJson(String modId, Path path) { for (var pluginId : object.keySet()) { var plugin = object.getAsJsonObject(pluginId); - var initializer = plugin.getAsJsonPrimitive(KEY_INITIALIZER).getAsString(); + var deprecatedInit = plugin.has(KEY_INITIALIZER) ? plugin.getAsJsonPrimitive(KEY_INITIALIZER).getAsString() : null; + var entrypoints = plugin.has(KEY_ENTRYPOINTS) ? plugin.getAsJsonObject(KEY_ENTRYPOINTS) : null; + var side = plugin.has(KEY_SIDE) ? Objects.requireNonNull(SIDES.get(plugin.get(KEY_SIDE).getAsString()), () -> readError(path) + ", invalid side, available: " + SIDES.keySet().stream().collect(Collectors.joining(", ", "[", "]"))) - : IPluginInfo.Side.BOTH; + : PluginSide.COMMON; if (!side.matches(ICommonService.INSTANCE.getSide())) { continue; @@ -129,7 +133,20 @@ protected void readPluginsJson(String modId, Path path) { var defaultEnabled = !plugin.has(KEY_DEFAULT_ENABLED) || plugin.get(KEY_DEFAULT_ENABLED).getAsBoolean(); - PluginInfo.register(modId, pluginId, side, initializer, required, defaultEnabled, false); + if (deprecatedInit != null) { + PluginInfo.registerDeprecated(modId, pluginId, side, deprecatedInit, required, defaultEnabled, false); + } else if (entrypoints != null) { + var common = entrypoints.has(KEY_ENTRYPOINT_COMMON) ? entrypoints.getAsJsonPrimitive(KEY_ENTRYPOINT_COMMON).getAsString() : null; + var client = entrypoints.has(KEY_ENTRYPOINT_CLIENT) ? entrypoints.getAsJsonPrimitive(KEY_ENTRYPOINT_CLIENT).getAsString() : null; + + if (common == null && client == null) { + throw new NullPointerException(readError(path) + ", need at least one entrypoint"); + } + + PluginInfo.register(modId, pluginId, side, common, client, required, defaultEnabled); + } else { + throw new NullPointerException(readError(path) + ", need at least one entrypoint"); + } } } catch (IOException e) { throw new RuntimeException(readError(path), e); @@ -144,12 +161,12 @@ public final void loadPlugins() { gatherPlugins(); if (Waila.DEBUG_CONFIG.get().showTestPluginToggle) { - PluginInfo.register(WailaConstants.MOD_ID, Waila.id("test").toString(), IPluginInfo.Side.BOTH, "mcp.mobius.waila.plugin.test.WailaPluginTest", List.of(), false, false); + PluginInfo.registerDeprecated(WailaConstants.MOD_ID, Waila.id("test").toString(), PluginSide.COMMON, "mcp.mobius.waila.plugin.test.WailaPluginTest", List.of(), false, false); } } PluginInfo.saveToggleConfig(); - IPluginInfo extraPlugin = null; + PluginInfo extraPlugin = null; // TODO: remove legacy method on Minecraft 1.21 List legacyPlugins = new ArrayList<>(); @@ -160,7 +177,7 @@ public final void loadPlugins() { initialize(info); } - if (((PluginInfo) info).isLegacy()) { + if (info.isLegacy()) { legacyPlugins.add(info.getPluginId().toString()); } } @@ -179,16 +196,27 @@ public final void loadPlugins() { JsonConfig.INSTANCES.forEach(it -> it.write(it.get(), true)); } - private void initialize(IPluginInfo info) { + private void initialize(PluginInfo info) { Registrar.get().attach(info); + var id = info.getPluginId(); + + var deprecatedInit = info.getDeprecatedInit(); + var common = info.getCommon(); + var client = info.getClient(); + if (info.isEnabled()) { - LOG.info("Initializing plugin {} at {}", info.getPluginId(), info.getInitializer().getClass().getCanonicalName()); + if (deprecatedInit != null) LOG.info("Initializing plugin {} at {}", id, deprecatedInit.getClass().getCanonicalName()); + if (common != null) LOG.info("Initializing common plugin {} at {}", id, common.getClass().getCanonicalName()); + if (client != null) LOG.info("Initializing client plugin {} at {}", id, client.getClass().getCanonicalName()); } else { - LOG.info("Skipping disabled plugin {}", info.getPluginId()); + LOG.info("Skipping disabled plugin {}", id); } - info.getInitializer().register(Registrar.get()); + if (deprecatedInit != null) deprecatedInit.register(Registrar.get()); + if (common != null) common.register(Registrar.get()); + if (client != null) client.register(Registrar.get()); + Registrar.get().attach(null); } diff --git a/src/main/java/mcp/mobius/waila/plugin/PluginSide.java b/src/main/java/mcp/mobius/waila/plugin/PluginSide.java new file mode 100644 index 000000000..c1f2e968a --- /dev/null +++ b/src/main/java/mcp/mobius/waila/plugin/PluginSide.java @@ -0,0 +1,20 @@ +package mcp.mobius.waila.plugin; + +import mcp.mobius.waila.api.IPluginInfo; + +public enum PluginSide { + CLIENT, DEDICATED_SERVER, COMMON; + + public boolean matches(PluginSide other) { + return this == COMMON || other == COMMON || this == other; + } + + @SuppressWarnings("deprecation") + public IPluginInfo.Side toDeprecated() { + return switch (this) { + case COMMON -> IPluginInfo.Side.BOTH; + case CLIENT -> IPluginInfo.Side.CLIENT; + case DEDICATED_SERVER -> IPluginInfo.Side.SERVER; + }; + } +} diff --git a/src/main/java/mcp/mobius/waila/registry/Registrar.java b/src/main/java/mcp/mobius/waila/registry/Registrar.java index 50e3e527b..32f7c355b 100644 --- a/src/main/java/mcp/mobius/waila/registry/Registrar.java +++ b/src/main/java/mcp/mobius/waila/registry/Registrar.java @@ -16,6 +16,8 @@ import com.google.common.collect.HashBiMap; import mcp.mobius.waila.Waila; import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IClientRegistrar; +import mcp.mobius.waila.api.ICommonRegistrar; import mcp.mobius.waila.api.IData; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IEntityComponentProvider; @@ -47,7 +49,8 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.Nullable; -public class Registrar implements IRegistrar { +@SuppressWarnings("deprecation") +public class Registrar implements ICommonRegistrar, IClientRegistrar, IRegistrar { private static final CachedSupplier INSTANCE = new CachedSupplier<>(Registrar::new); diff --git a/src/main/java/mcp/mobius/waila/service/ApiService.java b/src/main/java/mcp/mobius/waila/service/ApiService.java index ed17520f4..7aa34f474 100644 --- a/src/main/java/mcp/mobius/waila/service/ApiService.java +++ b/src/main/java/mcp/mobius/waila/service/ApiService.java @@ -103,14 +103,16 @@ public IPluginInfo getPluginInfo(ResourceLocation pluginId) { return PluginInfo.get(pluginId); } + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public Collection getAllPluginInfoFromMod(String modId) { - return PluginInfo.getAllFromMod(modId); + return (Collection) PluginInfo.getAllFromMod(modId); } + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public Collection getAllPluginInfo() { - return PluginInfo.getAll(); + return (Collection) PluginInfo.getAll(); } @Override diff --git a/src/main/java/mcp/mobius/waila/service/ICommonService.java b/src/main/java/mcp/mobius/waila/service/ICommonService.java index 4fcb9a520..2651cdd6c 100644 --- a/src/main/java/mcp/mobius/waila/service/ICommonService.java +++ b/src/main/java/mcp/mobius/waila/service/ICommonService.java @@ -3,8 +3,8 @@ import java.nio.file.Path; import java.util.Optional; -import mcp.mobius.waila.api.IPluginInfo; import mcp.mobius.waila.api.__internal__.Internals; +import mcp.mobius.waila.plugin.PluginSide; import mcp.mobius.waila.util.ModInfo; public interface ICommonService { @@ -21,7 +21,7 @@ public interface ICommonService { boolean isDev(); - IPluginInfo.Side getSide(); + PluginSide getSide(); String getIssueUrl(); diff --git a/src/main/java/mcp/mobius/waila/util/Log.java b/src/main/java/mcp/mobius/waila/util/Log.java index 5834c44af..2b9f9f5f1 100644 --- a/src/main/java/mcp/mobius/waila/util/Log.java +++ b/src/main/java/mcp/mobius/waila/util/Log.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings("StringConcatenationArgumentToLogCall") public final class Log { private static final String PREFIX = "[" + WailaConstants.MOD_NAME + "] "; diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/WailaPluginCore.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreClientPlugin.java similarity index 70% rename from src/pluginCore/java/mcp/mobius/waila/plugin/core/WailaPluginCore.java rename to src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreClientPlugin.java index ab107b5bc..ea7c85bfe 100644 --- a/src/pluginCore/java/mcp/mobius/waila/plugin/core/WailaPluginCore.java +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreClientPlugin.java @@ -1,8 +1,7 @@ package mcp.mobius.waila.plugin.core; -import mcp.mobius.waila.api.IRegistrar; -import mcp.mobius.waila.api.IWailaConfig.Overlay.Position.Align; -import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.IClientRegistrar; +import mcp.mobius.waila.api.IWailaClientPlugin; import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.plugin.core.event.CoreEventListener; import mcp.mobius.waila.plugin.core.provider.BlockProvider; @@ -11,7 +10,6 @@ import mcp.mobius.waila.plugin.core.raycast.CoreRayCastVectorProvider; import mcp.mobius.waila.plugin.core.theme.GradientTheme; import mcp.mobius.waila.plugin.core.theme.NinePatchTheme; -import net.minecraft.world.Nameable; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.block.Block; @@ -21,12 +19,12 @@ import static mcp.mobius.waila.api.TooltipPosition.HEAD; import static mcp.mobius.waila.api.TooltipPosition.TAIL; -public class WailaPluginCore implements IWailaPlugin { +public class CoreClientPlugin implements IWailaClientPlugin { private static final int PRIORITY = 900; @Override - public void register(IRegistrar registrar) { + public void register(IClientRegistrar registrar) { registrar.addRayCastVector(CoreRayCastVectorProvider.INSTANCE, 1100); registrar.addComponent(BlockProvider.INSTANCE, HEAD, Block.class, PRIORITY); @@ -36,7 +34,6 @@ public void register(IRegistrar registrar) { registrar.addEventListener(CoreEventListener.INSTANCE, PRIORITY); registrar.addIcon(BlockProvider.INSTANCE, Block.class, 1100); - registrar.addBlockData(BlockProvider.INSTANCE, Nameable.class); registrar.addIcon(FluidProvider.INSTANCE, LiquidBlock.class, PRIORITY); registrar.addComponent(FluidProvider.INSTANCE, HEAD, LiquidBlock.class, PRIORITY); @@ -49,15 +46,6 @@ public void register(IRegistrar registrar) { registrar.addRedirect(BlockProvider.INSTANCE, Block.class, 500); registrar.addRedirect(EntityProvider.INSTANCE, Entity.class, 500); - registrar.addConfig(WailaConstants.CONFIG_SHOW_BLOCK, true); - registrar.addConfig(WailaConstants.CONFIG_SHOW_FLUID, false); - registrar.addConfig(WailaConstants.CONFIG_SHOW_ENTITY, true); - registrar.addConfig(WailaConstants.CONFIG_SHOW_ICON, true); - registrar.addConfig(WailaConstants.CONFIG_ICON_POSITION, Align.Y.MIDDLE); - registrar.addConfig(WailaConstants.CONFIG_SHOW_MOD_NAME, true); - registrar.addConfig(WailaConstants.CONFIG_SHOW_ITEM_MOD_NAME, true); - registrar.addConfig(WailaConstants.CONFIG_SHOW_REGISTRY, false); - registrar.addThemeType(WailaConstants.THEME_TYPE_GRADIENT, GradientTheme.TYPE); registrar.addThemeType(WailaConstants.THEME_TYPE_NINE_PATCH, NinePatchTheme.TYPE); } diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreCommonPlugin.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreCommonPlugin.java new file mode 100644 index 000000000..9c6c34cf5 --- /dev/null +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/CoreCommonPlugin.java @@ -0,0 +1,26 @@ +package mcp.mobius.waila.plugin.core; + +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaCommonPlugin; +import mcp.mobius.waila.api.IWailaConfig.Overlay.Position.Align; +import mcp.mobius.waila.api.WailaConstants; +import mcp.mobius.waila.plugin.core.provider.data.NameableBlockDataProvider; +import net.minecraft.world.Nameable; + +public class CoreCommonPlugin implements IWailaCommonPlugin { + + @Override + public void register(ICommonRegistrar registrar) { + registrar.addConfig(WailaConstants.CONFIG_SHOW_BLOCK, true); + registrar.addConfig(WailaConstants.CONFIG_SHOW_FLUID, false); + registrar.addConfig(WailaConstants.CONFIG_SHOW_ENTITY, true); + registrar.addConfig(WailaConstants.CONFIG_SHOW_ICON, true); + registrar.addConfig(WailaConstants.CONFIG_ICON_POSITION, Align.Y.MIDDLE); + registrar.addConfig(WailaConstants.CONFIG_SHOW_MOD_NAME, true); + registrar.addConfig(WailaConstants.CONFIG_SHOW_ITEM_MOD_NAME, true); + registrar.addConfig(WailaConstants.CONFIG_SHOW_REGISTRY, false); + + registrar.addBlockData(NameableBlockDataProvider.INSTANCE, Nameable.class); + } + +} diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/BlockProvider.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/BlockProvider.java index fae1fe3b2..5d1ae5d23 100644 --- a/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/BlockProvider.java +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/BlockProvider.java @@ -3,11 +3,8 @@ import mcp.mobius.waila.api.IBlacklistConfig; import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IModInfo; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITargetRedirector; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.ITooltipComponent; @@ -15,12 +12,10 @@ import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.api.component.ItemComponent; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.Nameable; import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.Nullable; -public enum BlockProvider implements IBlockComponentProvider, IDataProvider { +public enum BlockProvider implements IBlockComponentProvider { INSTANCE; @@ -68,14 +63,4 @@ public void appendTail(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (accessor.getTarget() instanceof Nameable nameable) { - var name = nameable.getCustomName(); - if (name != null) { - data.raw().putString("customName", name.getString()); - } - } - } - } diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/data/NameableBlockDataProvider.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/data/NameableBlockDataProvider.java new file mode 100644 index 000000000..b434a80a9 --- /dev/null +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/provider/data/NameableBlockDataProvider.java @@ -0,0 +1,24 @@ +package mcp.mobius.waila.plugin.core.provider.data; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import net.minecraft.world.Nameable; +import net.minecraft.world.level.block.entity.BlockEntity; + +public enum NameableBlockDataProvider implements IDataProvider { + + INSTANCE; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (accessor.getTarget() instanceof Nameable nameable) { + var name = nameable.getCustomName(); + if (name != null) { + data.raw().putString("customName", name.getString()); + } + } + } + +} diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/ExtraPlugin.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/ExtraPlugin.java new file mode 100644 index 000000000..ffd53e155 --- /dev/null +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/ExtraPlugin.java @@ -0,0 +1,36 @@ +package mcp.mobius.waila.plugin.extra; + +import mcp.mobius.waila.api.IClientRegistrar; +import mcp.mobius.waila.api.ICommonRegistrar; +import mcp.mobius.waila.api.IWailaClientPlugin; +import mcp.mobius.waila.api.IWailaCommonPlugin; +import mcp.mobius.waila.plugin.extra.provider.EnergyProvider; +import mcp.mobius.waila.plugin.extra.provider.FluidProvider; +import mcp.mobius.waila.plugin.extra.provider.ItemProvider; +import mcp.mobius.waila.plugin.extra.provider.ProgressProvider; + +/** + * waila:extra is a pretty special plugin. + *

+ * Do NOT copy the code structure for your own plugins. + * See the vanilla plugin for what a plugin should look like. + */ +public class ExtraPlugin implements IWailaCommonPlugin, IWailaClientPlugin { + + @Override + public void register(ICommonRegistrar registrar) { + EnergyProvider.INSTANCE.register(registrar, 500); + FluidProvider.INSTANCE.register(registrar, 550); + ProgressProvider.INSTANCE.register(registrar, 1500); + ItemProvider.INSTANCE.register(registrar, 1550); + } + + @Override + public void register(IClientRegistrar registrar) { + EnergyProvider.INSTANCE.register(registrar, 500); + FluidProvider.INSTANCE.register(registrar, 550); + ProgressProvider.INSTANCE.register(registrar, 1500); + ItemProvider.INSTANCE.register(registrar, 1550); + } + +} diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/WailaPluginExtra.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/WailaPluginExtra.java deleted file mode 100644 index 231ca8505..000000000 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/WailaPluginExtra.java +++ /dev/null @@ -1,20 +0,0 @@ -package mcp.mobius.waila.plugin.extra; - -import mcp.mobius.waila.api.IRegistrar; -import mcp.mobius.waila.api.IWailaPlugin; -import mcp.mobius.waila.plugin.extra.provider.EnergyProvider; -import mcp.mobius.waila.plugin.extra.provider.FluidProvider; -import mcp.mobius.waila.plugin.extra.provider.ItemProvider; -import mcp.mobius.waila.plugin.extra.provider.ProgressProvider; - -public class WailaPluginExtra implements IWailaPlugin { - - @Override - public void register(IRegistrar registrar) { - EnergyProvider.INSTANCE.register(registrar, 500); - FluidProvider.INSTANCE.register(registrar, 550); - ProgressProvider.INSTANCE.register(registrar, 1500); - ItemProvider.INSTANCE.register(registrar, 1550); - } - -} diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java index 005d2a01d..7968c9955 100644 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java @@ -7,6 +7,8 @@ import com.google.gson.GsonBuilder; import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IClientRegistrar; +import mcp.mobius.waila.api.ICommonRegistrar; import mcp.mobius.waila.api.IData; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataReader; @@ -15,7 +17,6 @@ import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IJsonConfig; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IRegistrar; import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.TooltipPosition; @@ -63,24 +64,32 @@ protected DataProvider(IData.Type type, StreamCodec { +public enum BeaconProvider implements IBlockComponentProvider { INSTANCE; - public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("beacon")); - public static final StreamCodec DATA_CODEC = StreamCodec.composite( - WailaHelper.nullable(ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT)), Data::primary, - WailaHelper.nullable(ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT)), Data::secondary, - Data::new); - private MutableComponent getText(Holder effect) { return effect.value().getDisplayName().copy(); } @@ -40,38 +22,18 @@ private MutableComponent getText(Holder effect) { public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { if (!config.getBoolean(Options.EFFECT_BEACON)) return; - var data = accessor.getData().get(DATA); + var data = accessor.getData().get(BeaconDataProvider.DATA); if (data == null) return; - if (data.primary != null) { - var text = getText(data.primary); - if (data.primary == data.secondary) text.append(" II"); + if (data.primary() != null) { + var text = getText(data.primary()); + if (data.primary() == data.secondary()) text.append(" II"); tooltip.addLine(text); } - if (data.secondary != null && data.primary != data.secondary) { - tooltip.addLine(getText(data.secondary)); + if (data.secondary() != null && data.primary() != data.secondary()) { + tooltip.addLine(getText(data.secondary())); } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.EFFECT_BEACON)) data.add(DATA, res -> { - var beacon = (BeaconBlockEntity & BeaconBlockEntityAccess) accessor.getTarget(); - res.add(new Data(beacon.wthit_primaryPower(), beacon.wthit_levels() >= 4 ? beacon.wthit_secondaryPower() : null)); - }); - } - - public record Data( - @Nullable Holder primary, - @Nullable Holder secondary - ) implements IData { - - @Override - public Type type() { - return DATA; - } - - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java index 5be2c2c74..05dd3d175 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java @@ -1,61 +1,29 @@ package mcp.mobius.waila.plugin.vanilla.provider; -import mcp.mobius.waila.api.IData; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IEntityAccessor; import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.component.PairComponent; import mcp.mobius.waila.api.component.PositionComponent; import mcp.mobius.waila.api.component.WrappedComponent; import mcp.mobius.waila.buildconst.Tl; import mcp.mobius.waila.plugin.vanilla.config.Options; -import net.minecraft.core.BlockPos; -import net.minecraft.network.RegistryFriendlyByteBuf; +import mcp.mobius.waila.plugin.vanilla.provider.data.BeeDataProvider; import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.animal.Bee; -public enum BeeProvider implements IEntityComponentProvider, IDataProvider { +public enum BeeProvider implements IEntityComponentProvider { INSTANCE; - public static final IData.Type HIVE_POS_DATA = IData.createType(ResourceLocation.withDefaultNamespace("bee.hive_pos")); - public static final StreamCodec HIVE_POS_DATA_CODEC = StreamCodec.composite( - BlockPos.STREAM_CODEC, HivePosData::pos, - HivePosData::new); - @Override public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { - var hivePos = accessor.getData().get(HIVE_POS_DATA); + var hivePos = accessor.getData().get(BeeDataProvider.HIVE_POS); if (hivePos != null && config.getBoolean(Options.BEE_HIVE_POS)) { tooltip.addLine(new PairComponent( new WrappedComponent(Component.translatable(Tl.Tooltip.Bee.HIVE)), - new PositionComponent(hivePos.pos))); - } - } - - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.BEE_HIVE_POS)) { - var hivePos = accessor.getTarget().getHivePos(); - if (hivePos != null) { - data.addImmediate(new HivePosData(hivePos)); - } + new PositionComponent(hivePos.pos()))); } } - public record HivePosData(BlockPos pos) implements IData { - - @Override - public Type type() { - return HIVE_POS_DATA; - } - - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java index 7fca47437..a0013f3fa 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java @@ -1,56 +1,33 @@ package mcp.mobius.waila.plugin.vanilla.provider; -import java.util.ArrayList; -import java.util.List; - import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; -import mcp.mobius.waila.api.IData; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; -import mcp.mobius.waila.api.WailaHelper; import mcp.mobius.waila.api.component.PairComponent; import mcp.mobius.waila.buildconst.Tl; -import mcp.mobius.waila.mixin.BeehiveBlockEntityAccess; import mcp.mobius.waila.plugin.vanilla.config.Options; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.Tag; -import net.minecraft.network.RegistryFriendlyByteBuf; +import mcp.mobius.waila.plugin.vanilla.provider.data.BeehiveDataProvider; import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.block.BeehiveBlock; -import net.minecraft.world.level.block.entity.BeehiveBlockEntity; -import org.jetbrains.annotations.Nullable; -public enum BeehiveProvider implements IBlockComponentProvider, IDataProvider { +public enum BeehiveProvider implements IBlockComponentProvider { INSTANCE; - public static final IData.Type OCCUPANTS_DATA = IData.createType(ResourceLocation.withDefaultNamespace("bee.occupants")); - public static final StreamCodec OCCUPANTS_DATA_CODEC = StreamCodec.composite( - StreamCodec.composite( - ByteBufCodecs.registry(Registries.ENTITY_TYPE), OccupantsData.Occupant::entityType, - WailaHelper.nullable(ByteBufCodecs.STRING_UTF8), OccupantsData.Occupant::customName, - OccupantsData.Occupant::new).apply(ByteBufCodecs.list()), OccupantsData::occupants, - OccupantsData::new); - @Override public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { - var occupants = accessor.getData().get(OCCUPANTS_DATA); + var occupants = accessor.getData().get(BeehiveDataProvider.OCCUPANTS); if (occupants != null && config.getBoolean(Options.BEE_HIVE_OCCUPANTS)) { - var names = new Object2IntLinkedOpenHashMap(occupants.occupants.size()); + var names = new Object2IntLinkedOpenHashMap(occupants.occupants().size()); - for (var occupant : occupants.occupants) { + for (var occupant : occupants.occupants()) { Component component = null; - if (occupant.customName != null) component = Component.Serializer.fromJson(occupant.customName, accessor.getWorld().registryAccess()); - if (component == null) component = occupant.entityType.getDescription(); + if (occupant.customName() != null) { + component = Component.Serializer.fromJson(occupant.customName(), accessor.getWorld().registryAccess()); + } + if (component == null) component = occupant.entityType().getDescription(); var name = component.getString(); names.put(name, names.getOrDefault(name, 0) + 1); @@ -72,42 +49,4 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.BEE_HIVE_OCCUPANTS)) { - var stored = ((BeehiveBlockEntityAccess) accessor.getTarget()).wthit_stored(); - if (!stored.isEmpty()) { - var occupants = new ArrayList(stored.size()); - - for (var beeData : stored) { - var beeNbt = beeData.wthit_occupant().entityData().getUnsafe(); - - var entityType = EntityType.by(beeNbt); - if (entityType.isEmpty()) continue; - - var customName = beeNbt.contains("CustomName", Tag.TAG_STRING) - ? beeNbt.getString("CustomName") - : null; - - occupants.add(new OccupantsData.Occupant(entityType.get(), customName)); - } - - if (!occupants.isEmpty()) data.addImmediate(new OccupantsData(occupants)); - } - } - } - - public record OccupantsData(List occupants) implements IData { - - public record Occupant(EntityType entityType, @Nullable String customName) { - - } - - @Override - public Type type() { - return OCCUPANTS_DATA; - } - - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ChiseledBookShelfProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ChiseledBookShelfProvider.java index 85633d4b2..a46bd1e08 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ChiseledBookShelfProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ChiseledBookShelfProvider.java @@ -1,43 +1,25 @@ package mcp.mobius.waila.plugin.vanilla.provider; -import java.util.ArrayList; -import java.util.List; - import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; -import mcp.mobius.waila.api.IData; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IModInfo; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.ITooltipComponent; import mcp.mobius.waila.api.IWailaConfig; import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.api.component.ItemComponent; -import mcp.mobius.waila.api.data.ItemData; import mcp.mobius.waila.mixin.ChiseledBookShelfBlockAccess; -import mcp.mobius.waila.mixin.ChiseledBookShelfBlockEntityAccess; import mcp.mobius.waila.plugin.vanilla.config.Options; +import mcp.mobius.waila.plugin.vanilla.provider.data.ChiseledBookShelfDataProvider; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; import org.jetbrains.annotations.Nullable; -public enum ChiseledBookShelfProvider implements IBlockComponentProvider, IDataProvider { +public enum ChiseledBookShelfProvider implements IBlockComponentProvider { INSTANCE; - public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("chiseled_bookshelf")); - public static final StreamCodec DATA_CODEC = StreamCodec.composite( - ByteBufCodecs.collection(ArrayList::new, ItemStack.OPTIONAL_STREAM_CODEC), Data::items, - Data::new); - private int lastUpdateId = 0; private ItemStack hitItem = ItemStack.EMPTY; @@ -48,14 +30,14 @@ private void init(IBlockAccessor accessor, IPluginConfig config) { hitItem = ItemStack.EMPTY; if (!config.getBoolean(Options.BOOK_BOOKSHELF)) return; - var data = accessor.getData().get(DATA); + var data = accessor.getData().get(ChiseledBookShelfDataProvider.DATA); if (data == null) return; var block = ((ChiseledBookShelfBlockAccess) accessor.getBlock()); var hitSlot = block.wthit_getHitSlot(accessor.getBlockHitResult(), accessor.getBlockState()); if (hitSlot.isEmpty()) return; - hitItem = data.items.get(hitSlot.getAsInt()); + hitItem = data.items().get(hitSlot.getAsInt()); } @Override @@ -96,25 +78,4 @@ public void appendTail(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig tooltip.setLine(WailaConstants.MOD_NAME_TAG, IWailaConfig.get().getFormatter().modName(IModInfo.get(hitItem).getName())); } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - data.blockAll(ItemData.TYPE); - - if (config.getBoolean(Options.BOOK_BOOKSHELF)) data.add(DATA, res -> { - var bookshelf = (ChiseledBookShelfBlockEntityAccess) accessor.getTarget(); - res.add(new Data(bookshelf.wthit_items())); - }); - } - - public record Data( - List items - ) implements IData { - - @Override - public Type type() { - return DATA; - } - - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java index 02e147c70..1238d4f0d 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java @@ -2,12 +2,9 @@ import java.text.DecimalFormat; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IEntityAccessor; import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.ITooltipLine; import mcp.mobius.waila.api.component.ArmorComponent; @@ -20,10 +17,9 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -public enum EntityAttributesProvider implements IEntityComponentProvider, IDataProvider { +public enum EntityAttributesProvider implements IEntityComponentProvider { INSTANCE; @@ -115,13 +111,4 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (accessor.getTarget() instanceof LivingEntity living) { - if (config.getBoolean(Options.ENTITY_ABSORPTION) && living.getAbsorptionAmount() > 0) { - data.raw().putFloat("abs", living.getAbsorptionAmount()); - } - } - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java index a524fcfea..6c68c0a51 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java @@ -2,17 +2,12 @@ import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.plugin.vanilla.config.Options; -import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; -import net.minecraft.world.level.block.entity.JukeboxBlockEntity; -public enum JukeboxProvider implements IBlockComponentProvider, IDataProvider { +public enum JukeboxProvider implements IBlockComponentProvider { INSTANCE; @@ -24,17 +19,4 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.JUKEBOX_RECORD)) { - var stack = accessor.getTarget().getTheItem(); - if (!stack.isEmpty()) { - var text = stack.get(DataComponents.JUKEBOX_PLAYABLE) != null - ? Component.translatable(stack.getDescriptionId() + ".desc") - : stack.getDisplayName(); - data.raw().putString("record", Component.Serializer.toJson(text, accessor.getWorld().registryAccess())); - } - } - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java index eb675638a..1af67bee3 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java @@ -1,45 +1,28 @@ package mcp.mobius.waila.plugin.vanilla.provider; -import java.util.ArrayList; -import java.util.List; - -import mcp.mobius.waila.api.IData; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IEntityAccessor; import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.plugin.vanilla.config.Options; +import mcp.mobius.waila.plugin.vanilla.provider.data.MobEffectDataProvider; import net.minecraft.ChatFormatting; import net.minecraft.client.resources.language.I18n; -import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffectCategory; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.LivingEntity; -public enum MobEffectProvider implements IEntityComponentProvider, IDataProvider { +public enum MobEffectProvider implements IEntityComponentProvider { INSTANCE; - public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("mob_effects")); - public static final StreamCodec DATA_CODEC = StreamCodec.composite( - ByteBufCodecs.collection(ArrayList::new, MobEffectInstance.STREAM_CODEC), Data::list, - Data::new); - @Override public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { if (!config.getBoolean(Options.EFFECT_MOB)) return; - var data = accessor.getData().get(DATA); + var data = accessor.getData().get(MobEffectDataProvider.DATA); if (data == null) return; - data.list.forEach(it -> { + data.list().forEach(it -> { var text = Component.translatable(it.getDescriptionId()); var amplifier = it.getAmplifier(); @@ -57,25 +40,4 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig }); } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.EFFECT_MOB)) data.add(DATA, res -> res.add(new Data(accessor - .getTarget() - .getActiveEffects() - .stream() - .filter(it -> it.isVisible() || config.getBoolean(Options.EFFECT_HIDDEN_MOB)) - .toList()))); - } - - public record Data( - List list - ) implements IData { - - @Override - public Type type() { - return DATA; - } - - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java index 584f39b60..d42fd05b6 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java @@ -1,19 +1,15 @@ package mcp.mobius.waila.plugin.vanilla.provider; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IEntityAccessor; import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.component.PairComponent; import mcp.mobius.waila.buildconst.Tl; import mcp.mobius.waila.plugin.vanilla.config.Options; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.AgeableMob; -public enum MobTimerProvider implements IEntityComponentProvider, IDataProvider { +public enum MobTimerProvider implements IEntityComponentProvider { INSTANCE; @@ -63,10 +59,4 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - var mob = accessor.getTarget(); - data.raw().putInt("age", mob.getAge()); - } - } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java index 0bc58f47d..1b937858d 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java @@ -14,22 +14,18 @@ import com.google.common.base.Suppliers; import com.google.common.util.concurrent.Futures; import com.google.gson.JsonParser; -import mcp.mobius.waila.api.IDataProvider; -import mcp.mobius.waila.api.IDataWriter; import mcp.mobius.waila.api.IEntityAccessor; import mcp.mobius.waila.api.IEntityComponentProvider; import mcp.mobius.waila.api.IPluginConfig; -import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.component.PairComponent; import mcp.mobius.waila.buildconst.Tl; import mcp.mobius.waila.plugin.vanilla.config.Options; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.OwnableEntity; -public enum PetOwnerProvider implements IEntityComponentProvider, IDataProvider { +public enum PetOwnerProvider implements IEntityComponentProvider { INSTANCE; @@ -64,14 +60,6 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig } } - @Override - public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { - if (config.getBoolean(Options.PET_OWNER)) { - var uuid = ((OwnableEntity) accessor.getTarget()).getOwnerUUID(); - if (uuid != null) data.raw().putUUID("owner", uuid); - } - } - private Future requestOwner(UUID uuid) { return HTTP.get().sendAsync(HttpRequest.newBuilder() .uri(URI.create("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid)) diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BaseContainerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BaseContainerDataProvider.java similarity index 83% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BaseContainerProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BaseContainerDataProvider.java index 8d97c499f..b5a479e6c 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BaseContainerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BaseContainerDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -8,7 +8,7 @@ import mcp.mobius.waila.mixin.BaseContainerBlockEntityAccess; import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; -public enum BaseContainerProvider implements IDataProvider { +public enum BaseContainerDataProvider implements IDataProvider { INSTANCE; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeaconDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeaconDataProvider.java new file mode 100644 index 000000000..e88bb2fd1 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeaconDataProvider.java @@ -0,0 +1,51 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.WailaHelper; +import mcp.mobius.waila.mixin.BeaconBlockEntityAccess; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.level.block.entity.BeaconBlockEntity; +import org.jetbrains.annotations.Nullable; + +public enum BeaconDataProvider implements IDataProvider { + + INSTANCE; + + public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("beacon")); + public static final StreamCodec DATA_CODEC = StreamCodec.composite( + WailaHelper.nullable(ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT)), Data::primary, + WailaHelper.nullable(ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT)), Data::secondary, + Data::new); + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.EFFECT_BEACON)) data.add(DATA, res -> { + var beacon = (BeaconBlockEntity & BeaconBlockEntityAccess) accessor.getTarget(); + res.add(new Data(beacon.wthit_primaryPower(), beacon.wthit_levels() >= 4 ? beacon.wthit_secondaryPower() : null)); + }); + } + + public record Data( + @Nullable Holder primary, + @Nullable Holder secondary + ) implements IData { + + @Override + public Type type() { + return DATA; + } + + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeeDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeeDataProvider.java new file mode 100644 index 000000000..4f2890b23 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeeDataProvider.java @@ -0,0 +1,43 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.core.BlockPos; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.animal.Bee; + +public enum BeeDataProvider implements IDataProvider { + + INSTANCE; + + public static final IData.Type HIVE_POS = IData.createType(ResourceLocation.withDefaultNamespace("bee.hive_pos")); + public static final StreamCodec HIVE_POS_CODEC = StreamCodec.composite( + BlockPos.STREAM_CODEC, HivePosData::pos, + HivePosData::new); + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.BEE_HIVE_POS)) { + var hivePos = accessor.getTarget().getHivePos(); + if (hivePos != null) { + data.addImmediate(new HivePosData(hivePos)); + } + } + } + + public record HivePosData(BlockPos pos) implements IData { + + @Override + public Type type() { + return HIVE_POS; + } + + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeehiveDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeehiveDataProvider.java new file mode 100644 index 000000000..ed1ba83b5 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/BeehiveDataProvider.java @@ -0,0 +1,72 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import java.util.ArrayList; +import java.util.List; + +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.WailaHelper; +import mcp.mobius.waila.mixin.BeehiveBlockEntityAccess; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.Tag; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.block.entity.BeehiveBlockEntity; +import org.jetbrains.annotations.Nullable; + +public enum BeehiveDataProvider implements IDataProvider { + + INSTANCE; + + public static final IData.Type OCCUPANTS = IData.createType(ResourceLocation.withDefaultNamespace("bee.occupants")); + public static final StreamCodec OCCUPANTS_CODEC = StreamCodec.composite( + StreamCodec.composite( + ByteBufCodecs.registry(Registries.ENTITY_TYPE), OccupantsData.Occupant::entityType, + WailaHelper.nullable(ByteBufCodecs.STRING_UTF8), OccupantsData.Occupant::customName, + OccupantsData.Occupant::new).apply(ByteBufCodecs.list()), OccupantsData::occupants, + OccupantsData::new); + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.BEE_HIVE_OCCUPANTS)) { + var stored = ((BeehiveBlockEntityAccess) accessor.getTarget()).wthit_stored(); + if (!stored.isEmpty()) { + var occupants = new ArrayList(stored.size()); + + for (var beeData : stored) { + var beeNbt = beeData.wthit_occupant().entityData().getUnsafe(); + + var entityType = EntityType.by(beeNbt); + if (entityType.isEmpty()) continue; + + var customName = beeNbt.contains("CustomName", Tag.TAG_STRING) + ? beeNbt.getString("CustomName") + : null; + + occupants.add(new OccupantsData.Occupant(entityType.get(), customName)); + } + + if (!occupants.isEmpty()) data.addImmediate(new OccupantsData(occupants)); + } + } + } + + public record OccupantsData(List occupants) implements IData { + + public record Occupant(EntityType entityType, @Nullable String customName) {} + + @Override + public Type type() { + return OCCUPANTS; + } + + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ChiseledBookShelfDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ChiseledBookShelfDataProvider.java new file mode 100644 index 000000000..39eacfc6f --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ChiseledBookShelfDataProvider.java @@ -0,0 +1,51 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import java.util.ArrayList; +import java.util.List; + +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.ItemData; +import mcp.mobius.waila.mixin.ChiseledBookShelfBlockEntityAccess; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; + +public enum ChiseledBookShelfDataProvider implements IDataProvider { + + INSTANCE; + + public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("chiseled_bookshelf")); + public static final StreamCodec DATA_CODEC = StreamCodec.composite( + ByteBufCodecs.collection(ArrayList::new, ItemStack.OPTIONAL_STREAM_CODEC), Data::items, + Data::new); + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.blockAll(ItemData.TYPE); + + if (config.getBoolean(Options.BOOK_BOOKSHELF)) data.add(DATA, res -> { + var bookshelf = (ChiseledBookShelfBlockEntityAccess) accessor.getTarget(); + res.add(new Data(bookshelf.wthit_items())); + }); + } + + public record Data( + List items + ) implements IData { + + @Override + public Type type() { + return DATA; + } + + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ContainerEntityProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ContainerEntityDataProvider.java similarity index 86% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ContainerEntityProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ContainerEntityDataProvider.java index 5f0c5a2ca..6e4dd4e3c 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ContainerEntityProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/ContainerEntityDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -9,7 +9,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.vehicle.ContainerEntity; -public enum ContainerEntityProvider implements IDataProvider { +public enum ContainerEntityDataProvider implements IDataProvider { INSTANCE; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EnderChestProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EnderChestDataProvider.java similarity index 80% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EnderChestProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EnderChestDataProvider.java index 8c4cd1b51..d4e650d8d 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EnderChestProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EnderChestDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -7,7 +7,7 @@ import mcp.mobius.waila.api.data.ItemData; import net.minecraft.world.level.block.entity.EnderChestBlockEntity; -public enum EnderChestProvider implements IDataProvider { +public enum EnderChestDataProvider implements IDataProvider { INSTANCE; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EntityAttributesDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EntityAttributesDataProvider.java new file mode 100644 index 000000000..87ad41aa9 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/EntityAttributesDataProvider.java @@ -0,0 +1,24 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; + +public enum EntityAttributesDataProvider implements IDataProvider { + + INSTANCE; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (accessor.getTarget() instanceof LivingEntity living) { + if (config.getBoolean(Options.ENTITY_ABSORPTION) && living.getAbsorptionAmount() > 0) { + data.raw().putFloat("abs", living.getAbsorptionAmount()); + } + } + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/FurnaceDataProvider.java similarity index 88% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/FurnaceDataProvider.java index 0d50cf828..7bca59e01 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/FurnaceDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -9,7 +9,7 @@ import net.minecraft.world.level.block.AbstractFurnaceBlock; import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; -public enum FurnaceProvider implements IDataProvider { +public enum FurnaceDataProvider implements IDataProvider { INSTANCE; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HopperContainerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/HopperContainerDataProvider.java similarity index 84% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HopperContainerProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/HopperContainerDataProvider.java index afbb4dca2..6b9be71d9 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HopperContainerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/HopperContainerDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -8,7 +8,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.HopperBlockEntity; -public enum HopperContainerProvider implements IDataProvider { +public enum HopperContainerDataProvider implements IDataProvider { INSTANCE; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java new file mode 100644 index 000000000..dfdfdb4e9 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java @@ -0,0 +1,29 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.entity.JukeboxBlockEntity; + +public enum JukeboxDataProvider implements IDataProvider { + + INSTANCE; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.JUKEBOX_RECORD)) { + var stack = accessor.getTarget().getTheItem(); + if (!stack.isEmpty()) { + var text = stack.get(DataComponents.JUKEBOX_PLAYABLE) != null + ? Component.translatable(stack.getDescriptionId() + ".desc") + : stack.getDisplayName(); + data.raw().putString("record", Component.Serializer.toJson(text, accessor.getWorld().registryAccess())); + } + } + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobEffectDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobEffectDataProvider.java new file mode 100644 index 000000000..d5b26b906 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobEffectDataProvider.java @@ -0,0 +1,49 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import java.util.ArrayList; +import java.util.List; + +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.LivingEntity; + +public enum MobEffectDataProvider implements IDataProvider { + + INSTANCE; + + public static final IData.Type DATA = IData.createType(ResourceLocation.withDefaultNamespace("mob_effects")); + public static final StreamCodec DATA_CODEC = StreamCodec.composite( + ByteBufCodecs.collection(ArrayList::new, MobEffectInstance.STREAM_CODEC), Data::list, + Data::new); + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.EFFECT_MOB)) data.add(DATA, res -> res.add(new Data(accessor + .getTarget() + .getActiveEffects() + .stream() + .filter(it -> it.isVisible() || config.getBoolean(Options.EFFECT_HIDDEN_MOB)) + .toList()))); + } + + public record Data( + List list + ) implements IData { + + @Override + public Type type() { + return DATA; + } + + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobTimerDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobTimerDataProvider.java new file mode 100644 index 000000000..97961224c --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/MobTimerDataProvider.java @@ -0,0 +1,19 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import net.minecraft.world.entity.AgeableMob; + +public enum MobTimerDataProvider implements IDataProvider { + + INSTANCE; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + var mob = accessor.getTarget(); + data.raw().putInt("age", mob.getAge()); + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/PetOwnerDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/PetOwnerDataProvider.java new file mode 100644 index 000000000..532caff77 --- /dev/null +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/PetOwnerDataProvider.java @@ -0,0 +1,23 @@ +package mcp.mobius.waila.plugin.vanilla.provider.data; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.plugin.vanilla.config.Options; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.OwnableEntity; + +public enum PetOwnerDataProvider implements IDataProvider { + + INSTANCE; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(Options.PET_OWNER)) { + var uuid = ((OwnableEntity) accessor.getTarget()).getOwnerUUID(); + if (uuid != null) data.raw().putUUID("owner", uuid); + } + } + +} diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RandomizableContainerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/RandomizableContainerDataProvider.java similarity index 81% rename from src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RandomizableContainerProvider.java rename to src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/RandomizableContainerDataProvider.java index 43a035936..6e4498068 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RandomizableContainerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/RandomizableContainerDataProvider.java @@ -1,4 +1,4 @@ -package mcp.mobius.waila.plugin.vanilla.provider; +package mcp.mobius.waila.plugin.vanilla.provider.data; import mcp.mobius.waila.api.IDataProvider; import mcp.mobius.waila.api.IDataWriter; @@ -8,7 +8,7 @@ import net.minecraft.world.RandomizableContainer; import net.minecraft.world.level.block.entity.BlockEntity; -public enum RandomizableContainerProvider implements IDataProvider { +public enum RandomizableContainerDataProvider implements IDataProvider { INSTANCE;