Jump to content

[1.18.2] Get world data file path


J3ramy

Recommended Posts

Ok I will figure it out when my attempt now is not working.

Right now I am trying to send a CompoundNBT from the server to client.

My class looks like that:

Spoiler
public class SCPacketSendServerData {
    private final Server server;

    public SCPacketSendServerData(PacketBuffer buf){
        System.out.println("1");
        System.out.println(buf.readCompoundTag().getCompound("db")); //Null for some reason
      	System.out.println(buf.readString()); // TEST is printed
    }

    public SCPacketSendServerData(Server server){
        this.server = server;
    }

    public void toBytes(PacketBuffer buf){
        System.out.println("2");
        buf.writeCompoundTag(server.getData().getCompound("db")); //Normal object with all its contents
      	buf.writeString("TEST")
    }
}

 

As you can see I am writing my compound tag in toBytes. The tag is not null - I can get all the contents of the Server class.

But in my constructor the compount tag is null.

If I use a string instead it works fine. Can you find my mistake?

Link to comment
Share on other sites

Ok, I changed my class to:

 

Spoiler
package de.j3ramy.economy.network;

import de.j3ramy.economy.screen.ServerScreen;
import de.j3ramy.economy.utils.Server;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

import java.util.function.Supplier;

public class SCPacketSendServerData {
    private final Server server;

    public SCPacketSendServerData(PacketBuffer buf){
        System.out.println("1");
        System.out.println(buf.readCompoundTag()); //null
    }

    public SCPacketSendServerData(Server server){
        this.server = server;
    }

    public void toBytes(PacketBuffer buf){
        System.out.println("2");
        System.out.println(server.getData().getCompound("db")); //all good
        buf.writeCompoundTag(server.getData().getCompound("db"));
        System.out.println(buf.readCompoundTag()); // ERROR: Caused by: java.io.IOException: Root tag must be a named compound tag
    }

    public void handle(Supplier<NetworkEvent.Context> ctx){
        ctx.get().enqueueWork(() ->{
            System.out.println("3");
        });
        ctx.get().setPacketHandled(true);
    }
}

 

As you can see this error gets created when I try to print it after I saved it. And I don't really know what this error means, because the tag has a name ("db")

Link to comment
Share on other sites

Ah okay this was actually just for debug purpose. But good to know.

So, in there data not set yet, because it gets set there. Am I right?

 

But I don't get it why it's still null in the constructor

EDIT: It works now for some reason.

 

Another question: Is there a limit in how many content an nbt tag can save? E. g. can I add thousands of strings? Or is the limit actually the space on the hard disk?

Edited by J3ramy
Link to comment
Share on other sites

There are some "hidden" limits which you might hit.

e.g. StringTag.write() uses DataOutput.writeUTF() which has this in its javadoc

Quote

First,
     * the total number of bytes needed to represent
     * all the characters of {@code s} is
     * calculated. If this number is larger than
     * {@code 65535}, then a {@code UTFDataFormatException}
     * is thrown.

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.

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.



×
×
  • Create New...

Important Information

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