Minecraft Enchanting Simulator - Browser UI
Files added:
- index.html : The web UI
- styles.css : Styling
- script.js : Logic + charting
How to run (recommended):
- Serve the folder over HTTP (browsers block fetch on local files). From the project folder run:
# Simple Python 3 http server
python -m http.server 8000-
Open your browser to: http://localhost:8000/index.html
-
Use the dropdowns to select an item/material, choose enchant level and iterations, then click "Run Simulation".
Notes:
- The site fetches
items.jsonandenchantments.jsonfrom the same folder. Make sure those files are present. - Chart colours are taken from
enchantments.jsoncolorfields. - The simulator uses the same general mechanics as the notebook/runner but is simplified to run in the browser. Iterations are limited to avoid freezing the page.
Next steps you may want:
- Fill
applicable_itemsarrays inenchantments.jsonto restrict enchantments to correct item groups. - Add server-side endpoints if you want to run very large simulations (offload work from the browser).
- Add tooltips and nicer UX for chart details.
Python simulator (new)
- The algorithmic simulator has been added at the repository root as
enchant_simulator.py. - It implements Minecraft's enchanting-table algorithm (bookshelves → slot → enchantability modifiers → weighted selection, conflicts, extra-enchant iterations).
Quick examples (PowerShell):
# Run the small demo that prints a couple of sample draws
& ".venv\Scripts\python.exe" "./enchant_simulator.py"
# Use the simulator programmatically from a short script (example):
& ".venv\Scripts\python.exe" - <<'PY'
from enchant_simulator import EnchantSimulator
sim = EnchantSimulator()
print(sim.sample_by_modified_level('Helmet', 'Chain', 20, allow_treasure=False))
print(sim.sample_by_bookshelves('Sword', 'Diamond', 15, slot='bottom'))
PYValidation runner
- A helper script
run_validation.py(repo root) runs Monte Carlo trials to sample the simulator. To run 3 validation runs of 10,000 trials each:
& ".venv\Scripts\python.exe" "./run_validation.py"Notes
- Table-mode generation excludes treasure-only enchants (controlled by the
Treasureflag inItems_New_Probability/database.json).Treasure: truemarks an enchant as treasure-only; such enchants are excluded from enchanting-table draws unlessallow_treasure=Trueor the source explicitly permits treasure enchants (for example, Level-30 Books). - The new simulator uses enchantability values from
Items_New_Probability/database.json. - Results will differ from
Items_Old_Probabilityfiles because the enchant pool and metadata were expanded.
- For armor items (Helmet, Chestplate, Leggings, Boots, TurtleShell) the simulator will use the
armorEnchantabilityvalue fromItems_New_Probability/database.jsonwhen that key is present for a material. IfarmorEnchantabilityis missing the simulator falls back to the genericenchantabilityvalue. This ensures armor uses the intended, separate enchantability that differs from tools in some materials (for exampleGoldoften has a higherarmorEnchantability).
Example: to regenerate Helmet probabilities using base-level sampling (base-level 10) for all materials and levels 1..30 using 3 workers and 100k trials per level:
& ".venv\Scripts\python.exe" "./scripts/generate_new_probs.py" --mode base --items Helmet --materials Leather Chain Iron Diamond Gold Netherite --trials 100000 --workers 3 --all-levels --level 30 --seed 123The static site generator scripts/generate_enchant_site.py can produce per-enchant HTML pages and lightweight embedded SVG charts. It also supports producing high-resolution PNG graphs (useful for publishing or printing) when matplotlib and numpy are installed.
Install the optional dependencies:
pip install matplotlib numpyExamples (PowerShell):
Basic generation (reads precomputed JSONs from Items_New_Probability):
.venv\Scripts\python.exe scripts/generate_enchant_site.py --use-existing --outdir web/enchant_tables_existing --levels 30Embedded SVG graphs (lighter weight):
.venv\Scripts\python.exe scripts/generate_enchant_site.py --use-existing --outdir web/enchant_tables_existing --levels 30 --graphsHigh-resolution PNG graphs (requires matplotlib):
.venv\Scripts\python.exe scripts/generate_enchant_site.py --use-existing --outdir web/enchant_tables_existing --levels 30 --hires-graphs --graph-dpi 200 --graph-width 2000 --graph-height 500Notes:
--hires-graphscreates anassets/folder next to each enchant directory and saves PNG files named by item/material anchors (e.g.Sword_Diamond.png).- If
matplotlibis missing the script will skip PNG generation and continue producing HTML + embedded SVGs if requested. - Use
--xp-formula pernsteiner(default) or--xp-formula simpleto control XP cost computations used for estimated XP per attempt.