From e6c869f3fe50b54d8a0578ba5523b3b57301a689 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Tue, 15 Aug 2023 13:55:44 +0200 Subject: [PATCH] Add polydex support, fix hyperlink text's shadow rendering in front --- build.gradle | 2 + .../dev/hephaestus/glowcase/Glowcase.java | 6 +++ .../entity/HyperlinkBlockEntityRenderer.java | 2 + .../glowcase/compat/PolydexCompatibility.java | 47 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/main/java/dev/hephaestus/glowcase/compat/PolydexCompatibility.java diff --git a/build.gradle b/build.gradle index 1ac5a1a..c7453ce 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,8 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation include("eu.pb4:placeholder-api:2.1.2+1.20.1") + modCompileOnly "eu.pb4:polydex:1.0.0-beta.2.2+1.20.1" + modLocalRuntime "eu.pb4:polydex:1.0.0-beta.2.2+1.20.1" } diff --git a/src/main/java/dev/hephaestus/glowcase/Glowcase.java b/src/main/java/dev/hephaestus/glowcase/Glowcase.java index 6dd3a0a..65bc77f 100644 --- a/src/main/java/dev/hephaestus/glowcase/Glowcase.java +++ b/src/main/java/dev/hephaestus/glowcase/Glowcase.java @@ -12,7 +12,9 @@ import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity; import dev.hephaestus.glowcase.block.entity.MailboxBlockEntity; import dev.hephaestus.glowcase.block.entity.TextBlockEntity; +import dev.hephaestus.glowcase.compat.PolydexCompatibility; import dev.hephaestus.glowcase.networking.GlowcaseCommonNetworking; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.command.argument.BlockPosArgumentType; import net.minecraft.entity.player.PlayerEntity; @@ -88,6 +90,10 @@ public void onInitialize() { .then(CommandManager.argument("message", StringArgumentType.greedyString()).executes(this::sendMessage))) ); }); + + if (FabricLoader.getInstance().isModLoaded("polydex2")) { + PolydexCompatibility.onInitialize(); + } } private int sendMessage(CommandContext ctx) throws CommandSyntaxException { diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java index 69deeed..b090ad3 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java @@ -38,6 +38,8 @@ public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, V float scale = 0.025F; matrices.scale(scale, scale, scale); matrices.translate(-context.getTextRenderer().getWidth(entity.getUrl()) / 2F, -4, scale); + // Fixes shadow being rendered in front of actual text + matrices.scale(1, 1, -1); context.getTextRenderer().draw(entity.getUrl(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); } matrices.pop(); diff --git a/src/main/java/dev/hephaestus/glowcase/compat/PolydexCompatibility.java b/src/main/java/dev/hephaestus/glowcase/compat/PolydexCompatibility.java new file mode 100644 index 0000000..816c726 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/compat/PolydexCompatibility.java @@ -0,0 +1,47 @@ +package dev.hephaestus.glowcase.compat; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity; +import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity; +import eu.pb4.polydex.api.v1.hover.HoverDisplayBuilder; +import eu.pb4.polydex.impl.PolydexImpl; +import net.minecraft.registry.Registries; +import net.minecraft.text.Text; + +/** + * Makes Polydex hover display more correct information + * + * @author Patbox + */ +public class PolydexCompatibility { + public static void onInitialize() { + HoverDisplayBuilder.register(Glowcase.ITEM_DISPLAY_BLOCK, PolydexCompatibility::setupItemDisplayBlock); + HoverDisplayBuilder.register(Glowcase.HYPERLINK_BLOCK, PolydexCompatibility::setupHyperlinkBlock); + } + + private static void setupHyperlinkBlock(HoverDisplayBuilder hoverDisplayBuilder) { + var target = hoverDisplayBuilder.getTarget(); + if (target.player().isCreative()) { + return; + } + + if (target.blockEntity() instanceof HyperlinkBlockEntity blockEntity && !blockEntity.getUrl().isEmpty()) { + hoverDisplayBuilder.setComponent(HoverDisplayBuilder.NAME, Text.literal(blockEntity.getUrl())); + hoverDisplayBuilder.setComponent(HoverDisplayBuilder.MOD_SOURCE, Text.literal("Internet")); + } + } + + private static void setupItemDisplayBlock(HoverDisplayBuilder hoverDisplayBuilder) { + var target = hoverDisplayBuilder.getTarget(); + if (target.player().isCreative()) { + return; + } + + if (target.blockEntity() instanceof ItemDisplayBlockEntity blockEntity && blockEntity.hasItem()) { + var item = blockEntity.getDisplayedStack(); + hoverDisplayBuilder.setComponent(HoverDisplayBuilder.NAME, item.getName()); + // I won't break this I promise + hoverDisplayBuilder.setComponent(HoverDisplayBuilder.MOD_SOURCE, PolydexImpl.getMod(Registries.ITEM.getId(item.getItem()))); + } + } +}