Code Monkey home page Code Monkey logo

Comments (4)

macfreek avatar macfreek commented on July 28, 2024

I don't have time to look into it, but I suspect it has to do with this line:

Villages = TAG_List(type=TAG_Compound)

I would replace it with:

Villages = TAG_List(name = "Villages", type=TAG_Compound)

Let me know if this works,

from nbt.

macfreek avatar macfreek commented on July 28, 2024

When an unnamed TAG_Compound object is serialized with _render_buffer(), it raises the following exception:

Traceback (most recent call last):
  method <module> in test.py at line 69
    villages.write_file("villages.dat")
  method write_file in test.py at line 575
    self._render_buffer(self.file)
  method _render_buffer in test.py at line 401
    tag._render_buffer(buffer)
  method _render_buffer in test.py at line 400
    TAG_String(tag.name)._render_buffer(buffer)
  method _render_buffer in test.py at line 268
    save_val = self.value.encode("utf-8")
AttributeError: 'NoneType' object has no attribute 'encode'

A quick fix is to assume name is "" when it is not set (or simply set it to "" instead of None as the default).

Braindump: I don't think this leads to unexpected problems, but it does point to what I nowadays consider a design flaw in the NBT library: there is no clear distinction between a TAG and a Named TAG object. This distinction is only made by the calling function, not by the object itself. E.g., there is no clear distinction between a Named TAG with the name set to "", or a (unnamed) TAG with the name attribute set to None.

from nbt.

Omeganx avatar Omeganx commented on July 28, 2024

Well, you are right. I totally forgot to name that list, because I thought it has no name in the "villages.dat" minecraft file.

Also it turns out that I don't need, this lines:

Players = TAG_List(type=TAG_End, name="Players")
compound.tags.append(Players)

Since the file that the program wrote works fine, minecraft is actually doing this line for me.
At first i was scared that the order of the tags matters but it doesn't.

Thanks.

from nbt.

macfreek avatar macfreek commented on July 28, 2024

@Omeganx good to hear, you got it fixed. Thanks for reporting it.

I'll keep this open for a while; even when you don't name a TAG_Compound, it should not raise this error. If it is allowed in a NBT file, it should just serialize it. If it is not allowed in a NBT, it should raise a decent exception.

from nbt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.