Python 使用序列设置数组元素

Python 使用序列设置数组元素,python,mcedit,Python,Mcedit,我试图对mcedit过滤器进行扩展,最初由CrushedPixel编写,由NanoRex编辑。他们制作的版本不支持1.9快照/块,所以我决定制作一个更好的、无延迟的版本 代码如下: # MCEdit Filter by CrushedPixel # http://youtube.com/CrushedPixel # Heavily Modified by NanoRex # Major bug (and some minor ones) fixed by NanoRex # http://you

我试图对mcedit过滤器进行扩展,最初由CrushedPixel编写,由NanoRex编辑。他们制作的版本不支持1.9快照/块,所以我决定制作一个更好的、无延迟的版本

代码如下:

# MCEdit Filter by CrushedPixel
# http://youtube.com/CrushedPixel
# Heavily Modified by NanoRex
# Major bug (and some minor ones) fixed by NanoRex
# http://youtube.com/thecaptainrex7567

from pymclevel import TAG_List
from pymclevel import TAG_Byte
from pymclevel import TAG_Int
from pymclevel import TAG_Compound
from pymclevel import TAG_Short
from pymclevel import TAG_Double
from pymclevel import TAG_String
import math
from pymclevel import MCSchematic
import mcplatform

displayName = "JetDirectionsMod"

CmdBlockTypes = {
"Normal" : 137,
"Chain" : 211,
"Repeating" : 210,
}

CmdDataTypes = {
"Facing DOWN": 0,
"Facing UP": 1,
"Facing NORTH": 2,
"Facing SOUTH": 3,
"Facing WEST": 4,
"Facing EAST": 5,
}

DataKeys = ()
for key in CmdBlockTypes.keys():
    DataKeys = DataKeys + (key,)

DataTypeKeys = ()
for key in CmdDataTypes.keys():
    DataTypeKeys = DataTypeKeys + (key,)

inputs = (
    ("Placeholders: $rot | $mot | $dir","label"),
    ("Accuracy (Degrees)", (5,1,20)),
    ("Motion Factor", (0.1,9.0)),
    ("Set Position to In Front of Player:","label"),
    ("Placeholder: $pos","label"),
    ("Set Position", False),
    ("Distance From Player", (1,5)),
    ("Relative Y Position", (0,-1000,1000)),
    ("Command Block Type:", DataKeys),
    ("Commandblock Rotation:", DataTypeKeys),
)


def perform(level, box, options):

fac = options["Accuracy (Degrees)"]
speed = options["Motion Factor"]
adjustPos = options["Set Position"]
adjustAmount = options["Distance From Player"]
ypos = options["Relative Y Position"]
C = CmdBlockTypes[options["Command Block Type:"]]
D = CmdDataTypes[options["Commandblock Rotation:"]]
C = C, '  ', D

found = False

for x in xrange(box.minx,box.maxx):
    if not found:
        for y in xrange(box.miny,box.maxy):
            if not found:
                for z in xrange(box.minz,box.maxz):
                    te = level.tileEntityAt(x,y,z)

                    if te != None:
                        try:
                            text = te["Command"].value
                            found = True
                            break
                        except:
                            pass

commands = []

if not found:
    raise Exception("Please select a command block in order to run this filter.")

for y in range(-90/fac,90/fac):
    rxm = y*fac
    rx = ((y+1)*fac)-1
    if rx == 89 :
        rx += 1
    for x in range(-180/fac,180/fac):
        rym = x*fac
        ry = ((x+1)*fac)-1
        if ry == 179 :
            ry +=1

        xdeg = math.radians(((x+1)*fac)-(fac/2))
        ydeg = math.radians(((y+1)*fac)-(fac/2))

        xmov = -speed*(math.sin(xdeg)*math.cos(ydeg))
        ymov = -speed*math.sin(ydeg) + 0.1
        zmov = speed*(math.cos(xdeg)*math.cos(ydeg))

        cmd = text.replace("$rot", "rxm="+str(rxm)+",rx="+str(rx)+",rym="+str(rym)+",ry="+str(ry))
        cmd = cmd.replace("$mot", "Motion:["+str(xmov)+","+str(ymov)+","+str(zmov)+"]")
        cmd = cmd.replace("$dir", "direction:["+str(xmov)+","+str(ymov)+","+str(zmov)+"]")

        if adjustPos == True :
            if -67.5 < ((x+1)*fac)-(fac/2) < 67.5 :
                zadj = adjustAmount
            elif -180 <= ((x+1)*fac)-(fac/2) < -112.5 or 180 >= ((x+1)*fac)-(fac/2) > 112.5 :
                zadj = -adjustAmount
            else:
                zadj = 0

            if 22.5 < ((x+1)*fac)-(fac/2) < 157.5 :
                xadj = -adjustAmount
            elif -22.5 > ((x+1)*fac)-(fac/2) > -157.5 :
                xadj = adjustAmount
            else:
                xadj = 0

            cmd = cmd.replace("$pos", "~"+str(xadj)+" ~"+str(ypos)+" "+"~"+str(zadj))

        commands.append(cmd)


number = len(commands)
size = math.sqrt(number/2)
rs = math.ceil(size)
if rs ** 2 > 4096 :
    raise Exception("Too many command blocks for the /fill command. Increase \"Accuracy (Degrees)\" to solve this.")

schematic = MCSchematic((rs+2,4,rs+2), mats = level.materials)

i = 0
xc = 1
zc = -1

schematic.setBlockAt(1,3,0,210)
schematic.TileEntities.append(cmdBlockTe(1,3,0,"/fill ~ ~-2 ~1 ~"+str(int(rs))+" ~-2 ~"+str(int(rs+1))+" minecraft:redstone_block"))

schematic.setBlockAt(0,3,1,210)
schematic.TileEntities.append(cmdBlockTe(0,3,1,"/fill ~1 ~-2 ~ ~"+str(int(rs+1))+" ~-2 ~"+str(int(rs))+" minecraft:stone"))

for x in range(1, int(rs+2)):
    xc += 1
    for z in range(1, int(rs+2)):
        zc += 1
        y = 2
        if i < number:
            cmd = commands[i]
            schematic.setBlockAt(x, y, z, C, D)

            control = cmdBlockTe(x, y, z, cmd)

            schematic.TileEntities.append(control)

        i += 1
        y = 0
        if i < number:
            cmd = commands[i]
            schematic.setBlockAt(x, y, z, C)

            control = cmdBlockTe(x, y, z, cmd)

            schematic.TileEntities.append(control)

        i += 1

    zc = -1


schematic_file = mcplatform.askSaveFile(mcplatform.lastSchematicsDir or mcplatform.schematicsDir, "Save Schematic As...", "", "Schematic\0*.schematic\0\0", ".schematic")
if schematic_file == None:
    print "ERROR: No schematic filename provided!"
    return
schematic.saveToFile(schematic_file)


def cmdBlockTe(x,y,z,cmd):
    control = TAG_Compound()
    control["Command"] = TAG_String(cmd)
    control["id"] = TAG_String(u'Control')
    control["CustomName"] = TAG_String(u'@')
    control["z"] = TAG_Int(z)
    control["y"] = TAG_Int(y)
    control["x"] = TAG_Int(x)

    return control
这给了我一个错误:用senquence设置数组元素。 下面是一些屏幕,显示了它的用途和问题:
, . 好了,现在我知道问题的原因了。我怎样才能解决它?我真的很想让它工作:l

C=C',D创建一个序列,比如,',所以当你在做schematic.setBlockAtx,y,z,C时,你的C参数是一个序列,当它需要一个单独的项时。

我怎么解决这个问题?昨天我第一次尝试python,对不起。@kratenko: