Planet Centauri

Planet Centauri

Not enough ratings
Generating blueprints using python
By onilink_
This guide describe how to generate blueprints that can be used in creative mode.
   
Award
Favorite
Favorited
Unfavorite
Blueprints
Blueprints are a convenient way to import and export buildings or any world structures with the Copy (C) and Paste (V) tools in creative mode.

They can also be used for world generation as structures (ex: sky islands) or for dungeons generation...
File format
Official documentation on the file format can be found here[ic.onidev.fr].
Blueprint generation using python
This python script will output a base64 text than can be copied and pasted in the creative mode of Planet Centauri using the Paste tool (V key).

import struct import io import zlib import base64 def rle_compress_u16(s, t, marker): start = s.tell() counter = 1 previous = t[0] for idx in range(1, len(t)): e = t[idx] if(e == marker): return 0 if(e != previous or counter == 255): if(counter <= 3): for i in range(0, counter): s.write(struct.pack('H', previous)) else: s.write(struct.pack('H', marker)) s.write(struct.pack('B', counter)) s.write(struct.pack('H', previous)) counter = 1 else: counter += 1 previous = e if(counter <= 3): for i in range(0, counter): s.write(struct.pack('H', previous)) else: s.write(struct.pack('H', marker)) s.write(struct.pack('B', counter)) s.write(struct.pack('H', previous)) return len(t) def generate_tiles(pattern): pc_block_board_1 = 70 # Create the empty 128x128 tile matrix tiles_front = [0 for x in range(128*128)] # And fill it with the pattern wid = 1 for y in range(0, len(pattern)): line = pattern[y] for x in range(0, len(line)): if line[x] == 'X': tiles_front[x + y*128] = pc_block_board_1 wid = max(wid, len(line)) return tiles_front, wid, len(pattern) s = io.BytesIO() version = 47 tiles_front, wid, hei = generate_tiles( [ " X ", "XXX", " X ", ]) s.write(struct.pack('I', version)) s.write(struct.pack('I', wid)) s.write(struct.pack('I', hei)) # Write chunk # Tiles header = 1 s.write(struct.pack('B', header)) # RLE compression data_begin = s.tell() s.write(struct.pack('I', 0)) # pre-write data size count = rle_compress_u16(s, tiles_front, 0xFFFF) data_end = s.tell() s.seek(data_begin) s.write(struct.pack('I', count)) s.seek(data_end) s.write(struct.pack('H', 0)) # Grounds s.write(struct.pack('H', 0)) # Ores s.write(struct.pack('H', 0)) # Decorations s.write(struct.pack('H', 0)) # Events s.write(struct.pack('H', 0)) # Triggers # No doors s.write(struct.pack('H', 0)) binary_data = s.getvalue() compressed_data = zlib.compress(binary_data) base64_data = base64.b64encode(compressed_data) base64_string = "CENT" + base64_data.decode('utf-8') print(base64_string)

It will generate a + made of wooden blocks.
The pattern can be easily edited in the python script.
Many possibilities
Generating blueprints from any programming language should be straightforward if you follow the documentation, and unlocks many possibilities for modding and/or building. For example:
  • Import of pixel art images
  • Generation of procedural buildings
  • Parametric Magitech RAM, Registers or any repetitive structures
  • Custom procedural generation