GregoryAM-SP / The-Minecraft-Overviewer

The Minecraft Overviewer | Successor
https://overviewer.gregoryam.com
GNU General Public License v3.0
88 stars 12 forks source link

Display text for the new sign format #5

Closed BenKennish closed 1 year ago

BenKennish commented 1 year ago

I was looking at the changes to the code for handling signs in this commit https://github.com/GregoryAM-SP/The-Minecraft-Overviewer/commit/2d24bc38d7d38e8a34bab94792080b237f3a1535

as the genPOI stage was failing when I was trying to render my 1.20.1 world. I'm not a Python dev and I couldn't understand how the information stored in the messages variable is "delivered" to the config.py file. So I changed my signFilter function to simply test for ..

if "Text1" in poi:
   ...
else:
   return "(Unable to read signs with new format)"

How would I go about modifying my signFilter so that it displays the sign text on the map?

Gregory-AM commented 1 year ago

Within the description for v1.19.3.2:

Depending on if you're rendering a 1.20 World, or Pre-1.20 World: Add one of the following to your configuration file.

# Specifically for v1.20 Worlds
def signFilter(poi):
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        text_lines = []
        front_text = poi.get('front_text', {})
        back_text = poi.get('back_text', {})
        text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
        text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
        return "\n".join(text_lines)
# Specifically for Worlds before v1.20
def signFilter(poi):
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        return "\n".join([poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']])

This one is for backwards compatibility. If you plan on using the same Configuration file for 1.20 Worlds and Pre-1.20 worlds. You can use this, if you're unsure if one or the other will work.

def signFilter(poi):
    # Default Sign Filter Function (pre v1.20)
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        if 'Text1' in poi:
            text_lines = [line for line in [poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']] if line.strip()]
        else:
           # v1.20+ Sign Filter
            text_lines = []
            front_text = poi.get('front_text', {})
            back_text = poi.get('back_text', {})
            text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
            text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
        return '\n'.join(text_lines)

Your configuration file should look like this:

def signFilter(poi):
     # Default Sign Filter Function (pre v1.20)
     if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
         if 'Text1' in poi:
             text_lines = [line for line in [poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']] if line.strip()]
         else:
            # v1.20+ Sign Filter
             text_lines = []
             front_text = poi.get('front_text', {})
             back_text = poi.get('back_text', {})
             text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
             text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
         return '/n'.join(text_lines)

renders["myrender"] = {
    "world": "My World",
    "title": "Overworld",
    "northdirection": "upper-left",
        "markers": [
              dict(name="Signs", filterFunction=signFilter),
        ]
}
worlds['My World'] = C:/Path/to/world
outputdir = 'C:/Path/to/output'

overviewer.exe --config="C:/Path/to/config( .txt or .py )" --genpoi

Gregory-AM commented 1 year ago

If you're looking to display specific text within your world from a sign: Use ManualPOIs, described in the original Overviewer Docs.

BenKennish commented 1 year ago

Thanks @Gregory-AM. That worked a treat. I actually remember reading that text within the commit but forgot where I'd read it.

Gregory-AM commented 1 year ago

You're welcome, @BenKennish The Wiki here on GitHub will be Reflecting all changes made to the code, along with examples and images that will better help with understanding how specific Configurations work.

While the OG Overviewer Docs are amazing. They seem to be limited on examples and images that would be very helpful and beneficial to rendering a world.

I am waiting until I complete The Overviewer to create the Wiki as I'm not sure what will be changing.

prototype464 commented 3 months ago

Within the description for v1.19.3.2:

Depending on if you're rendering a 1.20 World, or Pre-1.20 World: Add one of the following to your configuration file.

# Specifically for v1.20 Worlds
def signFilter(poi):
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        text_lines = []
        front_text = poi.get('front_text', {})
        back_text = poi.get('back_text', {})
        text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
        text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
        return "\n".join(text_lines)
# Specifically for Worlds before v1.20
def signFilter(poi):
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        return "\n".join([poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']])

This one is for backwards compatibility. If you plan on using the same Configuration file for 1.20 Worlds and Pre-1.20 worlds. You can use this, if you're unsure if one or the other will work.

def signFilter(poi):
    # Default Sign Filter Function (pre v1.20)
    if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
        if 'Text1' in poi:
            text_lines = [line for line in [poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']] if line.strip()]
        else:
           # v1.20+ Sign Filter
            text_lines = []
            front_text = poi.get('front_text', {})
            back_text = poi.get('back_text', {})
            text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
            text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
        return '\n'.join(text_lines)

Your configuration file should look like this:

def signFilter(poi):
     # Default Sign Filter Function (pre v1.20)
     if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign':
         if 'Text1' in poi:
             text_lines = [line for line in [poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']] if line.strip()]
         else:
            # v1.20+ Sign Filter
             text_lines = []
             front_text = poi.get('front_text', {})
             back_text = poi.get('back_text', {})
             text_lines.extend(line for line in front_text.get('messages', []) if line.strip())
             text_lines.extend(line for line in back_text.get('messages', []) if line.strip())
         return '/n'.join(text_lines)

renders["myrender"] = {
  "world": "My World",
  "title": "Overworld",
  "northdirection": "upper-left",
        "markers": [
              dict(name="Signs", filterFunction=signFilter),
        ]
}
worlds['My World'] = C:/Path/to/world
outputdir = 'C:/Path/to/output'

overviewer.exe --config="C:/Path/to/config( .txt or .py )" --genpoi

Thank you for this!