1

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

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

4

1 回答 1

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 两次(两个坐标 1 分开 EW 或 NS)来创建一个双箱子。您可以连续创建 3 个,但 Minecraft 会使第 3 个箱子无效,使其无法在游戏中使用,因此请注意放置它们的方式。

创建一个空箱子:

CreateChestAt(x, y, z)

用物品创建一个箱子:

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

也可以指定 Direction 和 CustomName 的可选参数...

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

CreateChestAt(x, y, z, None, 4, "My Chest")
于 2015-11-04T19:43:29.240 回答