Skip to content

Commit

Permalink
Recipe Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJupiterDev authored Nov 8, 2024
1 parent e78fac7 commit a2bdb58
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 82 deletions.
127 changes: 65 additions & 62 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def recipeSlot(self, id):

def itemFormClosed(self, id, item):
self.recipe[str(id)] = item
print(self.recipe)
if id == 0:
self.ui.slot0Label.setText(item)
elif id == 1:
Expand Down Expand Up @@ -707,69 +706,73 @@ def generate(self):

# Recipes
for recipe in self.recipes:
with open(f'{self.packNamespace}\\recipe\\{self.recipes[recipe]["name"]}.json', 'a') as file:
letters = {"0": "A", "1": "D", "2": "G", "3": "B", "4": "E", "5": "H", "6": "C", "7": "F", "8": "I"}
recip = self.recipes[recipe]["items"]
file.write('{"type": "minecraft:crafting_shaped", "pattern": ["')
if recip["0"] != "":
file.write("A")
else:
file.write(" ")
if recip["3"] != "":
file.write("B")
else:
file.write(" ")
if recip["6"] != "":
file.write("C")
else:
file.write(" ")

file.write('","')

if recip["1"] != "":
file.write("D")
else:
file.write(" ")
if recip["4"] != "":
file.write("E")
else:
file.write(" ")
if recip["7"] != "":
file.write("F")
else:
file.write(" ")

file.write('","')

if recip["2"] != "":
file.write("G")
else:
file.write(" ")
if recip["5"] != "":
file.write("H")
else:
file.write(" ")
if recip["8"] != "":
file.write("I")
else:
file.write(" ")

file.write('"],"key":{')

for i in range(8):
if recip[str(i)] != "":
file.write('"' + letters[str(i)] + '":"minecraft:' + recip[str(i)] + '",')
if recip[str(8)] != "":
file.write('"' + letters[str(8)] + '":"minecraft:' + recip[str(8)] + '"')
if not self.recipes[recipe]["shapeless"]:
with open(f'{self.packNamespace}\\recipe\\{self.recipes[recipe]["name"]}.json', 'a') as file:
file.truncate(0)
file.seek(0)
letters = {"0": "A", "1": "D", "2": "G", "3": "B", "4": "E", "5": "H", "6": "C", "7": "F", "8": "I"}
recip = self.recipes[recipe]["items"]
file.write('{"type": "minecraft:crafting_shaped", "pattern": ["')
if recip["0"] != "":
file.write("A")
else:
file.write(" ")
if recip["3"] != "":
file.write("B")
else:
file.write(" ")
if recip["6"] != "":
file.write("C")
else:
file.write(" ")

file.write('","')

with open(f'{self.packNamespace}\\recipe\\{self.recipes[recipe]["name"]}.json', 'r+') as file:
content = file.read()
comma = content.rfind(',')
print(comma)
if comma != -1: content = content[:comma] + content[comma + 1:]
file.truncate(0)
file.write(content + '},"result": { "id":"minecraft:' + recip[str(9)] + '", "count":' + self.recipes[recipe]["count"] + '}}')
if recip["1"] != "":
file.write("D")
else:
file.write(" ")
if recip["4"] != "":
file.write("E")
else:
file.write(" ")
if recip["7"] != "":
file.write("F")
else:
file.write(" ")

file.write('","')

if recip["2"] != "":
file.write("G")
else:
file.write(" ")
if recip["5"] != "":
file.write("H")
else:
file.write(" ")
if recip["8"] != "":
file.write("I")
else:
file.write(" ")

file.write('"],"key":{')
items = [(k, v) for k, v in recip.items() if v not in (None, '')][:-1]
for i, (key, value) in enumerate(items):
if value != "" and value != None:
file.write('"' + letters[str(key).replace("'", '"')] + '":"minecraft:' + value + '"')
if i < len(items) -1: file.write(',')
file.write('},"result": { "id":"minecraft:' + recip[str(9)] + '", "count":' + self.recipes[recipe]["count"] + '}}')
else:
with open(f'{self.packNamespace}\\recipe\\{self.recipes[recipe]["name"]}.json', 'a') as file:
recip = self.recipes[recipe]["items"]
file.write('{"type": "minecraft:crafting_shapeless", "ingredients": [')
items = [(k, v) for k, v in recip.items() if v not in (None, '')][:-1]
for ingredient, (key, value) in enumerate(items):
if str(value) != "":
file.write('"minecraft:' + str(value) + '"')
if ingredient < len(items) - 1: file.write(',')
file.write('],"result":{"id": "minecraft:' + recip[str(9)] + '", "count":' + self.recipes[recipe]["count"] + '}}')

self.setStatus("Generated!")

Expand Down
46 changes: 26 additions & 20 deletions src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def setupUi(self, MainWindow):
self.status.setText("")
self.status.setObjectName("status")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 921, 671))
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 921, 721))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def setupUi(self, MainWindow):
self.menuBar.addAction(self.menuFile.menuAction())

self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(3)
self.tabWidget.setCurrentIndex(0)
self.tabWidget_2.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

Expand Down Expand Up @@ -1063,7 +1063,7 @@ def retranslateUi(self, MainWindow):
self.placeSound.setPlaceholderText(_translate("MainWindow", "minecraft:block.stone.place"))
self.blockName.setToolTip(_translate("MainWindow", "<html><head/><body><p>The name the program and the pack recognizes.<br/>Supports lowercase characters &amp; underscores.</p></body></html>"))
self.blockName.setPlaceholderText(_translate("MainWindow", "ruby_ore"))
self.blockModel.setToolTip(_translate("MainWindow", "<html><head/><body><p>The block model! As of now, you can only create full blocks, but</p><p>slabs &amp; stairs are planned for some point.</p></body></html>"))
self.blockModel.setToolTip(_translate("MainWindow", "<html><head/><body><p>Block: A regular block.</p><p>Custom: Your own custom 3D model.</p></body></html>"))
self.blockModel.setItemText(0, _translate("MainWindow", "Block"))
self.blockModel.setItemText(1, _translate("MainWindow", "Custom"))
self.bottomFaceBtn.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Bottom face of the block</p></body></html>"))
Expand Down Expand Up @@ -1098,11 +1098,11 @@ def retranslateUi(self, MainWindow):
self.groupBox.setTitle(_translate("MainWindow", "Bottom"))
self.label_22.setText(_translate("MainWindow", "If Model is set to custom, then only this texture will be applied to the whole model."))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Blocks"))
self.itemList.setToolTip(_translate("MainWindow", "<html><head/><body><p>A list of all custom blocks you have created.</p></body></html>"))
self.itemList.setToolTip(_translate("MainWindow", "<html><head/><body><p>A list of all custom items you have created.</p></body></html>"))
self.label_16.setText(_translate("MainWindow", "All Items"))
self.buttonEditItem.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a block from above, then press Edit to edit the block.</p></body></html>"))
self.buttonEditItem.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a items from above, then press Edit to edit the block.</p></body></html>"))
self.buttonEditItem.setText(_translate("MainWindow", "Edit"))
self.buttonRemoveItem.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a block from above, then press Remove to delete it.<br/>This action cannot be undone.</p></body></html>"))
self.buttonRemoveItem.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a items from above, then press Remove to delete it.<br/>This action cannot be undone.</p></body></html>"))
self.buttonRemoveItem.setText(_translate("MainWindow", "Remove"))
self.label_8.setText(_translate("MainWindow", "Display Name:"))
self.itemDisplayName.setToolTip(_translate("MainWindow", "<html><head/><body><p>The name your item displays in your inventory.</p></body></html>"))
Expand All @@ -1119,34 +1119,40 @@ def retranslateUi(self, MainWindow):
self.itemComponents.setToolTip(_translate("MainWindow", "<html><head/><body><p>Any custom components you want to add to the item. <span style=\" font-weight:600;\">This will be removed in a future update.</span></p></body></html>"))
self.itemComponents.setPlaceholderText(_translate("MainWindow", "minecraft:custom_data={my_data:1b},attributes={[]}"))
self.label_21.setText(_translate("MainWindow", "Model:"))
self.itemModel.setToolTip(_translate("MainWindow", "<html><head/><body><p>Generated for regular items.</p><p>Handheld for things such as swords or shovels.</p></body></html>"))
self.itemModel.setToolTip(_translate("MainWindow", "<html><head/><body><p>Generated for regular items.</p><p>Handheld for things such as swords or shovels.</p><p>Custom to select your own 3D model.</p></body></html>"))
self.itemModel.setItemText(0, _translate("MainWindow", "Generated"))
self.itemModel.setItemText(1, _translate("MainWindow", "Handheld"))
self.itemModel.setItemText(2, _translate("MainWindow", "Custom"))
self.itemAddButton.setToolTip(_translate("MainWindow", "<html><head/><body><p>Adds the item to be generated!</p></body></html>"))
self.itemAddButton.setText(_translate("MainWindow", "Add Item"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "Items"))
self.recipeList.setToolTip(_translate("MainWindow", "<html><head/><body><p>A list of all custom blocks you have created.</p></body></html>"))
self.buttonEditRecipe.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a block from above, then press Edit to edit the block.</p></body></html>"))
self.recipeList.setToolTip(_translate("MainWindow", "<html><head/><body><p>A list of all custom recipes you have created.</p></body></html>"))
self.buttonEditRecipe.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a recipe from above, then press Edit to edit the block.</p></body></html>"))
self.buttonEditRecipe.setText(_translate("MainWindow", "Edit"))
self.buttonRemoveRecipe.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a block from above, then press Remove to delete it.<br/>This action cannot be undone.</p></body></html>"))
self.buttonRemoveRecipe.setToolTip(_translate("MainWindow", "<html><head/><body><p>Click a recipe from above, then press Remove to delete it.<br/>This action cannot be undone.</p></body></html>"))
self.buttonRemoveRecipe.setText(_translate("MainWindow", "Remove"))
self.label_23.setText(_translate("MainWindow", "All Recipes"))
self.shapeless.setToolTip(_translate("MainWindow", "<html><head/><body><p>Should the recipe be shapeless?</p></body></html>"))
self.shapeless.setText(_translate("MainWindow", "Shapeless?"))
self.slot6.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot5.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot8.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot2.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot9.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot4.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot1.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot6.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot5.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot8.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot2.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot9.setToolTip(_translate("MainWindow", "<html><head/><body><p>The output of the crafting recipe. Click to select.</p></body></html>"))
self.slot4.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot1.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.exact.setToolTip(_translate("MainWindow", "<html><head/><body><p>Should it be exactly where places?</p></body></html>"))
self.exact.setText(_translate("MainWindow", "Exactly where Placed?"))
self.slot7.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot3.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot0.setToolTip(_translate("MainWindow", "<html><head/><body><p>The Top face of the block</p></body></html>"))
self.slot7.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot3.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.slot0.setToolTip(_translate("MainWindow", "<html><head/><body><p>One of the 9 slots in a crafting table. Click to select item/block.</p></body></html>"))
self.lineEdit.setToolTip(_translate("MainWindow", "<html><head/><body><p>The name of the recipe! Should be lowercase &amp; underscores only.</p></body></html>"))
self.label_25.setText(_translate("MainWindow", "Recipe Name:"))
self.slot9Count.setToolTip(_translate("MainWindow", "<html><head/><body><p>The count of the output.</p></body></html>"))
self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_5), _translate("MainWindow", "Crafting"))
self.label_24.setText(_translate("MainWindow", "COMING SOON!"))
self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_6), _translate("MainWindow", "Smelting"))
self.buttonAddRecipe.setToolTip(_translate("MainWindow", "<html><head/><body><p>Adds the recipe!</p></body></html>"))
self.buttonAddRecipe.setText(_translate("MainWindow", "Add"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "Recipes"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
Expand Down

0 comments on commit a2bdb58

Please sign in to comment.