Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Last active November 7, 2022 05:02
Show Gist options
  • Save AndyNovo/1dcbf6de7d8e62774ca27500da7b611a to your computer and use it in GitHub Desktop.
Save AndyNovo/1dcbf6de7d8e62774ca27500da7b611a to your computer and use it in GitHub Desktop.
#put a black and white PNG in the same directory (replace helloworld.png) and copy the output into a command block
template = """/give @p minecraft:writable_book{pages:["/say Welcome to Minestax","/scoreboard objectives add udctf dummy","/scoreboard players set 1 udctf 1","/scoreboard players set 0 udctf 0","/execute at @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] run fill ~ ~ ~-200 ~ ~64 ~200 air replace","/kill @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}]","/summon minecraft:armor_stand ~10 ~ ~ {CustomNameVisible:1b,CustomName:\"\\\"idx\\\"\",Tags:[\"idx\"],HandItems:[{id:white_concrete_powder,Count:1b},{id:black_concrete_powder,Count:1b}]}","/execute at @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] run setblock ~ ~-1 ~ minecraft:white_concrete_powder replace", "/data modify block ~-4 ~ ~ Items set value [{Slot:0b,id:writable_book,Count:1b,tag:{pages:[\"data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[3].tag.pages\", \"say run\"]}},{Slot:1b,id:writable_book,Count:1b,tag:{pages:[REPLACEME]}},{Slot:2b,id:writable_book,Count:1b},{Slot:3b,id:writable_book,Count:1b,tag:{pages:[\"data modify block ~-4 ~ ~ Items[2].tag.pages set value ['c']\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[12].tag.pages\",\"data modify block ~-4 ~ ~ Items[2].tag.pages[0] set value 'i'\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[6].tag.pages\",\"data modify block ~-4 ~ ~ Items[2].tag.pages[0] set value 'd'\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[11].tag.pages\",\"data modify block ~-4 ~ ~ Items[2].tag.pages[0] set value 's'\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[13].tag.pages\",\"data modify block ~-4 ~ ~ Items[2].tag.pages[0] set value 'l'\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[8].tag.pages\",\"data modify block ~-4 ~ ~ Items[2].tag.pages[0] set value 'r'\",\"execute store success score @p udctf run data modify block ~-4 ~ ~ Items[2].tag.pages[0] set from block ~-4 ~ ~ Items[1].tag.pages[0]\",\"execute if score @p udctf = 0 udctf run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[9].tag.pages\",\"say fin\"]}},{Slot:4b,id:writable_book,Count:1b,tag:{pages:[\"item replace entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]}] armor.head from entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]},limit=1] weapon.offhand\",\"item replace entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]}] weapon.offhand from entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]},limit=1] weapon.mainhand\",\"item replace entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]}] weapon.mainhand from entity @e[type=armor_stand,nbt={\\\"Tags\\\":[\\\"idx\\\"]},limit=1] armor.head\",\"data remove block ~-4 ~ ~ Items[1].tag.pages[0]\",\"data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[10].tag.pages\",\"say f\"]}},{Slot:5b,id:writable_book,Count:1b,tag:{pages:['execute at @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] run clone ~ ~ ~ ~ ~64 ~ ~ ~ ~-1 replace','data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[8].tag.pages','say f']}},{Slot:6b,id:writable_book,Count:1b,tag:{pages:['execute at @e[type=armor_stand,nbt={\"Tags\":[\"idx\"]}] run clone ~ ~-1 ~ ~ ~-1 ~ ~ ~32 ~','data remove block ~-4 ~ ~ Items[1].tag.pages[0]','execute if data block ~-4 ~ ~ Items[1].tag.pages[0] run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[3].tag.pages','say f']}},{Slot:7b,id:writable_book,Count:1b,tag:{pages:['execute at @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] run clone ~ ~ ~ ~ ~32 ~ ~ ~32 ~1 replace','execute at @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] run fill ~ ~ ~ ~ ~32 ~ air replace','execute if data block ~-4 ~ ~ Items[1].tag.pages[0] run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[9].tag.pages','say f']}},{Slot:8b,id:writable_book,Count:1b,tag:{pages:['execute as @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] at @s run tp @s ~ ~ ~-1','data remove block ~-4 ~ ~ Items[1].tag.pages[0]','execute if data block ~-4 ~ ~ Items[1].tag.pages[0] run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[10].tag.pages','say f']}},{Slot:9b,id:writable_book,Count:1b,tag:{pages:['execute as @e[type=minecraft:armor_stand,nbt={\"Tags\":[\"idx\"]}] at @s run tp @s ~ ~ ~1','data remove block ~-4 ~ ~ Items[1].tag.pages[0]','execute if data block ~-4 ~ ~ Items[1].tag.pages[0] run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[10].tag.pages','say f']}},{Slot:10b,id:writable_book,Count:1b,tag:{pages:['execute as @e[type=armor_stand,nbt={\"Tags\":[\"idx\"]}] if entity @s[nbt={\"ArmorItems\":[{},{},{},{id:\"minecraft:black_concrete_powder\",Count:1b}]}] at @s run setblock ~ ~-1 ~ black_concrete_powder replace','execute as @e[type=armor_stand,nbt={\"Tags\":[\"idx\"]}] if entity @s[nbt={\"ArmorItems\":[{},{},{},{id:\"minecraft:white_concrete_powder\",Count:1b}]}] at @s run setblock ~ ~-1 ~ white_concrete_powder replace','execute if data block ~-4 ~ ~ Items[1].tag.pages[0] run data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[3].tag.pages','say f']}},{Slot:11b,id:writable_book,Count:1b,tag:{pages:['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[5].tag.pages','say f']}},{Slot:12b,id:writable_book,Count:1b,tag:{pages:['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[4].tag.pages','say f']}},{Slot:13b,id:writable_book,Count:1b,tag:{pages:['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','data modify block ~-4 ~ ~ Items[0].tag.pages set from block ~-4 ~ ~ Items[7].tag.pages','say f']}}]"]} 1"""
import copy
from PIL import Image
def makeline(n,cur=0,res=""):
if cur == n:
return res
if n == cur+1:
return res + "i"
if n == cur*2:
return res + "ds"
if cur == 0:
return makeline(n, 2, "ii")
if cur*2 < n:
return makeline(n, cur*2, res + "ds")
return makeline(n,cur+2,res+"ii")
def makecol(parts):
res="l"
if type(parts) == str:
return parts
if parts[0] < 0:
res += "c"
parts[0] = -1*parts[0]
return res + "scl".join(map(makeline, parts)) + "s"
def makespecial(pxls):
#this consumes [0, 0, 0, 1, 1, 0, 0, 0] and should return [3,2,3] and if the first element is 1 make it [-3, 2, 3]
cur = pxls[0]
count = 0
res=[]
for i in range(len(pxls)):
if pxls[i] == cur:
count += 1
else:
res.append(count)
count = 1
cur = pxls[i]
res.append(count)
if pxls[0] == 1:
res[0] = res[0]*-1
return res
def readimage(filename):
im=Image.open(filename)
colis=range(im.size[0]-1,-1,-1)
cols=[]
for i in colis:
pxls=[im.getpixel((i,j)) for j in range(im.size[1]-1, -1, -1)]
cols.append(makespecial(pxls))
#could make this more efficient by duping columns that are the same
return "l".join(map(makecol, cols))
def pagify(code):
return str(map(str,code)).replace(" ","").replace("[","").replace("]","")
code=readimage("helloworld.png")
if len(code) > 8000:
print("too long to copy into a command block")
runme = template.replace("REPLACEME", pagify(code))
print(runme)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment