Forget `nbtlib` return to `PyNBT`
This commit is contained in:
parent
35ab69994a
commit
22126c576e
|
@ -594,10 +594,9 @@ class Planet(QMainWindow):
|
|||
|
||||
self.delete_appimage_button = QPushButton("Delete")
|
||||
self.delete_appimage_button.clicked.connect(self.delete_appimage)
|
||||
|
||||
self.import_gmcpil_button = QPushButton("Import settings")
|
||||
self.import_gmcpil_button.clicked.connect(self.import_gmpil)
|
||||
|
||||
self.import_gmcpil_button = QPushButton("Import settings")
|
||||
self.import_gmcpil_button.clicked.connect(self.import_gmcpil)
|
||||
|
||||
layout.addWidget(skin_label, 0, 0)
|
||||
layout.addWidget(self.skin_button, 0, 1)
|
||||
|
@ -633,8 +632,7 @@ class Planet(QMainWindow):
|
|||
) # Set the icon
|
||||
|
||||
return tabs
|
||||
|
||||
|
||||
|
||||
def import_gmcpil(self):
|
||||
with open(f"/home/{USER}/.gmcpil.json") as f:
|
||||
gmcpil_features = json.loads(f.read())["features"]
|
||||
|
@ -714,14 +712,16 @@ class Planet(QMainWindow):
|
|||
def delete_config(self):
|
||||
dialog = QMessageBox()
|
||||
dialog.setWindowTitle("Are you sure you want to reset?")
|
||||
dialog.setText("Are you sure you want to delete the config? This action is unrecoverable.")
|
||||
dialog.setText(
|
||||
"Are you sure you want to delete the config? This action is unrecoverable."
|
||||
)
|
||||
dialog.setStandardButtons(QMessageBox.Ok | QMessageBox.Abort)
|
||||
dialog.setIcon(QMessageBox.Warning)
|
||||
|
||||
|
||||
button = dialog.exec()
|
||||
|
||||
|
||||
if button == QMessageBox.Ok:
|
||||
|
||||
|
||||
os.remove(f"/home/{USER}/.planet-launcher/config.json")
|
||||
self.hide()
|
||||
sys.exit()
|
||||
|
@ -729,14 +729,16 @@ class Planet(QMainWindow):
|
|||
def delete_appimage(self):
|
||||
dialog = QMessageBox()
|
||||
dialog.setWindowTitle("Are you sure you want to reset?")
|
||||
dialog.setText("Are you sure you want to delete the AppImage? This action is unrecoverable.")
|
||||
dialog.setText(
|
||||
"Are you sure you want to delete the AppImage? This action is unrecoverable."
|
||||
)
|
||||
dialog.setStandardButtons(QMessageBox.Ok | QMessageBox.Abort)
|
||||
dialog.setIcon(QMessageBox.Warning)
|
||||
|
||||
|
||||
button = dialog.exec()
|
||||
|
||||
|
||||
if button == QMessageBox.Ok:
|
||||
|
||||
|
||||
os.remove(f"/home/{USER}/.planet-launcher/minecraft.AppImage")
|
||||
self.hide()
|
||||
sys.exit()
|
||||
|
|
|
@ -26,31 +26,34 @@ if os.path.exists("/usr/lib/planet-launcher/"):
|
|||
if not os.path.exists(f"/home/{USER}/.minecraft-pi/games/com.mojang/minecraftWorlds/"):
|
||||
os.makedirs(f"/home/{USER}/.minecraft-pi/games/com.mojang/minecraftWorlds/")
|
||||
|
||||
GAME_TYPES = {"Survival": nbt.nbtlib.Int(0), "Creative": nbt.nbtlib.Int(1)}
|
||||
GAME_TYPES = {"Survival": nbt.pynbt.TAG_Int(0), "Creative": nbt.pynbt.TAG_Int(1)}
|
||||
|
||||
GAME_INTREGERS = {"0": "Survival", "1": "Creative"}
|
||||
|
||||
BOOLEAN_INTREGERS = {0: False, 1: True}
|
||||
BOOLEAN_INTREGERS_REVERSED = {False: 0, True: 1}
|
||||
|
||||
|
||||
class AboutWindow(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
|
||||
label = QLabel("About MCPIedit")
|
||||
label.setAlignment(Qt.AlignHCenter)
|
||||
font = label.font() # Font used
|
||||
font.setPointSize(15) # Set the font size
|
||||
label.setFont(font) # Aplly the font onto the label
|
||||
|
||||
desc_label = QLabel("The default built-in NBT editor for Planet.\n\nMCPIedit makes use of Pi-NBT\n from the original MCPIedit project\nby TheBrokenRail, which is\nlicensed under the MIT license.")
|
||||
|
||||
desc_label = QLabel(
|
||||
"The default built-in NBT editor for Planet.\n\nMCPIedit makes use of Pi-NBT\n from the original MCPIedit project\nby TheBrokenRail, which is\nlicensed under the MIT license."
|
||||
)
|
||||
desc_label.setAlignment(Qt.AlignHCenter)
|
||||
|
||||
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(desc_label)
|
||||
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
|
||||
|
@ -59,12 +62,14 @@ class FileSelectorTab(QWidget):
|
|||
super().__init__()
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
info_label = QLabel("NBT editors allow you to edit your world\nfiles to change game modes, time,\nand even the world name. Select an NBT\nfile to edit using the button below.")
|
||||
|
||||
info_label = QLabel(
|
||||
"NBT editors allow you to edit your world\nfiles to change game modes, time,\nand even the world name. Select an NBT\nfile to edit using the button below."
|
||||
)
|
||||
info_label.setAlignment(Qt.AlignHCenter)
|
||||
|
||||
self.load_button = QPushButton("Select NBT File")
|
||||
|
||||
|
||||
self.about_button = QPushButton("About")
|
||||
self.about_button.clicked.connect(self.about_window)
|
||||
|
||||
|
@ -73,7 +78,7 @@ class FileSelectorTab(QWidget):
|
|||
layout.addWidget(self.about_button)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
|
||||
def about_window(self):
|
||||
self.window = AboutWindow()
|
||||
self.window.show()
|
||||
|
@ -96,21 +101,20 @@ class EditorTab(QWidget):
|
|||
self.tabs.addTab(self.main_tab(), "General")
|
||||
self.tabs.addTab(self.world_tab(), "World")
|
||||
|
||||
self.name_edit.setText(str(self.nbt["LevelName"]))
|
||||
self.timestamp_box.setValue(int(self.nbt["LastPlayed"]))
|
||||
self.game_box.setCurrentText(GAME_INTREGERS[str(int(self.nbt["GameType"]))])
|
||||
self.seed_edit.setText(str(int(self.nbt["RandomSeed"])))
|
||||
self.time_edit.setText(str(int(self.nbt["Time"])))
|
||||
#self.mobs_toggle.setChecked(BOOLEAN_INTREGERS[int(self.nbt["SpawnMobs"])]) # REMOVED BECAUSE DOES NOT WORK
|
||||
|
||||
|
||||
self.spawn_x_box.setValue(int(self.nbt["SpawnX"]))
|
||||
self.spawn_y_box.setValue(int(self.nbt["SpawnY"]))
|
||||
self.spawn_z_box.setValue(int(self.nbt["SpawnZ"]))
|
||||
|
||||
self.player_spawn_x_box.setValue(int(self.nbt["Player"]["SpawnX"]))
|
||||
self.player_spawn_y_box.setValue(int(self.nbt["Player"]["SpawnY"]))
|
||||
self.player_spawn_z_box.setValue(int(self.nbt["Player"]["SpawnZ"]))
|
||||
self.name_edit.setText(str(self.nbt["LevelName"].value))
|
||||
self.timestamp_box.setValue(int(self.nbt["LastPlayed"].value))
|
||||
self.game_box.setCurrentText(GAME_INTREGERS[str(int(self.nbt["GameType"].value))])
|
||||
self.seed_edit.setText(str(int(self.nbt["RandomSeed"].value)))
|
||||
self.time_edit.setText(str(int(self.nbt["Time"].value)))
|
||||
# self.mobs_toggle.setChecked(BOOLEAN_INTREGERS[int(self.nbt["SpawnMobs"])]) # REMOVED BECAUSE DOES NOT WORK
|
||||
|
||||
self.spawn_x_box.setValue(int(self.nbt["SpawnX"].value))
|
||||
self.spawn_y_box.setValue(int(self.nbt["SpawnY"].value))
|
||||
self.spawn_z_box.setValue(int(self.nbt["SpawnZ"].value))
|
||||
|
||||
self.player_spawn_x_box.setValue(int(self.nbt["Player"]["SpawnX"].value))
|
||||
self.player_spawn_y_box.setValue(int(self.nbt["Player"]["SpawnY"].value))
|
||||
self.player_spawn_z_box.setValue(int(self.nbt["Player"]["SpawnZ"].value))
|
||||
|
||||
layout.addWidget(self.tabs)
|
||||
|
||||
|
@ -142,18 +146,18 @@ class EditorTab(QWidget):
|
|||
|
||||
self.game_box = QComboBox()
|
||||
self.game_box.addItems(["Survival", "Creative"])
|
||||
|
||||
#self.mobs_toggle = AnimatedToggle(
|
||||
|
||||
# self.mobs_toggle = AnimatedToggle(
|
||||
# checked_color="#59b8e0",
|
||||
# pulse_checked_color="#92cee8"
|
||||
#)
|
||||
|
||||
# )
|
||||
|
||||
self.time_label = QLabel("Time (In Ticks)")
|
||||
|
||||
|
||||
self.time_edit = QLineEdit()
|
||||
self.time_edit.setPlaceholderText("1770")
|
||||
self.time_edit.setValidator(QIntValidator())
|
||||
|
||||
|
||||
self.back_button = QPushButton("Back")
|
||||
|
||||
self.save_button = QPushButton("Save")
|
||||
|
@ -170,9 +174,9 @@ class EditorTab(QWidget):
|
|||
|
||||
layout.addWidget(self.game_label, 3, 0)
|
||||
layout.addWidget(self.game_box, 3, 1)
|
||||
|
||||
layout.addWidget(self.time_label, 4, 0)
|
||||
layout.addWidget(self.time_edit, 4, 1)
|
||||
|
||||
layout.addWidget(self.time_label, 4, 0)
|
||||
layout.addWidget(self.time_edit, 4, 1)
|
||||
|
||||
layout.addWidget(self.back_button, 5, 0)
|
||||
layout.addWidget(self.save_button, 5, 1)
|
||||
|
@ -180,105 +184,98 @@ class EditorTab(QWidget):
|
|||
widget.setLayout(layout)
|
||||
|
||||
return widget
|
||||
|
||||
|
||||
|
||||
|
||||
def world_tab(self):
|
||||
|
||||
|
||||
layout = QGridLayout()
|
||||
|
||||
|
||||
x_label = QLabel("Spawnpoint X")
|
||||
|
||||
|
||||
self.spawn_x_box = QSpinBox()
|
||||
self.spawn_x_box.setMinimum(-128)
|
||||
self.spawn_x_box.setMaximum(128)
|
||||
|
||||
|
||||
y_label = QLabel("Spawnpoint Y")
|
||||
|
||||
|
||||
self.spawn_y_box = QSpinBox()
|
||||
self.spawn_y_box.setMinimum(-64)
|
||||
self.spawn_y_box.setMaximum(64)
|
||||
|
||||
|
||||
z_label = QLabel("Spawnpoint Z")
|
||||
|
||||
|
||||
self.spawn_z_box = QSpinBox()
|
||||
self.spawn_z_box.setMinimum(-128)
|
||||
self.spawn_z_box.setMaximum(128)
|
||||
|
||||
|
||||
player_x_label = QLabel("Player Spawnpoint X")
|
||||
|
||||
|
||||
self.player_spawn_x_box = QSpinBox()
|
||||
self.player_spawn_x_box.setMinimum(-128)
|
||||
self.player_spawn_x_box.setMaximum(128)
|
||||
|
||||
|
||||
player_y_label = QLabel("Player Spawnpoint Y")
|
||||
|
||||
|
||||
self.player_spawn_y_box = QSpinBox()
|
||||
self.player_spawn_y_box.setMinimum(-64)
|
||||
self.player_spawn_y_box.setMaximum(64)
|
||||
|
||||
|
||||
player_z_label = QLabel("Player Spawnpoint Z")
|
||||
|
||||
|
||||
self.player_spawn_z_box = QSpinBox()
|
||||
self.player_spawn_z_box.setMinimum(-128)
|
||||
self.player_spawn_z_box.setMaximum(128)
|
||||
|
||||
layout.addWidget(x_label, 0, 0)
|
||||
layout.addWidget(y_label, 1, 0)
|
||||
layout.addWidget(z_label, 2, 0)
|
||||
|
||||
layout.addWidget(player_x_label, 3, 0)
|
||||
layout.addWidget(player_y_label, 4, 0)
|
||||
layout.addWidget(player_z_label, 5, 0)
|
||||
|
||||
note_label = QLabel("Note:\nPlayer spawnpoints are very buggy!\nYou might spawn in the wrong\nplace or even outside the world!\nDo not use on valuable worlds.")
|
||||
|
||||
layout.addWidget(x_label, 0, 0)
|
||||
layout.addWidget(y_label, 1, 0)
|
||||
layout.addWidget(z_label, 2, 0)
|
||||
|
||||
|
||||
layout.addWidget(self.spawn_x_box, 0, 1)
|
||||
layout.addWidget(self.spawn_y_box, 1, 1)
|
||||
layout.addWidget(self.spawn_z_box, 2, 1)
|
||||
|
||||
layout.addWidget(self.player_spawn_x_box, 3, 1)
|
||||
layout.addWidget(self.player_spawn_y_box, 4, 1)
|
||||
layout.addWidget(self.player_spawn_z_box, 5, 1)
|
||||
|
||||
layout.addWidget(note_label, 6, 0, 1, 2)
|
||||
layout.addWidget(player_x_label, 3, 0)
|
||||
layout.addWidget(player_y_label, 4, 0)
|
||||
layout.addWidget(player_z_label, 5, 0)
|
||||
|
||||
note_label = QLabel(
|
||||
"Note:\nPlayer spawnpoints are very buggy!\nYou might spawn in the wrong\nplace or even outside the world!\nDo not use on valuable worlds."
|
||||
)
|
||||
|
||||
layout.addWidget(self.spawn_x_box, 0, 1)
|
||||
layout.addWidget(self.spawn_y_box, 1, 1)
|
||||
layout.addWidget(self.spawn_z_box, 2, 1)
|
||||
|
||||
layout.addWidget(self.player_spawn_x_box, 3, 1)
|
||||
layout.addWidget(self.player_spawn_y_box, 4, 1)
|
||||
layout.addWidget(self.player_spawn_z_box, 5, 1)
|
||||
|
||||
layout.addWidget(note_label, 6, 0, 1, 2)
|
||||
|
||||
|
||||
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
|
||||
|
||||
self.scroll = QScrollArea()
|
||||
|
||||
|
||||
self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
|
||||
self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
self.scroll.setWidgetResizable(True)
|
||||
self.scroll.setWidget(widget)
|
||||
|
||||
|
||||
return self.scroll
|
||||
|
||||
def save(self):
|
||||
self.nbt["LevelName"] = nbt.nbtlib.String(self.name_edit.text())
|
||||
self.nbt["LastPlayed"] = nbt.nbtlib.Long(self.timestamp_box.value())
|
||||
self.nbt["LevelName"] = nbt.pynbt.TAG_String(self.name_edit.text())
|
||||
self.nbt["LastPlayed"] = nbt.pynbt.TAG_Long(self.timestamp_box.value())
|
||||
self.nbt["GameType"] = GAME_TYPES[self.game_box.currentText()]
|
||||
self.nbt["RandomSeed"] = nbt.nbtlib.Long(int(self.seed_edit.text()))
|
||||
self.nbt["Time"] = nbt.nbtlib.Long(int(self.time_edit.text()))
|
||||
|
||||
self.nbt["SpawnX"] = nbt.nbtlib.Int(self.spawn_x_box.value())
|
||||
self.nbt["SpawnY"] = nbt.nbtlib.Int(self.spawn_y_box.value())
|
||||
self.nbt["SpawnZ"] = nbt.nbtlib.Int(self.spawn_z_box.value())
|
||||
|
||||
self.nbt["Player"]["SpawnX"] = nbt.nbtlib.Int(self.player_spawn_x_box.value())
|
||||
self.nbt["Player"]["SpawnY"] = nbt.nbtlib.Int(self.player_spawn_y_box.value())
|
||||
self.nbt["Player"]["SpawnZ"] = nbt.nbtlib.Int(self.player_spawn_z_box.value())
|
||||
|
||||
|
||||
self.nbt["RandomSeed"] = nbt.pynbt.TAG_Long(int(self.seed_edit.text()))
|
||||
self.nbt["Time"] = nbt.pynbt.TAG_Long(int(self.time_edit.text()))
|
||||
|
||||
self.nbt["SpawnX"] = nbt.pynbt.TAG_Int(self.spawn_x_box.value())
|
||||
self.nbt["SpawnY"] = nbt.pynbt.TAG_Int(self.spawn_y_box.value())
|
||||
self.nbt["SpawnZ"] = nbt.pynbt.TAG_Int(self.spawn_z_box.value())
|
||||
|
||||
self.nbt["Player"]["SpawnX"] = nbt.pynbt.TAG_Int(self.player_spawn_x_box.value())
|
||||
self.nbt["Player"]["SpawnY"] = nbt.pynbt.TAG_Int(self.player_spawn_y_box.value())
|
||||
self.nbt["Player"]["SpawnZ"] = nbt.pynbt.TAG_Int(self.player_spawn_z_box.value())
|
||||
|
||||
nbt.save_nbt(self.nbt, self.filename)
|
||||
|
||||
|
||||
|
||||
class NBTEditor(QWidget):
|
||||
|
@ -302,14 +299,14 @@ class NBTEditor(QWidget):
|
|||
f"/home/{USER}/.minecraft-pi/games/com.mojang/minecraftWorlds/",
|
||||
"Minecraft Pi Level NBT (level.dat)",
|
||||
)
|
||||
|
||||
if fname[0] == '':
|
||||
|
||||
if fname[0] == "":
|
||||
return
|
||||
|
||||
|
||||
editor = EditorTab(fname[0])
|
||||
editor.back_button.clicked.connect(lambda: self.layout.setCurrentIndex(0))
|
||||
|
||||
self.layout.insertWidget(1, editor)
|
||||
self.layout.insertWidget(1, editor)
|
||||
self.layout.setCurrentIndex(1)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ SOFTWARE.
|
|||
|
||||
"""
|
||||
|
||||
import nbtlib
|
||||
import pynbt
|
||||
import subprocess
|
||||
|
||||
|
||||
|
@ -53,13 +53,15 @@ def load_nbt(filename: str, header=False):
|
|||
if header:
|
||||
remove_header(filename)
|
||||
|
||||
with nbtlib.load(
|
||||
filename=filename + "_temp.dat", gzipped=False, byteorder="little"
|
||||
) as nbt:
|
||||
with open(filename+"_temp.dat", "rb") as nbt:
|
||||
nbt = pynbt.NBTFile(io=nbt, little_endian=True)
|
||||
return nbt
|
||||
|
||||
|
||||
def save_nbt(nbt: nbtlib.File, filename: str, header=True):
|
||||
nbt.save(filename + "_temp.dat")
|
||||
def save_nbt(nbt: pynbt.NBTFile, filename: str, header=True):
|
||||
|
||||
with open(filename+"_temp.dat", "wb") as writefile:
|
||||
nbt.save(io=writefile, little_endian = True)
|
||||
|
||||
if header:
|
||||
add_header(filename)
|
||||
|
|
|
@ -4,3 +4,4 @@ pypresence
|
|||
pillow
|
||||
qtwidgets
|
||||
darkdetect
|
||||
pynbt
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pip3 install pyqtdarktheme pypresence pillow darkdetect qtwidgets
|
||||
pip3 install pyqtdarktheme pypresence pillow darkdetect qtwidgets pynbt
|
||||
link /usr/lib/planet-launcher/main.py /usr/bin/planet-launcher
|
||||
chmod 755 /usr/lib/planet-launcher/main.py
|
||||
link /usr/lib/planet-launcher/assets/planet-launcher.desktop /usr/share/applications/planet-launcher.desktop
|
||||
|
|
Loading…
Reference in New Issue