import nucleation as nuc
def basic_usage():
print("=== Basic Usage ===")
sch = nuc.Schematic("Python Demo")
sch.set_block(0, 0, 0, "minecraft:stone")
sch.set_block(1, 0, 0, "minecraft:oak_log")
sch.set_block(2, 0, 0, "minecraft:diamond_block")
sch.set_block_with_properties(
3, 0, 0,
"minecraft:oak_stairs",
{"facing": "north", "half": "bottom"}
)
sch.set_block_from_string(
4, 0, 0,
'minecraft:barrel[facing=up]{signal=13}'
)
print(f"Dimensions: {sch.dimensions}")
print(f"Block count: {sch.block_count}")
print(f"Volume: {sch.volume}")
print()
return sch
def block_state_demo():
print("=== BlockState Demo ===")
stone = nuc.BlockState("minecraft:stone")
print(f"Stone: {stone.name}")
print(f"Properties: {stone.properties}")
stairs = nuc.BlockState("minecraft:oak_stairs")
stairs_north = stairs.with_property("facing", "north")
stairs_complete = stairs_north.with_property("half", "top")
print(f"Stairs: {stairs_complete.name}")
print(f"Properties: {stairs_complete.properties}")
print()
def file_operations():
print("=== File Operations ===")
sch = nuc.Schematic("File Demo")
for x in range(5):
for z in range(5):
sch.set_block(x, 0, z, "minecraft:oak_planks")
for i in range(5):
sch.set_block(i, 1, 0, "minecraft:oak_log")
sch.set_block(i, 1, 4, "minecraft:oak_log")
sch.set_block(i, 2, 0, "minecraft:oak_log")
sch.set_block(i, 2, 4, "minecraft:oak_log")
sch.set_block(0, 1, i, "minecraft:oak_log")
sch.set_block(4, 1, i, "minecraft:oak_log")
sch.set_block(0, 2, i, "minecraft:oak_log")
sch.set_block(4, 2, i, "minecraft:oak_log")
sch.set_block_with_properties(2, 1, 0, "minecraft:oak_door", {"half": "lower"})
sch.set_block_with_properties(2, 2, 0, "minecraft:oak_door", {"half": "upper"})
for x in range(5):
for z in range(5):
sch.set_block(x, 3, z, "minecraft:oak_planks")
litematic_data = sch.to_litematic()
with open("python_house.litematic", "wb") as f:
f.write(litematic_data)
print("Saved as python_house.litematic")
schematic_data = sch.to_schematic()
with open("python_house.schematic", "wb") as f:
f.write(schematic_data)
print("Saved as python_house.schematic")
with open("python_house.litematic", "rb") as f:
data = f.read()
loaded_sch = nuc.Schematic("Loaded House")
loaded_sch.from_data(data)
print(f"Loaded schematic dimensions: {loaded_sch.dimensions}")
print(f"Loaded schematic block count: {loaded_sch.block_count}")
print()
return loaded_sch
def advanced_features(sch):
print("=== Advanced Features ===")
block_at_origin = sch.get_block(0, 0, 0)
if block_at_origin:
print(f"Block at origin: {block_at_origin.name}")
print(f"Properties: {block_at_origin.properties}")
all_blocks = sch.get_all_blocks()
print(f"Total blocks in schematic: {len(all_blocks)}")
entities = sch.get_all_block_entities()
if entities:
print(f"Found {len(entities)} block entities")
for entity in entities:
print(f" Entity at {entity['position']}: {entity['id']}")
print("\nASCII representation:")
print(sch.print_schematic())
print("\nDebug info:")
print(nuc.debug_schematic(sch))
print()
def chunk_operations():
print("=== Chunk Operations ===")
sch = nuc.Schematic("Chunk Demo")
for x in range(10):
for y in range(10):
for z in range(10):
if (x + y + z) % 3 == 0:
sch.set_block(x, y, z, "minecraft:stone")
elif (x + y + z) % 3 == 1:
sch.set_block(x, y, z, "minecraft:dirt")
else:
sch.set_block(x, y, z, "minecraft:grass_block")
chunks = sch.get_chunks(5, 5, 5, strategy="bottom_up")
print(f"Generated {len(chunks)} chunks using bottom_up strategy")
chunks_random = sch.get_chunks(5, 5, 5, strategy="random")
print(f"Generated {len(chunks_random)} chunks using random strategy")
chunks_camera = sch.get_chunks(
5, 5, 5,
strategy="distance_to_camera",
camera_x=5.0, camera_y=5.0, camera_z=5.0
)
print(f"Generated {len(chunks_camera)} chunks ordered by camera distance")
print()
def copy_region_demo():
print("=== Region Copying Demo ===")
source = nuc.Schematic("Source")
for x in range(3):
for y in range(3):
for z in range(3):
if x == 1 and y == 1 and z == 1:
source.set_block(x, y, z, "minecraft:diamond_block")
else:
source.set_block(x, y, z, "minecraft:stone")
dest = nuc.Schematic("Destination")
for i in range(3):
dest.copy_region(
source,
0, 0, 0, 2, 2, 2, i * 4, 0, 0, [] )
print(f"Copied pattern 3 times. Destination has {dest.block_count} blocks")
dest.copy_region(
source,
0, 0, 0,
2, 2, 2,
0, 4, 0,
["minecraft:diamond_block"] )
print(f"Copied without diamonds. Destination now has {dest.block_count} blocks")
print()
def main():
print("Nucleation Python Binding Example")
print("=" * 40)
basic_sch = basic_usage()
block_state_demo()
file_sch = file_operations()
advanced_features(file_sch)
chunk_operations()
copy_region_demo()
print("Example completed successfully!")
import os
try:
os.remove("python_house.litematic")
os.remove("python_house.schematic")
print("Cleaned up generated files")
except FileNotFoundError:
pass
if __name__ == "__main__":
main()