Jump to content

Recommended Posts

Posted

I belive title is pretty self explanatory about the main idea.

In detail, I'm looking to extract a value like total broken stones and then render it on screen. I got the rendering text on screen part but I can't manage to find a way to access the stats.
It's on a singleplayer world.

I've also tried looking at the wiki of net.minecraft.stats but couldn't find anything because i don't really comprehend most of the text that I read.

One last thing that I tried is asking in the moddedmc discord but a partner told me to press escape then press statictics so you know.

Posted

ServerPlayer.getStats() then retrieve the stat you want.

 

To access it on the client you will need to write your own network packet.

https://forge.gemwire.uk/wiki/Main_Page

A possible implementation is to subscribe for LevelTickEvent and check you are server side.

Then check for changes for each player (MinecraftServer.getPlayerList) and send a client bound network packet to refresh the data when it changes.

 

Alternatively, if this is a GUI screen you can just do what StatsScreen does.

Implement the StatsUpdateListener and send the network packet (see the init method) when you want the data.

This will send all stats so maybe not what you want for this use case?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

im sorry but i dont know how to write a nerwork packet. Also tried doing my research but I didn't find anything I understood. 

Also, ServerPlayer.getStats() does not exist, I'm guessing that it is because i dont have that network packet thing. I just started in java so I dont know if its a general thing or not

Thank you

Posted

Documentation for network packets is in the link I posted above. See the "Handling Information" section.

ServerPlayer.getStats() does exist. It has the full signature (in net.minecraft.server.level.ServerPlayer)

   public ServerStatsCounter getStats() {

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
13 minutes ago, NaNasuuAkiaa said:

im sorry but i dont know how to write a nerwork packet. Also tried doing my research but I didn't find anything I understood.

https://forge.gemwire.uk/wiki/SimpleChannel

14 minutes ago, NaNasuuAkiaa said:

Also, ServerPlayer.getStats() does not exist, I'm guessing that it is because i dont have that network packet thing.

the method ServerPlayer#getStats exists, show how you tried to use the method

16 minutes ago, NaNasuuAkiaa said:

I just started in java so I dont know if its a general thing or not

Note that basic java is required for modding Minecraft

Posted

So, instead of trying to get the statictics from the player itself, i need to ask the server for them? 

Update before posting: So first i need a packet handler, then I need to send the packet with the packet handler to obtain the stats from the server? 
Second update: This is the entire packet handler I did:

import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;

public class utilitiesforthestreamPacketHandler {
    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
            new ResourceLocation("utilitiesforthestream", "main"),
            () -> PROTOCOL_VERSION,
            PROTOCOL_VERSION::equals,
            PROTOCOL_VERSION::equals);
}

 

Posted

after a bit search through the vanilla code i found this in the StatsScreen

this.minecraft.getConnection().send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.REQUEST_STATS));

this means you don't need a custom Network packet you need to send the ServerboundClientCommandPacket with action REQUEST_STATS to the server
you then be able to get the Stats from LocalPlayer#getStats which you can get from Minecraft#player

Posted

The REQUEST_STATS downloads all the stats. Repeatedly doing this in "real time" is going to be very inefficient.

It is designed for the stats screen that only downloads the data once when you display that screen.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
14 minutes ago, diesieben07 said:

You should send the packet from the server side and only include the stats that you need. You can even use the vanilla packet for this, there is no need to make your own.

Then how can I do this? I'm still learning java and this gets a bit out of my hands

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.