Advertisement
EdmundC

mine

Sep 13th, 2024 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. from PIL import Image
  2.  
  3. # Define the expanded block palette
  4. BLOCK_PALETTE = {
  5.     (255, 0, 0): "red_concrete",
  6.     (0, 255, 0): "lime_concrete",
  7.     (0, 0, 255): "blue_concrete",
  8.     (255, 255, 0): "yellow_concrete",
  9.     (255, 105, 180): "pink_concrete",
  10.     (255, 165, 0): "orange_concrete",
  11.     (128, 0, 128): "purple_concrete",
  12.     (0, 255, 255): "cyan_concrete",
  13.     (255, 0, 255): "magenta_concrete",
  14.     (128, 128, 128): "gray_concrete",
  15.     (192, 192, 192): "light_gray_concrete",
  16.     (105, 105, 105): "dark_gray_concrete",
  17.     (139, 69, 19): "brown_concrete",
  18.     (0, 0, 0): "black_concrete",
  19.     (255, 228, 225): "white_concrete",
  20.     (255, 228, 196): "light_gray_concrete",
  21.     (220, 20, 60): "red_terracotta",
  22.     (255, 160, 122): "sandstone",
  23.     (184, 134, 11): "gold_block",
  24.     (112, 128, 144): "stone_slab"
  25. }
  26.  
  27. def map_color_to_block(color):
  28.     return BLOCK_PALETTE.get(color, "stone")  # Default to stone if color not found
  29.  
  30. def generate_minecraft_commands(image_path, output_file):
  31.     with Image.open(image_path) as img:
  32.         img = img.resize((128, 128))  # Resize to 128x128 if needed
  33.         pixels = img.load()
  34.        
  35.         with open(output_file, 'w') as file:
  36.             for y in range(128):
  37.                 for x in range(128):
  38.                     color = pixels[x, y]
  39.                     block = map_color_to_block(color)
  40.                     command = f"/fill {x} 0 {y} {x} 255 {y} {block}\n"
  41.                     file.write(command)
  42.  
  43. if __name__ == "__main__":
  44.     generate_minecraft_commands("path/to/your/image.png", "commands.txt")
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement