forked from Haven-King/glowcase
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Patbox/1.20
Add polydex support, fix hyperlink text's shadow rendering in front
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/dev/hephaestus/glowcase/compat/PolydexCompatibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} | ||
} |