使用senquence设置数组元素

时间:2015-10-28 12:14:21

标签: python mcedit

尝试对mcedit过滤器进行扩展,最初是由NanoRex编辑的CrushedPixel。他们制作的那个版本不支持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的数组元素。” 这里有一些屏幕显示了这个用途,以及问题是什么: Screen 1Screen 2。好的,现在我知道导致问题的原因了。我该如何解决?我真的想让它发挥作用:l

1 个答案:

答案 0 :(得分:0)

创建序列的

C = C, ' ', D,即。像(<Original C>, ' ', <Original D>)这样的东西,所以当你正在进行schematic.setBlockAt(x, y, z, C)时,C的参数是一个序列,当它期待一个项目时。