def editCommandBlock(self, point): panel = Dialog() block = self.editor.level.blockAt(*point) blockData = self.editor.level.blockDataAt(*point) tileEntity = self.editor.level.tileEntityAt(*point) undoBackupEntityTag = copy.deepcopy(tileEntity) if not tileEntity: tileEntity = pymclevel.TAG_Compound() tileEntity["id"] = pymclevel.TAG_String("Control") tileEntity["x"] = pymclevel.TAG_Int(point[0]) tileEntity["y"] = pymclevel.TAG_Int(point[1]) tileEntity["z"] = pymclevel.TAG_Int(point[2]) tileEntity["Command"] = pymclevel.TAG_String() tileEntity["CustomName"] = pymclevel.TAG_String("@") tileEntity["TrackOutput"] = pymclevel.TAG_Byte(0) self.editor.level.addTileEntity(tileEntity) titleLabel = Label("Edit Command Block") commandField = TextField(width=200) nameField = TextField(width=100) trackOutput = CheckBox() commandField.value = tileEntity["Command"].value oldCommand = commandField.value trackOutput.value = tileEntity["TrackOutput"].value oldTrackOutput = trackOutput.value nameField.value = tileEntity["CustomName"].value oldNameField = nameField.value class CommandBlockEditOperation(Operation): def __init__(self, tool, level): self.tool = tool self.level = level self.undoBackupEntityTag = undoBackupEntityTag self.canUndo = False def perform(self, recordUndo=True): if self.level.saving: alert("Cannot perform action while saving is taking place") return self.level.addTileEntity(tileEntity) self.canUndo = True def undo(self): self.redoBackupEntityTag = copy.deepcopy(tileEntity) self.level.addTileEntity(self.undoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def redo(self): self.level.addTileEntity(self.redoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def updateCommandBlock(): if oldCommand != commandField.value or oldTrackOutput != trackOutput.value or oldNameField != nameField.value: tileEntity["Command"] = pymclevel.TAG_String(commandField.value) tileEntity["TrackOutput"] = pymclevel.TAG_Byte(trackOutput.value) tileEntity["CustomName"] = pymclevel.TAG_String(nameField.value) op = CommandBlockEditOperation(self.editor, self.editor.level) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() chunk = self.editor.level.getChunk(int(int(point[0]) / 16), int(int(point[2]) / 16)) chunk.dirty = True panel.dismiss() okBTN = Button("OK", action=updateCommandBlock) cancel = Button("Cancel", action=panel.dismiss) column = [titleLabel, Row((Label("Command"), commandField)), Row((Label("Custom Name"), nameField)), Row((Label("Track Output"), trackOutput)), okBTN, cancel] panel.add(Column(column)) panel.shrink_wrap() panel.present() return
def editSkull(self, point): block = self.editor.level.blockAt(*point) blockData = self.editor.level.blockDataAt(*point) tileEntity = self.editor.level.tileEntityAt(*point) undoBackupEntityTag = copy.deepcopy(tileEntity) skullTypes = { "Skeleton": 0, "Wither Skeleton": 1, "Zombie": 2, "Player": 3, "Creeper": 4, } inverseSkullType = { 0: "Skeleton", 1: "Wither Skeleton", 2: "Zombie", 3: "Player", 4: "Creeper", } if not tileEntity: tileEntity = pymclevel.TAG_Compound() tileEntity["id"] = pymclevel.TAG_String("Skull") tileEntity["x"] = pymclevel.TAG_Int(point[0]) tileEntity["y"] = pymclevel.TAG_Int(point[1]) tileEntity["z"] = pymclevel.TAG_Int(point[2]) tileEntity["SkullType"] = pymclevel.TAG_Byte(3) self.editor.level.addTileEntity(tileEntity) titleLabel = Label("Edit Skull Data") usernameField = TextField(width=150) panel = Dialog() skullMenu = mceutils.ChoiceButton(map(str, skullTypes)) if "Owner" in tileEntity: usernameField.value = str(tileEntity["Owner"]["Name"].value) elif "ExtraType" in tileEntity: usernameField.value = str(tileEntity["ExtraType"].value) else: usernameField.value = "" oldUserName = usernameField.value skullMenu.selectedChoice = inverseSkullType[tileEntity["SkullType"].value] oldSelectedSkull = skullMenu.selectedChoice class SkullEditOperation(Operation): def __init__(self, tool, level): self.tool = tool self.level = level self.undoBackupEntityTag = undoBackupEntityTag self.canUndo = False def perform(self, recordUndo=True): if self.level.saving: alert("Cannot perform action while saving is taking place") return self.level.addTileEntity(tileEntity) self.canUndo = True def undo(self): self.redoBackupEntityTag = copy.deepcopy(tileEntity) self.level.addTileEntity(self.undoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def redo(self): self.level.addTileEntity(self.redoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def updateSkull(): if usernameField.value != oldUserName or oldSelectedSkull != skullMenu.selectedChoice: tileEntity["ExtraType"] = pymclevel.TAG_String(usernameField.value) tileEntity["SkullType"] = pymclevel.TAG_Byte(skullTypes[skullMenu.selectedChoice]) if "Owner" in tileEntity: del tileEntity["Owner"] op = SkullEditOperation(self.editor, self.editor.level) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() chunk = self.editor.level.getChunk(int(int(point[0]) / 16), int(int(point[2]) / 16)) chunk.dirty = True panel.dismiss() okBTN = Button("OK", action=updateSkull) cancel = Button("Cancel", action=panel.dismiss) column = [titleLabel, usernameField, skullMenu, okBTN, cancel] panel.add(Column(column)) panel.shrink_wrap() panel.present()