Skip to content

Commit

Permalink
Add polydex support, fix hyperlink text's shadow rendering in front
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Aug 15, 2023
1 parent 1d8f779 commit e6c869f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/hephaestus/glowcase/Glowcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ServerCommandSource> ctx) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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())));
}
}
}

0 comments on commit e6c869f

Please sign in to comment.