2015-11-03 62 views
1

在MCEdit过滤器编程中,您如何从头创建一个箱子?是不是胸部实体和处理不同于您可以使用setBlockAt的块。MCEdit过滤器:如何在代码中创建胸部?

任何人都可以显示一些示例代码在过滤器中创建一个新的空洞箱?最好在用户制作的选择框内。

回答

0

在深入挖掘MCE的源代码并为SethBling的某些过滤器提供源代码后,我设法创建了一些代码。

以下函数假定一个名为levelOBJ的全局对象,该对象设置为perform()函数中的传入级别对象。这样你就不必保持传球水平或方格。

# 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) 

然后你可以称他们为下面的样品中描述的用我的功能在你的过滤器。在下面,x,y,z假定它们已经由希望胸部放置的适当坐标填充。

此外,双箱只是两个并排的箱子。调用CreateChestAt两次(两个坐标分开E-W或N-S)创建一个双重胸部。您可以连续创建3个,但Minecraft会使第3个胸部失效,使其无法在游戏中进入,因此请注意您如何放置它们。

创建一个空的胸部:

CreateChestAt(x, y, z) 

来创建项目胸部:指导和CustomName,也可以指定的

# 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) 

可选参数......

创建一个空洞胸朝西名为“我的胸”

CreateChestAt(x, y, z, None, 4, "My Chest") 
相关问题