[Mod] Offhand Items [offhand] [1.1.0]

Post Reply
User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

[Mod] Offhand Items [offhand] [1.1.0]

by TestificateMods » Post

When playing Minetest, I always missed the handiness of the offhand that Minecraft has.
While out adventuring, it is really convenient to throw down some torches without having to deselect your sword.
While building, it is a real time saver to keep your pickaxe equipped for upcoming mistakes while you're building.

The mcl_offhand mod for Mineclone2 provides such an offhand but it is limited to that specific game and it only lets you equip shields, not building blocks or torches.
That's why I edited it to remove the dependency and to let you use any item of your choice.

Image

How it works
  • Install the mod alongside controls and modlib.
  • Select a stack of nodes, torches, etc. in your hotbar
  • Press your aux1 button (usually E) to move that stack to your offhand
  • Select any tool (like a sword or pickaxe) or an empty hand in your hotbar
  • Right-click to place nodes from your offhand
Compatibility with sprint mods
By default, the mod uses the aux1 key to switch items between hands. The same key that some sprint mods use. You can select a different key in the mod settings. Alternatively, give minetest_wadsprint a try which doesn't require that key.

Recommended mods
I recommend using visible_wielditem to ensure that items look the same in both hands.

Use wielded_light to make held torches (and other glowing things) emit light while in your offhand. The illumination mod is not compatible, so make sure you use wielded_light instead.

If you use 3d_armor then I recommend disabling the included wieldview mod in favour of visible_wielditem. If you don't like the 3d item display on your offhand then you can also disable that in this mod's settings. The item will not be displayed if equipped with a shield to prevent clipping.

License
GNU GPL v3, following the original mod
This is a fork of mcl_offhand. For credit, please also checkout Mineclone2's credit section.
The code for the 3D item view is forked form visible_wielditem and dual-licensed under GNU GPL v3 as well as MIT.

The texture pack used in the video above is Soothing32

Links
Download - Source Code
Last edited by TestificateMods on Sun Mar 26, 2023 20:21, edited 32 times in total.

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: [Mod] Offhand Items [offhand] [0.0.1]

by Andrey01 » Post

There is the PR being currently developed for adding that feature (Dual Wielding): https://github.com/minetest/minetest/pull/11016 Only probably it doesn't have key binding for now, however the items swapping is possible to be executed e.g. via the chat command.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.1]

by TestificateMods » Post

Andrey01 wrote:
Sat Feb 25, 2023 11:22
There is the PR being currently developed for adding that feature
A proper engine implementation is of course a better solution but will probably still take some time.
With this Lua implentation, I am mostly trying to fill the gap until then. The offhand is something I always missed, so it's better to have something usable now than having to wait. Most people probably don't want to download an experimental development branch and compile Minetest themselves.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.4]

by TestificateMods » Post

Changes since 0.0.1
  • Items now show up on the player model when no shield is equipped (configurable)
  • Items now drop into the player bones upon death (requires bones mod)
  • Lumiscent items now emit light when held (requires wielded_light)
  • Bugfixes
Uploaded to ContentDB now, can be installed from there once it passes review.

Bonus: Happy Sam holding a stack of torches while wielding a sword:
Image
(used texture pack: Soothing32)

I now consider this mod mostly stable, so should be safe to use with pretty much anything.

User avatar
Tarruvi
New member
Posts: 6
Joined: Sat Feb 18, 2023 12:09
IRC: Tarruvi
In-game: Tarruvi

Re: [Mod] Offhand Items [offhand] [0.0.4]

by Tarruvi » Post

Which file do you set a key to be the off-hand switch key? The key I wanted to be the default key is "F", and I have no clue how to set it.

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Offhand Items [offhand] [0.0.4]

by Blockhead » Post

Tarruvi wrote:
Wed Mar 01, 2023 07:03
Which file do you set a key to be the off-hand switch key? The key I wanted to be the default key is "F", and I have no clue how to set it.
It's the Aux1 key. Use the in-game keybindings menu to configure that key to be F. That's available in-game from the Escape key menu. Minetest doesn't have a complicated control API, so all the keys in that menu are the maximum extent of what any mod can use as keybindings. You can read my detailed opinion about why F should be Aux1 and E for inventory over at this thread.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Tarruvi
New member
Posts: 6
Joined: Sat Feb 18, 2023 12:09
IRC: Tarruvi
In-game: Tarruvi

Re: [Mod] Offhand Items [offhand] [0.0.4]

by Tarruvi » Post

Blockhead wrote:
Wed Mar 01, 2023 08:14
It's the Aux1 key. Use the in-game keybindings menu to configure that key to be F. That's available in-game from the Escape key menu.
I know about setting the key bindings, I've got the stamina mod installed and set it to "shift". But, I was hoping to set the key binding for the off-hand switch to a separate key (i.e. "F"). So whenever I sprint, I'm not switching items between hands. It's not a troubling thing having the same key be for sprinting and item switching, but. In a scenario where you're trying to run from hostile mobs and then scaffold upwards, the block in your hand could be replaced by something like an Apple when you pressed the key for Aux1.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.4]

by TestificateMods » Post

Tarruvi wrote:
Thu Mar 02, 2023 06:39
But, I was hoping to set the key binding for the off-hand switch to a separate key (i.e. "F"). So whenever I sprint, I'm not switching items between hands.
The short answer: That is not possible. The engine only lets us assign a single auxiliary key that isn't already assigned to some sort of functionality. There is no way for two mods to register two different hotkeys without overriding functionality.

You can look at my mod settings where you can bind the hotkey to something else but the other options will have similar issues. You could set it to the zoom key if your subgame doesn't give you the zoom privilege by default. Or you could set it to the sneak key which I've found to be slightly less irritating than sprinting.

I also had a look on ContentDB and there seems to be a mod called wadsprint that doesn't use the aux1 key. I haven't tested it, though.

User avatar
Tarruvi
New member
Posts: 6
Joined: Sat Feb 18, 2023 12:09
IRC: Tarruvi
In-game: Tarruvi

Re: [Mod] Offhand Items [offhand] [0.0.4]

by Tarruvi » Post

TestificateMods wrote:
Thu Mar 02, 2023 07:30
I also had a look on ContentDB and there seems to be a mod called wadsprint that doesn't use the aux1 key. I haven't tested it, though.
I am back from giving that mod a go, and it's promising. However, it's optional dependency on hud_hunger by BlockMen is not compatible with i3. Causing the hot bar to appear with 8 item slots when there's 9 available in i3. The hunger side works fine though.

I may just stick with the Stamina mod, and set the off-hand switch key to one of the other available controls.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.4]

by TestificateMods » Post

Tarruvi wrote:
Thu Mar 02, 2023 09:36
it's optional dependency on hud_hunger by BlockMen is not compatible with i3. Causing the hot bar to appear with 8 item slots when there's 9 available in i3. The hunger side works fine though.
You could either activate legacy inventory mode in i3 to reduce the hotbar to eight OR replace hud_hunger with hbhunger.

User avatar
joseanastacio
New member
Posts: 1
Joined: Thu Sep 16, 2021 13:46
GitHub: josegamestest
In-game: joseanastacio
Location: Pecanha, MG
Contact:

Re: [Mod] Offhand Items [offhand] [0.0.4]

by joseanastacio » Post

Very good
I liked the mod, I'm doing some tests with it, I liked the idea of ​​exchanging items,
I still need to test the shield of the armor mod on it.
I recorded a video about it on my channel
https://youtu.be/O9I498203o8

Gorm
Member
Posts: 29
Joined: Tue Feb 14, 2023 17:06

Re: [Mod] Offhand Items [offhand] [0.0.4]

by Gorm » Post

Hello!

Code: Select all

ERROR[Main]: ModError: Failed to load and run script from /home/user/Minetest/minetest-master/bin/../mods/offhand/init.lua:
ERROR[Main]: ...er/Minetest/minetest-master/bin/../mods/offhand/init.lua:15: bad argument #1 to 'insert' (table expected, got nil)
ERROR[Main]:       ...er/Minetest/minetest-master/bin/../mods/offhand/init.lua:15: in main chunk
I use the bones mod from fluxionary: https://content.minetest.net/packages/rheo/bones/

Looks like there is a little problem ;-)

Yours Gorm

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.4]

by TestificateMods » Post

Gorm wrote:
Fri Mar 03, 2023 18:19
I use the bones mod from fluxionary: https://content.minetest.net/packages/rheo/bones/
Looks like there is a little problem ;-)
Thanks! That bit of code was meant for bones mod but apparently didn't work with bones (redo). It's fixed now, so it shouldn't crash anymore.

If you want bones (redo) to handle the offhand inventory as well then you will need to add the "offhand" inventory to that mod's configuration like so:

Code: Select all

bones.lists_to_bones = main,craft,armor,offhand
The normal bones mod doesn't need that bit of extra setup.

Gorm
Member
Posts: 29
Joined: Tue Feb 14, 2023 17:06

Re: [Mod] Offhand Items [offhand] [0.0.5]

by Gorm » Post

Hello TestificateMods!

Thank you very much for your quick reply and the quick solution!
I tested the functionalty and now i'm near to happy :-)

But as always now the next thing appears:
menu_error.png
menu_error.png (62.28 KiB) Viewed 3455 times
Looks weird. Thats due to my 16 slot hotbar. I've looked at your code but did not found the place where the position is set. So ...
If i set my hotbar to 10 slots all is good but i prefer 16. :-)

One more issue arised. If i place pkarcs they are now rotated by 90° around y. If i disable offhand they are placed as before. But if i place slopes they are placed as usual. So this time the issue is maybe related to pkarcs. I look at it later.

Code: Select all

2023-03-04 20:55:26: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'petz' in callback luaentity_Step(): Runtime error from mod 'petz' in callback item_OnPlace(): .../Minetest/minetest-master/bin/../mods/offhand/init.lua:93: attempt to index local 'player' (a nil value)
2023-03-04 20:55:26: ERROR[Main]: stack traceback:
2023-03-04 20:55:26: ERROR[Main]:       .../Minetest/minetest-master/bin/../mods/offhand/init.lua:93: in function <...be/Minetest/minetest-master/bin/../mods/offhand/init.lua:92>
2023-03-04 20:55:26: ERROR[Main]:       [C]: in function 'place_node'
2023-03-04 20:55:26: ERROR[Main]:       .../minetest-master/bin/../mods/petz/petz/brains/bh_ant.lua:58: in function 'bh_lay_antegg'
2023-03-04 20:55:26: ERROR[Main]:       .../minetest-master/bin/../mods/petz/petz/brains/br_ant.lua:72: in function 'logic'
2023-03-04 20:55:26: ERROR[Main]:       ...inetest/minetest-master/bin/../mods/petz/kitz/engine.lua:819: in function 'stepfunc'
2023-03-04 20:55:26: ERROR[Main]:       ...inetest-master/bin/../mods/petz/petz/petz/ant_mobkit.lua:126: in function 'func'
2023-03-04 20:55:26: ERROR[Main]:       ...etest-master/bin/../builtin/profiler/instrumentation.lua:107: in function 'func'
2023-03-04 20:55:26: ERROR[Main]:       ...etest-master/bin/../builtin/profiler/instrumentation.lua:107: in function <...etest-master/bin/../builtin/profiler/instrumentation.lua:100>
Not much time and the next issue. For today i give up. Hope you are able to solve these. Thanks for your time.

Yours Gorm

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

[Mod] Offhand Items [offhand] [0.0.6]

by TestificateMods » Post

Gorm wrote:
Sat Mar 04, 2023 15:21
Looks weird. Thats due to my 16 slot hotbar.
I just pushed a new version. The HUD overlay will now adjust automatically based on your hotbar size.
You will need to empty your offhand once and then re-equip the item in order to reset it.
If for whatever reason the position still doesn't fit properly, you can use the new setting to adjust it.
Edit: I noticed that mods like dreambuilder_hotbar have a delay, causing my script to not detect this at startup. I now edited it to consistently check for changes. Emptying the offhand is thus not necessary.
If i place pkarcs they are now rotated by 90° around y. If i disable offhand they are placed as before. But if i place slopes they are placed as usual. So this time the issue is maybe related to pkarcs.
Honestly, no idea what might be causing this at this point in time. There might be some weirdness going on in that mod.
Lua: Runtime error from mod 'petz' in callback luaentity_Step()
Didn't test it yet with the petz mod but I have an idea what caused this and added an additional constraint to hopefully prevent this from happening again.

Bonus change: You can now use your offhand with the empty hand in addition to tools in your main hand.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

[Mod] Offhand Items [offhand] [0.0.8]

by TestificateMods » Post

Gorm wrote:
Sat Mar 04, 2023 15:21
One more issue arised. If i place pkarcs they are now rotated by 90° around y. If i disable offhand they are placed as before. But if i place slopes they are placed as usual. So this time the issue is maybe related to pkarcs. I look at it later.
I had another look and was able to sort out the issue. Turns out that I accidentally removed the param2 value.

Gorm
Member
Posts: 29
Joined: Tue Feb 14, 2023 17:06

Re: [Mod] Offhand Items [offhand] [0.0.8]

by Gorm » Post

Hello TestificateMods!

Uh your fast :-) Thank you very much for solving these issues.
During play yesterday evening that was the only thing missing.

Great work men!

Yours Gorm

QBSteve
Member
Posts: 19
Joined: Wed Mar 15, 2023 00:00
In-game: QBSteve

Re: [Mod] Offhand Items [offhand] [0.0.9]

by QBSteve » Post

The game crashes whenever I try to put a source block (like lava, not the bucket, the source block) into my offhand. I'll put the error on the fourm. Here's the error:

AsyncErr: Lua: Runtime error from mod 'offhand' in callback environment_Step(): ...ograms\minetest-5.6.1-win64\bin\..\mods\offhand\init.lua:59: attempt to concatenate a table value
stack traceback:
...ograms\minetest-5.6.1-win64\bin\..\mods\offhand\init.lua:59: in function 'build_inventory_icon'
...ograms\minetest-5.6.1-win64\bin\..\mods\offhand\init.lua:180: in function <...ograms\minetest-5.6.1-win64\bin\..\mods\offhand\init.lua:163>
...ms\minetest-5.6.1-win64\bin\..\builtin\game\register.lua:431: in function <...ms\minetest-5.6.1-win64\bin\..\builtin\game\register.lua:417>
Hello! I'm just some random person with an ancient 7 year old potato that is my laptop :)

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [0.0.10]

by TestificateMods » Post

QBSteve wrote:
Tue Mar 21, 2023 01:02
The game crashes whenever I try to put a source block (like lava, not the bucket, the source block) into my offhand.
Thanks for the report! I fixed it in the newest version.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [1.0.0]

by TestificateMods » Post

I just released a new update. This will allow you to trigger the on_secondary_use handler when right-clicking the air. This gives full functionality to all right-click handlers in your offhand.

I also patched a small bug that could potentially delete the itemstack.

QBSteve
Member
Posts: 19
Joined: Wed Mar 15, 2023 00:00
In-game: QBSteve

Re: [Mod] Offhand Items [offhand] [1.0.0]

by QBSteve » Post

This mod caused a error while I was playing. I checked debug.txt, but I didn't find much, except for the errors, and a lot of warnings for some of my other mods.
Here's what I was doing: I was playing Minetest Survival. I placed down a torch in a cave (from the offhand), then quickly swapped it for my ladders, combined a stack of 90-ish and 3 torches, then swapped again. That's when the texture bug happened. I equiped my stone pickaxe, then I saw this error: ERROR[Main]: generateImage(): Could not load image "(T@default)Stone PickaxeE" while building texture; Creating a dummy image
I have included a list of the mods I was using at the time.
Attachments
List of all the mods I was using (except worldedit)
List of all the mods I was using (except worldedit)
Screenshot 2023-03-22 192245.png (48.91 KiB) Viewed 3064 times
Hello! I'm just some random person with an ancient 7 year old potato that is my laptop :)

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [1.0.0]

by TestificateMods » Post

QBSteve wrote:
Thu Mar 23, 2023 01:24
This mod caused a error while I was playing. I checked debug.txt, but I didn't find much, except for the errors, and a lot of warnings for some of my other mods.
Here's what I was doing: I was playing Minetest Survival. I placed down a torch in a cave (from the offhand), then quickly swapped it for my ladders, combined a stack of 90-ish and 3 torches, then swapped again. That's when the texture bug happened. I equiped my stone pickaxe, then I saw this error: ERROR[Main]: generateImage(): Could not load image "(T@default)Stone PickaxeE" while building texture; Creating a dummy image
I have included a list of the mods I was using at the time.
Thanks for the report! I'm not sure what would cause this as I haven't had it happen to me yet.
It must, however, be part of the wield item that gets attached to the player model. If this issue bothers you, you can go into the settings and disable the "Show 3D model of held item" setting. At least until I figure out what might be the cause of it.

User avatar
TestificateMods
Member
Posts: 88
Joined: Sat Apr 11, 2020 02:09
GitHub: t-affeldt
In-game: Testificate

Re: [Mod] Offhand Items [offhand] [1.0.0]

by TestificateMods » Post

QBSteve wrote:
Thu Mar 23, 2023 01:24
This mod caused a error while I was playing.
I swapped out the code for the 3D item with that from visible_wielditem. I did some testing and it appears to be much more stable than before. This should also get rid of the bug you described.

QBSteve
Member
Posts: 19
Joined: Wed Mar 15, 2023 00:00
In-game: QBSteve

Re: [Mod] Offhand Items [offhand] [1.0.0]

by QBSteve » Post

TestificateMods wrote:
Sun Mar 26, 2023 20:14
QBSteve wrote:
Thu Mar 23, 2023 01:24
This mod caused a error while I was playing.
I swapped out the code for the 3D item with that from visible_wielditem. I did some testing and it appears to be much more stable than before. This should also get rid of the bug you described.
Thanks for the quick update. :) I'll report any new issues that appear (if there are any).
Hello! I'm just some random person with an ancient 7 year old potato that is my laptop :)

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests