Skip to content
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

Example to save chunks from a server #267

Open
JosephLA1 opened this issue Dec 26, 2023 · 5 comments
Open

Example to save chunks from a server #267

JosephLA1 opened this issue Dec 26, 2023 · 5 comments
Labels
question Further information is requested save

Comments

@JosephLA1
Copy link

Hello,

Is there an example to simply join a server and view the chunks given by the server?

Thank you.

@Tnze
Copy link
Owner

Tnze commented Dec 26, 2023

Hi, you can take a look at the "daze" example, when server sends a chunk, the onChunkLoad function is called. Then you can gain the chunk data from worldManager.

@Tnze Tnze added question Further information is requested save labels Dec 26, 2023
@JosephLA1
Copy link
Author

Thanks. I was using that before but could not figure out how to save normal minecraft chunks or even view the blocks. I am new to this.

@Tnze
Copy link
Owner

Tnze commented Dec 26, 2023

You can use the save package to save the chunks. But the structure definitions inside might not update to date. Some data might be dropped.

@JosephLA1
Copy link
Author

I am using this code:

func onChunkLoad(pos level.ChunkPos) error {
	chunk := worldManager.Columns[pos]
	saveChunk := new(save.Chunk)
	err := level.ChunkToSave(chunk, saveChunk)
	if err != nil {
		log.Println(err)
		return err
	}

	file, _ := os.Create(fmt.Sprintf("chunks/r.%d.%d.mca", pos[0], pos[1]))
	defer file.Close()
	data, err := saveChunk.Data(1)
	if err != nil {
		log.Println(err)
		return err
	}

	file.Write(data)
	return nil
}

but I am getting encode "block_ticks" error: unsupport type nbt.RawMessage. What am I doing wrong? Thanks.

@Tnze
Copy link
Owner

Tnze commented Dec 26, 2023

The data scheme inside level and save are maintained by hand. Maybe there is something outdated. Feel free to clone go-mc and make some change. You can use tools like NBTExplorer to compare the actual data generated by the game and the Chunk structure written in save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested save
Projects
None yet
Development

No branches or pull requests

2 participants