[Mod] Override [0.2] [override]

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

[Mod] Override [0.2] [override]

by AntumDeluge » Thu Aug 03, 2017 06:17

Override Mod

Description:

A mod to simplify overriding craft items. Single or multiple items can be overridden with another pre-registered item using override.replaceItems. Single or multiple items can be overridden with a newly created item using override.overrideItems.

Supported object types:

(overriding other types of objects may be supported in the future)

Global functions:
  • override.replaceItems (items, target)
    • Unregisters items & set names as aliases for another existing item.
    • items: List of item names to be overridden (can be string for single item override).
    • target: Item name of aliases' target.
  • override.overrideItems (name, def)
    • Unregisters craft items & registers names as aliases for new item.
    • name: Name of new item.
    • def: Item definition (see: core.register_craftitem) with additional overrides field (list of item names to be overridden or string for single item override).

Examples:

To override multiple items with an item that is already registered, say default:diamond for example, call:
Code: Select all
override.replaceItems({"mod1:diamond", "mod2:diamond", ...}, "default:diamond")


To override multiple items with a newly created one, call:
Code: Select all
override.overrideItems("modname:item", {
    overrides = {"mod1:item", "mod2:item", ...},
    description = "New item",
    wield_image = "modname_item.png",
    ...
}


Pre-existing items can be overridden using a file named overrides.txt in the world path. Each new line in the file represents a call to overrides.replaceItems. The formatting is as follows:
Code: Select all
alias1,alias2,...;target

In the example above, each existing item (alias1, alias2, etc.) will be unregistered & re-added as an alias of target.

Licensing:

Requirements:
  • Depends: none

Links:
Last edited by AntumDeluge on Wed Aug 30, 2017 18:08, edited 7 times in total.
 

User avatar
DS-minetest
Member
 
Posts: 1025
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Override [0.1] [override]

by DS-minetest » Thu Aug 03, 2017 08:29

There's a minetest.override_item(name, redefinition) function (https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2247).
You shouldn't only look at the dev wiki.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
Linuxdirk
Member
 
Posts: 1658
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk
 

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Override [0.1] [override]

by AntumDeluge » Thu Aug 03, 2017 16:00

I believe this mod is a little different though, because it allows overriding multiple items at once & redefines them as aliases. Perhaps the semantics between override & redefine are confusing? I would consider the functionality of minetest.override_item to be more like redefining. Though, override works for that too.

Overriding multiple items as aliases of another is useful when there are multiple mods that use similar items. I'll try to think of a good example. At the moment I can only think of default:diamond & gems:diamond. I believe this mod makes it easy to unify similar items into one.

If the item that you want to use already exists, say default:diamond, just call:

Code: Select all
override.replaceItems({"mod1:diamond", "mod2:diamond", ...}, "default:diamond")


If you want to create a new item to override others, call:

Code: Select all
override.overrideItems("modname:diamond", {
    overrides = {"default:diamond", "gems:diamond",},
    description = "New diamond item",
    wield_image = "modname_diamond.png",
    ...
}


Also, I want to try to make this mod capable of overriding other object types as well.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Override [0.1] [override]

by AntumDeluge » Thu Aug 03, 2017 17:12

azekill_DIABLO wrote:alias?

So, if you call:
Code: Select all
override.replaceItems("gems:diamond", "default:diamond")

gems:diamond is first unregistered with:
Code: Select all
core.unregister_item("gems:diamond")

Then, it is re-added as an alias of default:diamond using:
Code: Select all
core.register_alias("gems:diamond", "default:diamond")


The same goes for multiple items:
Code: Select all
override.replaceItems({"mod1:diamond", "mod2:diamond",}, "default:diamond")

Each of mod1:diamond & mod2:diamond is first unregistered, then re-added as aliases of default:diamond.

So, in this mod, you're not just redefining an item. You are replacing it with either an existing or new one.
 

User avatar
rubenwardy
Moderator
 
Posts: 5545
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Override [0.1] [override]

by rubenwardy » Thu Aug 03, 2017 17:23

override.replaceItems("gems:diamond", "default:diamond")

Could be done with

minetest.register_alias_force("gems: diamond", "default:diamond")

Nice mod anyway, to allow doing this with lists
 

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Override [0.1] [override]

by AntumDeluge » Thu Aug 03, 2017 18:20

rubenwardy wrote:override.replaceItems("gems:diamond", "default:diamond")

Could be done with

minetest.register_alias_force("gems: diamond", "default:diamond")

I had forgotten about force.
 

User avatar
Wuzzy
Member
 
Posts: 3243
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod] Override [0.1] [override]

by Wuzzy » Thu Aug 03, 2017 23:29

This mod seems pointless. It's just a wrapper mod which doesn't add any new functionality.

If you think the syntax of current Lua API is lacking, just fix Minetest.
My creations. I gladly take any bitcoins you have lying around: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH
 

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Override [0.1] [override]

by AntumDeluge » Fri Aug 04, 2017 00:25

I would prefer this functionality to be in the Minetest core, but I'm not a very good C++ coder. I may put in a feature request though.


--- Edit ---

Now can read from overrides.txt in world path:

override @ Git commit 35ab53c
Last edited by AntumDeluge on Wed Aug 30, 2017 18:08, edited 1 time in total.
 

User avatar
AntumDeluge
Member
 
Posts: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Override [0.2] [override]

by AntumDeluge » Wed Aug 30, 2017 18:07

UPDATES:
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 


Return to WIP Mods



Who is online

Users browsing this forum: Bing [Bot] and 1 guest