Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] Display text in the upper right


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 post
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 post
Share on other sites

I cloned your repository, however it does not even let you get into a world, because your network version check is broken (it always rejects the server side version number).

Additionally, the only way the code ever draws something is if nowWanted is not 0. The only code path that sets nowWanted is WantedDisplay#set, which is called from PacketContainer (sidenote: what on earth is that packet sending code doing?!). PacketContainer is never sent by the server. In conclusion: nowWanted is always 0, so nothing ever draws - if you would even get into the world.

Link to post
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 post
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 post
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.

Guest
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I had no clue what topic to put this under because its not really modding with forge but modding forge itself. So I have terrain generation mods that are only server side and Bungeecord that has Geyser packet translator so people on bedrock edition can play as well, but when a bedrock player connects it gets a unknown packet error. I tested the proxy on a Spigot server verifying it was forge. With no mods installed I still get the error. I got a wireshark log of it all and I found the packet where it aborts the connection due to the invalid packet but I have no clue how to stop it. When I still had the mods installed I disabled the forge handshake protocol but it did not fix the issue. If you know what part of forge is doing this or a way to fix it all together that would be awesome. I know modifying forge can end really baddy (definitely the handshake protocol) but I think that is my only fix here. Im open to any suggestions tho. I have run out of ideas to fix it so any help would be nice. Also it seems the packet id causing the connection error is 0xFE but im not sure cause the client also sends back a packet with that ID. I have a whole bunch of info collected so if you need any more information on the issue, I willing to give it, just not the ips on the wireshark log.
    • Okay, I got it working correctly now, but I'm not sure how to make it work with multiple blocks.   My Block Code:   package expanded.blocks; import javax.annotation.Nullable; import expanded.VanillaBuildingBlocks; import net.minecraft.block.BlockState; import net.minecraft.block.RotatedPillarBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ToolType; public class CustomLog extends RotatedPillarBlock {            public CustomLog(Properties properties) {         super(properties);     }      @Override     @Nullable     public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {         return toolType == ToolType.AXE ? VanillaBuildingBlocks.acacia_log.defaultBlockState() : null;     } }
    • ? Registering the block and overriding a function inside the class are two completely different things
    • Ya but I'm not sure how I would actually add/implement it into the class correctly, and then registering the block correctly in my register class.
    • This tutorial from 1.12.2 is as easy as anyone could possibly explain it, it hasn't changed much til now except some slight changes here and there for you to figure out, it's pretty straightforward (https://www.planetminecraft.com/blog/forge-tutorial-capability-system/). Obviously instead of mana you'd just replace it with whatever else you're doing. All a capability is in essence is the ability to serialize/deserialize standard data types to an entity. When the player dies the game creates a new instance of a PlayerEntity object so your data won't automatically "transfer" over to that new object unless as you say, you copy the data over in an event hook. After you have this set up, if you want to access the data you store in player capabilities you create a class with a static get function that retrieves it.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.