Skip to content

Instantly share code, notes, and snippets.

@Rubisk
Created January 6, 2015 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rubisk/88b1d466dba215ef2e78 to your computer and use it in GitHub Desktop.
Save Rubisk/88b1d466dba215ef2e78 to your computer and use it in GitHub Desktop.
Chest To Command
from pymclevel import TAG_Compound
from pymclevel import TAG_Int
from pymclevel import TAG_Short
from pymclevel import TAG_Byte
from pymclevel import TAG_String
from pymclevel import TAG_Float
from pymclevel import TAG_Double
from pymclevel import TAG_List
from pymclevel import TileEntity
from pymclevel import nbt
displayName = "Chest To Summon Command"
inputs = (
)
def perform(level, box, options):
for (chunk, slices, point) in level.getChunkSlices(box):
for e in chunk.TileEntities:
x = e["x"].value
y = e["y"].value
z = e["z"].value
if (x,y,z) in box:
if e["id"].value == "Chest":
for slot in e["Items"]:
if slot["Slot"].value == 0:
createCommandBlock(level, slot, x, (y-1), z)
def createCommandBlock(level, slot, x, y, z):
level.setBlockAt(x, y, z, 137)
chunk = level.getChunk(x/16, z/16)
chunk.TileEntities.append(createTileEntity(slot, x, y, z))
chunk.dirty = True
def createTileEntity(slot, x, y, z):
tileEntity = TAG_Compound()
tileEntity["x"] = TAG_Int(x)
tileEntity["y"] = TAG_Int(y)
tileEntity["z"] = TAG_Int(z)
tileEntity["id"] = TAG_String("Control")
id = slot["id"]
DataString = "/summon Item x y z {"
for i in slot:
DataString += (evaluateString(i, slot)) + ","
DataString += ("}")
print DataString
tileEntity["Command"] = TAG_String(DataString)
return tileEntity
def evaluateString(i, slot):
if slot[i].__class__.__name__ == "TAG_List":
string = "["
count = 0
for tag in slot[i].value:
print slot[i].value
print tag.name
string += evaluateString(count, slot[i].value) + ","
count += 1
string += "]"
elif slot[i].__class__.__name__ == "TAG_Compound":
string = "{"
for tag in slot[i].value:
string += tag.name + ":" + evaluateString(tag.name, slot[i]) + ","
string += "}"
else:
string = i + ":" + str(slot[i].value)
return string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment