Jump to content

[1.15.2] Display text in the upper right


Peyang

Recommended Posts

(Please forgive me for using a translator. :D

I wanted to show strings on the display and created a project in 1.15.2.
I ported from the code that worked in 1.8.9, but apparently it doesn't work in 1.15.2.
In the code of 1.8.9
I used Minecraft.getInstance().fontRenderer.drawStringWithShadow() from RenderGameOverlayEvent.Pre.
Since there was the same method in 1.15.2, I wrote it as it is, but it seems that it does not work.

I also tried, but it didn't work. I also tried RenderGameOverlayEvent.Post and so on.

Can anyone please teach me how to display the character string in the upper left corner of the screen?

 

Link to comment
Share on other sites

@SubscribeEvent
public void onRender(final RenderGameOverlayEvent.Pre event)
{
    if (event.getType() != RenderGameOverlayEvent.ElementType.ALL/*HEALTH*/)
        return;
    DrawTest.draw();
}
public void draw()
{
    if (nowWanted == 0)
        return;
    IngameGui gui = Minecraft.getInstance().ingameGUI;
    int maxWidth = Minecraft.getInstance().getMainWindow().getWidth();
    int maxHeight = Minecraft.getInstance().getMainWindow().getHeight();
    int width = Regions.getStringWidth(StringUtils.repeat(/*'\u2606'*/"a", 5));
    String nowS= StringUtils.repeat(/*'\u2605'*/"a", 5);
    String maxS= StringUtils.repeat(/*'\u2606'*/"b", 5);
    String cS= nowS+ maxS;
    Matcher matcher = new Pattern("[\\s]{1,5}").matcher(cS);
    AtomicInteger ip = new AtomicInteger();
    FontRenderer fr = Minecraft.getInstance().fontRenderer;
    while (matcher.find())
    {
        //drawText(matcher.group(), 2, 2);
        gui.drawCenteredString(fr, "Test123", 20, 20, 0xffFFFFFF);
        ip.set(ip.get() + 11);
    }
}

 

 

public static final int FULL_COLOR = Regions.colorFromRGB(255, 255, 255, 255)
public static int colorFromRGB(Number red, Number green, Number blue, Number alpha)
{
    return red.intValue() << 16 | green.intValue() << 8 | blue.intValue() | alpha.intValue() << 24;
}
public static void drawText(String s, int w, int h)
{
    FontRenderer fr = Minecraft.getInstance().fontRenderer;
    fr.drawStringWithShadow(s, (float) w, (float) h, FULL_COLOR);}

 

 

 

Edited by Peyang
Link to comment
Share on other sites

Originally it was created to connect Bukkit and Forge with a Plugin Message. nowWanted is a dedicated plug-in "https://github.com/TeamKun/GTAWantedDisplayTestPlugin" Changed from "/ wanted <max> <now>".

The server is Bukkit Server, not Forge Server.

Also, nowWanted if passed safely and I was able to get standard output.

I look forward to working with you.

Also, this mod does not need to send packets, it intercepts packets from the server.

I pushed the code for this log.

public void draw()
{

    if (nowWanted == 0)
        return;
    System.out.println("nowWanted: " + nowWanted);

image.png.cd88f8ed3c2ac12f449b52c7f32a6687.png

Link to comment
Share on other sites

This is a mod that reproduces the GTA Wanted Star.
1. Build a PaperMC 1.15.2 server.
2. Copy https://github.com/TeamKun/GTAWantedDisplayTestPlugin/releases to plugins and do /reload or /restart.
3. Build https://github.com/TeamKun/GTA5WantedDisplayMod and enter the Bukkit server.
4. From the player, run /wanted <maxWanted> <nowWanted>.
Note: maxWanted is the maximum number of stars and nowWanted is the number of stars to change

Five stars will wrap to the next line.

Test case:


Input /wanted 10 4
Expected output: 
★★★★☆
☆☆☆☆☆

 

Input /wanted 5 3
Expected output: 
★★★☆☆

 

Input /wanted 20 13
Expected output:
★★★★★
★★★★★
★★★☆☆
☆☆☆☆☆

 

I look forward to working with you.
Thank you

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.