New Features - Faith-and-Code-Technologies/mDirt GitHub Wiki
How to Add New Feature Types (Elements) to mDirt
🚧 This page is under construction and very unfinished 🚧
Expanding mDirt with new Minecraft feature types (like Biomes, Advancements, etc.) lets you grow the app’s capabilities and support more kinds of content.
This guide walks you through the process of adding a new element type to mDirt.
Overview
Adding a new element type involves:
- Building the GUI
- Adding application logic
- Creating the generator
Step 1: Build the GUI
- Open lib/ui.ui in Qt Designer.
- Add a new page to the QStackedWidget named
elementEditor
.
Note the page number — you'll use it in code. - In the menu bar, add a new Action under "New Element" titled {Element}.
- Add all necessary input widgets for the element. Name them clearly (e.g. elementNameInput, elementColorPicker, etc.)
- Save the UI file.
- In Qt Designer, go to: Form > View Python Code > Save
- Save to src/ui/ui.py
- Overwrite when prompted
Step 2: Add Application Logic
2.1 - Update Enums
In src/utils/enums.py, under ElementPage
, add your new element.
main.py
2.2 - Add Element Logic in In src/main.py, define the following methods for your element:
new{Element}
add{Element}
edit{Element}
validate{Element}Details
These can be modeled after how other elements are handled.
2.3 - Add Connections
In App.__init__
:
- Connect the new menu action using
.triggered.connect(self.new{Element})
- Connect any buttons or signals
- Add Drop Handlers if needed
2.4 - Setup Project State
In App.setupProjectData
:
- Add a new dictionary for your element:
self.{element} = {}
- Add a corresponding
QTreeWidgetItem
to the tree
2.5 - Save Project
In App.saveProjectAs
:
- Add:
with open(projectDirectory / '{element}.json', 'w') as file:
json.dump(self.{element}, file, indent=4)
- Also add:
os.makedirs(projectDirectory / '{element}', exist_ok=True)
2.6 - Load Project
In App.loadProject
:
- Load the file:
with open(projectDirectory / '{element}.json') as file:
self.{element} = json.load(file)
- Populate the tree:
for item in self.{element}:
# Create QTreeWidgetItem and add to tree
2.7 - Handle Selection
In App.elementClicked
, add a block for your new element
2.8 - Hook Into Generation
In App.generate
, pass self.{element}
into the generator
Step 3: Create the Generator
🚧 This page is incomplete! 🚧