minetest-mods / 3d_armor

Visible player armor & wielded items for minetest
Other
17 stars 39 forks source link

[Feature]: Reduce duplicative code around craft recepies #118

Open Lazerbeak12345 opened 1 year ago

Lazerbeak12345 commented 1 year ago

In https://github.com/minetest-whynot/whynot-game/pull/170#discussion_r1372463656

It seems all code with @section craft has a lot of duplicative behavior shared with (virtually) all armor. The license isn't compatible, but I've seen that Instant Ores does this in a better way, by making a function for this. Edge cases would be best served the way this code is currently written, with abstractions for the most common cases.

(This issue is not blocking that pull request).

A few arguments for this:

  1. Less code is less bugs
  2. Less code is less work to maintain
  3. Less code is less code to update when changes happen.
  4. A lot of this code is actually documentation. It's nearly (if not exactly the same) across all of them, and could be unified to one place.
  5. Edge cases can still be done alongside the conventional function call.
  6. A lot of different armor mods outside of this modpack could make great use of this new API.

Problem:

I don't know where the function would go, or what it would and wouldn't cover.

Requirements

BuckarooBanzay commented 1 year ago

Proposals/PR's welcome :+1:

Lazerbeak12345 commented 1 year ago

Early draft API proposal:

A few new functions, place on the armor table and exact names are TBD

For exceptions like the two wooden shields, using only the abstractions above would be a bad idea. They should use the current API for recipe exceptions.

The registration function for shield crafting should be owned by the shields mod. The sheilds mod could perhaps override the "standard recipes" function to also register a shield. Alternatively, a data-oriented approach could be taken, and the "standard recipes" function could determine what functions to call via a list of function references stored in an accessible place.

Recipe names will be the most difficult part if the API is to work for 3rd party armor mods.

BuckarooBanzay commented 1 year ago

It seems all code with @section craft has a lot of duplicative behavior shared with (virtually) all armor.

uh, before i forget: make sure to don't mess up the docs if possible: https://minetest-mods.github.io/3d_armor/reference/topics/helmets.html