-
Notifications
You must be signed in to change notification settings - Fork 23
HUD Text API #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zr0n1
wants to merge
14
commits into
ModificationStation:develop
Choose a base branch
from
zr0n1:hud-text-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HUD Text API #122
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c36d9a4
First version of tool items update
mineLdiver 433fa82
Mining levels graph
mineLdiver a6dfbdc
Fix a bad mixin declaration in lifecycle events
calmilamsy 6a63f39
Add RegistriesFrozenEvent
calmilamsy b7c658f
Merge branch 'refs/heads/master' into 2.0-alpha.3
mineLdiver 92353e2
simple hud text api
zr0n1 14de99b
fix flattening hud text offset
zr0n1 af40995
Merge branch 'ModificationStation:master' into hud-text-api
zr0n1 d9513eb
simple hud text api
zr0n1 adf33c8
fix flattening hud text offset
zr0n1 ef9f0a9
Merge remote-tracking branch 'origin/hud-text-api' into hud-text-api
zr0n1 d10742d
clean
zr0n1 3fd3c70
newlines, fixes and documentation
zr0n1 6bc1941
una linea
zr0n1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
src/test/java/net/modificationstation/sltest/gui/hud/TestHudText.java
This file contains hidden or 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,33 @@ | ||
| package net.modificationstation.sltest.gui.hud; | ||
|
|
||
| import net.mine_diver.unsafeevents.listener.EventListener; | ||
| import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine; | ||
| import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextRenderEvent; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class TestHudText { | ||
| private static final int[] COLORS = {0x5BCEFA, 0xF5A9B8, 0xFFFFFF, 0xF5A9B8}; | ||
| private final Random random = new Random(); | ||
| private int frames; | ||
| private int color; | ||
| private int verColor; | ||
|
|
||
| @EventListener | ||
| public void renderHudText(HudTextRenderEvent event) { | ||
| if (frames % 7 == 0) verColor = random.nextInt(0xFFFFFF + 1); | ||
| event.setVersion(new HudTextLine( | ||
| "Statint api 2rd ediction ;)" + (event.debug ? "(" + event.minecraft.debugText + ")" : ""), | ||
| verColor) | ||
| ); | ||
| if (frames > 0 && frames % 15 == 0) { | ||
| color = color + 1 < COLORS.length? color + 1 : 0; | ||
| } | ||
| event.right.add(new HudTextLine("gaming", COLORS[color])); | ||
| if (event.debug) { | ||
| event.left.add(new HudTextLine("This Texts only Shows In de Bugge ?!??! :0")); | ||
| event.right.add(new HudTextLine("this text has a rly big offsets", 0xFF0000, 40)); | ||
| } | ||
| frames++; | ||
| } | ||
| } |
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
src/test/resources/data/minecraft/stationapi/tags/blocks/mineable/pickaxe.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "values": [ | ||
| "sltest:test_block" | ||
| ] | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/test/resources/data/sltest/stationapi/tags/blocks/needs_tool_level_modded.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "values": [ | ||
| "sltest:test_block" | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
...java/net/modificationstation/stationapi/impl/client/gui/hud/StationFlatteningHudText.java
This file contains hidden or 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,59 @@ | ||
| package net.modificationstation.stationapi.impl.client.gui.hud; | ||
|
|
||
| import net.fabricmc.loader.api.FabricLoader; | ||
| import net.mine_diver.unsafeevents.listener.EventListener; | ||
| import net.minecraft.block.Block; | ||
| import net.minecraft.block.entity.BlockEntity; | ||
| import net.minecraft.util.hit.HitResult; | ||
| import net.minecraft.util.hit.HitResultType; | ||
| import net.modificationstation.stationapi.api.StationAPI; | ||
| import net.modificationstation.stationapi.api.block.BlockState; | ||
| import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextRenderEvent; | ||
| import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine; | ||
| import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint; | ||
| import net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy; | ||
| import net.modificationstation.stationapi.api.state.property.Property; | ||
| import net.modificationstation.stationapi.api.tag.TagKey; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| import static net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine.GRAY; | ||
| import static net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine.WHITE; | ||
|
|
||
| @Entrypoint(eventBus = @EventBusPolicy(registerInstance = false)) | ||
| public class StationFlatteningHudText { | ||
| @EventListener(phase = StationAPI.INTERNAL_PHASE) | ||
| private static void renderHudText(HudTextRenderEvent event) { | ||
| if (!event.debug) return; | ||
| HitResult hit = event.minecraft.field_2823; | ||
| if (hit == null || hit.type != HitResultType.BLOCK) return; | ||
| BlockState state = event.minecraft.world.getBlockState(hit.blockX, hit.blockY, hit.blockZ); | ||
| Collections.addAll(event.right, | ||
| new HudTextLine("Block: " + state.getBlock().getTranslatedName(), WHITE, 20), | ||
| new HudTextLine("Meta: " + event.minecraft.world.getBlockMeta(hit.blockX, hit.blockY, hit.blockZ)) | ||
| ); | ||
| Collection<Property<?>> properties = state.getProperties(); | ||
| if (!properties.isEmpty()) { | ||
| event.right.add(new HudTextLine("Properties:")); | ||
| event.right.addAll(properties.stream().map(prop -> | ||
| new HudTextLine(prop.getName() + ": " + state.get(prop), GRAY) | ||
| ).toList()); | ||
| } | ||
|
|
||
| Collection<TagKey<Block>> tags = state.streamTags().toList(); | ||
| if (!tags.isEmpty()) { | ||
| event.right.add(new HudTextLine("Tags:")); | ||
| event.right.addAll(tags.stream().map(tag -> new HudTextLine("#" + tag.id(), GRAY)).toList()); | ||
| } | ||
|
|
||
| if (FabricLoader.getInstance().isDevelopmentEnvironment()) { | ||
| BlockEntity entity = event.minecraft.world.method_1777(hit.blockX, hit.blockY, hit.blockZ); | ||
| if (entity != null) { | ||
| String className = entity.getClass().getName(); | ||
| String text = "Tile Entity: " + className.substring(className.lastIndexOf('.') + 1); | ||
| event.right.add(new HudTextLine(text, WHITE, 20)); | ||
| } | ||
| } | ||
| } | ||
| } |
83 changes: 0 additions & 83 deletions
83
.../main/java/net/modificationstation/stationapi/mixin/flattening/client/InGameHudMixin.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
...rc/main/java/net/modificationstation/stationapi/api/client/event/gui/hud/HudTextLine.java
This file contains hidden or 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,29 @@ | ||
| package net.modificationstation.stationapi.api.client.event.gui.hud; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
|
|
||
| /** | ||
| * Text and info for rendering custom HUD text lines. | ||
| */ | ||
| @AllArgsConstructor | ||
| public final class HudTextLine { | ||
| public static final int WHITE = 0xFFFFFF; | ||
| public static final int GRAY = 0xE0E0E0; | ||
|
|
||
| public String text; | ||
| /** | ||
| * @see net.glasslauncher.mods.api.gcapi.api.CharacterUtils#getIntFromColour(Color) | ||
| */ | ||
| public int color; | ||
| /** | ||
| * Y offset from the last rendered line. | ||
| */ | ||
| public int yOffset; | ||
|
|
||
| public HudTextLine(String text) { | ||
| this(text, WHITE); | ||
| } | ||
| public HudTextLine(String text, int color) { | ||
| this(text, color, 10); | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
.../java/net/modificationstation/stationapi/api/client/event/gui/hud/HudTextRenderEvent.java
This file contains hidden or 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,34 @@ | ||
| package net.modificationstation.stationapi.api.client.event.gui.hud; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.experimental.SuperBuilder; | ||
| import net.mine_diver.unsafeevents.Event; | ||
| import net.mine_diver.unsafeevents.event.EventPhases; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.modificationstation.stationapi.api.StationAPI; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Fires while rendering in-game (debug) HUD text. | ||
| */ | ||
| @SuperBuilder | ||
| @EventPhases({StationAPI.INTERNAL_PHASE, EventPhases.DEFAULT_PHASE}) | ||
| public class HudTextRenderEvent extends Event { | ||
| /** | ||
| * Whether the F3 debug HUD is enabled. | ||
| * @see net.minecraft.client.option.GameOptions#debugHud | ||
| */ | ||
| public final boolean debug; | ||
zr0n1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public final Minecraft minecraft; | ||
| public final List<HudTextLine> left = new ArrayList<>(), right = new ArrayList<>(); | ||
| @Getter private HudTextLine version; | ||
|
|
||
| /** | ||
| * Set by highest priority listener. | ||
calmilamsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| public void setVersion(HudTextLine line) { | ||
| if (version == null) version = line; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.