Python MCEdit过滤器:如何在代码中创建胸部?

Python MCEdit过滤器:如何在代码中创建胸部?,python,filter,mcedit,Python,Filter,Mcedit,在MCEdit过滤器编程中,如何从头开始创建胸部?与可以使用setBlockAt的块不同的是,不是箱子实体和处理方式 有人能展示一些在过滤器中创建新空箱子的示例代码吗?最好是在用户制作的选择框内。在深入了解MCE的源代码以及SethBling的一些过滤器的源代码后,我设法编写了一些代码 以下函数假定一个名为levelOBJ的全局对象,该对象在perform()函数中设置为传入的level对象。这样你就不必一直通过关卡或禁区 # Just so I don't have to keep doing

在MCEdit过滤器编程中,如何从头开始创建胸部?与可以使用setBlockAt的块不同的是,不是箱子实体和处理方式


有人能展示一些在过滤器中创建新空箱子的示例代码吗?最好是在用户制作的选择框内。

在深入了解MCE的源代码以及SethBling的一些过滤器的源代码后,我设法编写了一些代码

以下函数假定一个名为levelOBJ的全局对象,该对象在perform()函数中设置为传入的level对象。这样你就不必一直通过关卡或禁区

# Just so I don't have to keep doing the math        
def getChunkAt(x, z):
    chunk = levelObj.getChunk(x / 16, z / 16)
    return chunk

# Creates a TAG_Compound Item (for use with the CreateChestAt function)
def CreateChestItem(itemid, damage=0, count=1, slot=0):
    item = TAG_Compound()
    item["id"] = TAG_Short(itemid)
    item["Damage"] = TAG_Short(damage)
    item["Count"] = TAG_Byte(count)
    item["Slot"] = TAG_Byte(slot)
    return item

# Creates a chest at the specified coords containing the items passed    
def CreateChestAt(x, y, z, Items=None, Direction=2, CustomName=""):
    levelObj.setBlockAt(x, y, z, 54) # Chest Block (single = 27 slots 0-26), 54 == chest, 146 == Trapped Chest
    levelObj.setBlockDataAt(x, y, z, Direction) # 2==N, 3==S, 4==W, 5==E anything else == N

    # Now Create Entity Block and add it to the chunk
    chunk = getChunkAt(x, z)
    chest = TileEntity.Create("Chest")
    TileEntity.setpos(chest, (x, y, z))
    if Items <> None:
        chest["Items"] = Items
    if CustomName <> "":
        chest["CustomName"] = CustomName
    chunk.TileEntities.append(chest)
要创建包含项目的箱子,请执行以下操作:

# Build item list (4 Jungle Planks and 11 chests
ChestItems = TAG_List()
ChestItems.append( CreateChestItem(5, 3, 4, 0) )
ChestItems.append( CreateChestItem(54, 0, 11, 1) )

# Make a chest with the items.
CreateChestAt(x, y, z, ChestItems)
还可以指定方向和自定义名称的可选参数

创建一个面向西方的空箱子,名为“我的箱子”


在深入研究了MCE的源代码和SethBling的一些过滤器的源代码之后,我设法编写了一些代码

以下函数假定一个名为levelOBJ的全局对象,该对象在perform()函数中设置为传入的level对象。这样你就不必一直通过关卡或禁区

# Just so I don't have to keep doing the math        
def getChunkAt(x, z):
    chunk = levelObj.getChunk(x / 16, z / 16)
    return chunk

# Creates a TAG_Compound Item (for use with the CreateChestAt function)
def CreateChestItem(itemid, damage=0, count=1, slot=0):
    item = TAG_Compound()
    item["id"] = TAG_Short(itemid)
    item["Damage"] = TAG_Short(damage)
    item["Count"] = TAG_Byte(count)
    item["Slot"] = TAG_Byte(slot)
    return item

# Creates a chest at the specified coords containing the items passed    
def CreateChestAt(x, y, z, Items=None, Direction=2, CustomName=""):
    levelObj.setBlockAt(x, y, z, 54) # Chest Block (single = 27 slots 0-26), 54 == chest, 146 == Trapped Chest
    levelObj.setBlockDataAt(x, y, z, Direction) # 2==N, 3==S, 4==W, 5==E anything else == N

    # Now Create Entity Block and add it to the chunk
    chunk = getChunkAt(x, z)
    chest = TileEntity.Create("Chest")
    TileEntity.setpos(chest, (x, y, z))
    if Items <> None:
        chest["Items"] = Items
    if CustomName <> "":
        chest["CustomName"] = CustomName
    chunk.TileEntities.append(chest)
要创建包含项目的箱子,请执行以下操作:

# Build item list (4 Jungle Planks and 11 chests
ChestItems = TAG_List()
ChestItems.append( CreateChestItem(5, 3, 4, 0) )
ChestItems.append( CreateChestItem(54, 0, 11, 1) )

# Make a chest with the items.
CreateChestAt(x, y, z, ChestItems)
还可以指定方向和自定义名称的可选参数

创建一个面向西方的空箱子,名为“我的箱子”