Page 1 of 1

[Mod] Explorer Tools (place an item on right click) [explore

PostPosted: Sun Apr 13, 2014 15:34
by Kilarin
Explorer Tools Version 1.2
This mod adds a pick, axe, and shovel that not only dig on a left click, but will place whatever item is in the inventory slot immediately to their right on a right click.

Have you ever been frustrated when digging a mine or exploring a cavern because you have to dig, dig, dig, then swap the active inventory item to a torch, place a torch, swap the active inventory item back to your pick, and repeat? Did you ever wish that you could just place a torch (or a block of stone or glass) with a right click while still wielding your pick, axe, or shovel? If so, then this mod is for you!

The tools are based upon the diamond versions, and are crafted by replacing the top stick in the recipe with a mese crystal:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
diamond,   diamond   ,diamond        diamond,diamond              diamond
       ,mese fragment,               diamond,mese fragment      mese fragment
       ,   stick     ,                      ,stick                 stick

Image

These tools have the same stats as a diamond tool, with the exception that the uses has been increased by 10%. (to account for the extra expense of adding a mese crystal)
The tools work exactly like the base diamond version, EXCEPT that when wielding these tools, if you right click, it does a "place" using the item directly to the right in the players inventory. So, for example, if your inventory slots looked like this:

Image

Then a left click with the pick would dig, but point the pick at the wall and right click, and it will place a torch from your second inventory slot on the wall. No need to switch active inventory items at all. Left click to dig with the pick, right click to place a torch.

And it doesn't have to be a torch. Perhaps you are building a project that requires digging out stone and replacing it with glass. Just put your stack of glass in the inventory slot next to the explorer pick, dig the stone out with a left click, place the glass with a right click. The axe and the shovel work the same way.

Alternative mod:
There was a request that the explorertool place on rightclick function be added to every pick, axe, and shovel in the game. 4aiman implemented this in his magichet game, and kindly gave me permission to create an explorertoolsall mod based on his code. Download THAT version if you want ALL tools to be able to place an item on right click.

Possible future changes:
The textures, eh, not so great here. If someone gets inspired to suggest an improvement, I'm very open to it. I didn't create an explorer hoe, because there was not a diamond version of the hoe in the default game, but adding a hoe would be simple.
This is my first MineTest mod, and my first time ever programming in Lua, so any suggestions for improvements in the code are very welcome.

Credits:
My son helped me with the idea, the programming, and the textures. Thanks to kaeza for sample code of how to get the inventory item to the right of the tool, and to PilzAdam and Stu for answering my questions about how the uses field works. 4aiman for the change the code for Explorer Tools All.

Incompatibilities:
Do not use with Inventory Tweak mod, on right click your tool will disappear!

---For Explorer Tools: (use this one for special explorer tools)
Dependencies:
soft depends on default, but without default you have no recipe.

License: CC0

To browse source:
https://github.com/Kilarin/ExplorerTools

Download:
https://github.com/Kilarin/ExplorerTools/archive/master.zip

---For Explorer Tools All: (use this one to let all tools do a right click place)
Dependencies:
Soft depends on default. Add soft dependencies for any other tool mods you want this to affect.

License: gplv3

To browse source:
https://github.com/Kilarin/explorertoolsall

Download:
https://github.com/Kilarin/explorertoolsall/archive/master.zip

---

To install:
Simply unzip the file into your mods folder, and rename the folder to explorertools (Or explorertoolsall)
OR, simply install it directly from minetest using the online mod repository.

Mod Database:
If you use either of these mods, please consider reviewing it on the MineTest Mod Database.
https://forum.minetest.net/mmdb/mod/explorertools/
https://forum.minetest.net/mmdb/mod/explorertoolsall/

Change Log:
1.2 change from kaeza: Force-update stack instead of relying on success indicator.
This eliminates a problem where using explorertoolsall and an itemframe would
allow you to duplicate items. And, to my surprise, it does not seem to cause
you to lose items when you can't place the stack.
1.1 changed hard depends on default to soft
removed requirement that index pos of tool be less than 8
updated readme to include explorertoolsall referenc
1.0 initial release

PostPosted: Sun Apr 13, 2014 15:42
by rubenwardy
I like this!

You need to upload your file to somewhere. You are currently linking to a directory on your computer.

  • Upload it as a forum attachment
  • or Dropbox.com
  • or Add your mod to mod store and upload it there

PostPosted: Sun Apr 13, 2014 15:45
by Krock
Yup, try dropbox, mediafire or 2shared to upload your file. Else we can not download it.

PostPosted: Sun Apr 13, 2014 16:53
by Kilarin
Krock wrote:Yup, try dropbox, mediafire or 2shared to upload your file. Else we can not download it.

UGH!!!
Sorry, what a stupid mistake. I uploaded it to mediafire, tested the link, and then somehow I copied the wrong link into the post and didn't notice it. <sigh> Anyway, link corrected.

I'll look into putting it on modstore once a few people have tried it and confirmed everything is working ok.

PostPosted: Sun Apr 13, 2014 20:03
by Sokomine
Sounds simple but could be extremly useful. Nice idea! Hope it will be available for download soon (no, mediafire dosn't count as that does not work - a site that requires JavaScript for a mere download is broken by design). Please be so kind to add a forum attachment :-) Adding it to the minetest mod database would also be nice. I'm sure a lot of people will enjoy it!

PostPosted: Sun Apr 13, 2014 20:08
by Krock
Well I didn't say my opinion yet because it's not world-moving, it's just ... an useful function to put torches without needing to switch.
(Well scrolling the mouse wheel isn't a big thing too but I'm not used in it)

PostPosted: Sun Apr 13, 2014 20:57
by Kilarin
Krock wrote:Well I didn't say my opinion yet because it's not world-moving, it's just ... an useful function to put torches without needing to switch.

yep, pretty simple, but I didn't want to pick something really complicated for my first mod. :)

Sokomine wrote: Nice idea! Hope it will be available for download soon (no, mediafire dosn't count as that does not work - a site that requires JavaScript for a mere download is broken by design). Please be so kind to add a forum attachment :-) Adding it to the minetest mod database would also be nice.

I added it as an attachment, and I added it to the mod database:
https://forum.minetest.net/mmdb/mod/83/

PostPosted: Mon Apr 14, 2014 00:09
by Sokomine
Kilarin wrote:I added it as an attachment, and I added it to the mod database:

Thank you! Hope it gets installed on servers I build on.

PostPosted: Mon Apr 14, 2014 06:47
by 4aiman
Cool idea and so is mod!
I've just realized why there isn't smth like this in Minecraft - ppl use RMB to block :)

I've couple suggestions:
1. You could use player:get_inventory():get_width(player:get_wielded_list()) to find out width of a wield bar. Then compare idx with it instead of assuming that width = 8.

2. Could you redefine all tools that are registered before your mod loaded to use the same feature? I can help with that if you want :)

PostPosted: Mon Apr 14, 2014 08:08
by bajanhgk
Krock wrote:Well I didn't say my opinion yet because it's not world-moving, it's just ... an useful function to put torches without needing to switch.
(Well scrolling the mouse wheel isn't a big thing too but I'm not used in it)

Krock sometimes people use laptop and they don't use a mouse on there laptop like me
Edit: oh yah this a really useful mod for me

PostPosted: Mon Apr 14, 2014 08:22
by nman3600
Krock wrote:Well I didn't say my opinion yet because it's not world-moving, it's just ... an useful function to put torches without needing to switch.
(Well scrolling the mouse wheel isn't a big thing too but I'm not used in it)

*a useful*

PostPosted: Mon Apr 14, 2014 08:50
by Krock
nman3600 wrote:*a useful*

Do not correct my grammar fails, #grammarnazi.

Testing this mod now on my server, 100%of the players (2) like it already xD

PostPosted: Mon Apr 14, 2014 11:00
by nman3600
Krock wrote:
nman3600 wrote:*a useful*

Do not correct my grammar fails, #grammarnazi.

Testing this mod now on my server, 100%of the players (2) like it already xD


Lol im one of them #imagrammarnazi

PostPosted: Mon Apr 14, 2014 12:02
by Kilarin
4aiman wrote:You could use player:get_inventory():get_width(player:get_wielded_list()) to find out width of a wield bar. Then compare idx with it instead of assuming that width = 8.

That is a most excellent idea! Like I said, this is my first mod, so I didn't have any clue how to get the inventory list width. (Or think about the fact that a Mod might have changed it) Much to learn!

4aiman wrote:2. Could you redefine all tools that are registered before your mod loaded to use the same feature? I can help with that if you want :)

You mean, have this work for all tools, instead of just a particular pick/axe/shovel? I considered that, but was worried about making too big an impact on the game and also that overriding the right click behavior on some tools could cause problems (Such as the screwdriver) But my son had suggested this, making the argument that you do a lot of mining and cavern exploring before you've gotten down to the depth where you can get diamond and mese. Which I think is a valid point.

So, certainly, if you think this would be an improvement, I would welcome help in how to make the change.

Krock wrote:Testing this mod now on my server, 100%of the players (2) like it already xD

I'm glad both of you are finding it useful! Thank you for giving it a try.

PostPosted: Tue Apr 15, 2014 07:33
by 4aiman
Kilarin wrote:So, certainly, if you think this would be an improvement, I would welcome help in how to make the change.


I meant that on_place should be defined if only there is NO definition. So things like screwdriver shouldn't suffer.

To override a tool you'll need to:
(If you'll need extra details - feel free to ask via PM.)
1. Soft-depend on all mods that have tools. This is essential. You need all tools to be loaded prior to your mod.
2. You already have your function to place items, so this step is taken already :)
3. Add the following to the end of you init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    for cou,def in pairs(minetest.registered_tools) do
        if not def['on_place'] then
          minetest.override_item(def.name, {on_place = explorertools_place,})
        end
    end

Already tested and working!

PostPosted: Tue Apr 15, 2014 07:40
by Krock
4aiman wrote:Already tested and working!

Wooden pickaxes and pain sticks would have no difference with the explorer tools with this.
Explorer tools have to be special and unique.

EDIT: Also, your code would override all swords, do you want to place nodes with swords? I don't think so.

PostPosted: Tue Apr 15, 2014 09:00
by 4aiman
Krock wrote:pain sticks

Is it "plain" or there is a mod with sticks as weapon? I want such a thing.

Also sorry, I've tested this w/o if statement and my "works" was referring the piece with substitution.

Here's working version. Only axes, pics and shovels/spades.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    for cou,def in pairs(minetest.registered_tools) do
        if def.name:find('pick')
        or def.name:find('axe')
        or def.name:find('shovel')
        or def.name:find('spade')
        then
          minetest.override_item(def.name, {on_place = explorertools_place,})
        end
    end

PostPosted: Tue Apr 15, 2014 10:26
by bajanhgk
warning: do not use this mod with inventory twerk you lose your pick if you right click

PostPosted: Tue Apr 15, 2014 14:09
by Kilarin
4aiman wrote:Here's working version. Only axes, pics and shovels/spades.

Krock wrote:Explorer tools have to be special and unique.


Sounds like I should put two versions out there. One that works the way I set this one up, with explorer tools being a special item you create, and one using the fascinating code 4aiman has offered that changes the behavior of all pick/axe/shoves that don't have a on_place already defined. That way everyone can choose which way they want it to work for their game/server.

bajanhgk wrote:warning: do not use this mod with inventory twerk you lose your pick if you right click

Yikes! I updated the post to indicate that. Any idea WHY it does this? Or how I could fix it not to do that anymore?

PostPosted: Wed Apr 16, 2014 09:40
by 4aiman
Kilarin wrote: that don't have a on_place already defined

PM-ed you on this matter. on_place is always defined... Please, use the second piece of code.

Kilarin wrote:Sounds like I should put two versions out there.


If you want to keep 2 versions separately then you can create 2 different files for each one.
You can add a variable which would load "original_ver.lua" or "chnged_ver.lua" depending on it's state:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- change this to "true" if you want on_place called on right click for all tools:
local same_trick_for_all = false
if same_trick_for_all then
    dofile(minetest.get_modpath('explorertools').."/changed_ver.lua")
else
    dofile(minetest.get_modpath('explorertools').."/original_ver.lua")
end

Then place your old code in "original_ver.lua" file and changed into "changed_ver.lua".

But I'd recommend to wrap redefinition only within that " if " clause. So, It'll look like this (I'll shorten this):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- change this to "true" if you want on_place called on right click for all tools:
local same_trick_for_all = false


function explorertools_place(item, player, pointed)
...
end

if same_trick_for_all then
 ...
         minetest.override_item(def.name, {on_place = explorertools_place,})
 ...
else
---Explorer Pickaxe
minetest.register_craft({...})
minetest.register_tool("explorertools:pick_explorer", {...})


---Explorer Axe
minetest.register_craft({...})
minetest.register_tool("explorertools:axe_explorer", {...})

---Explorer Shovel
minetest.register_craft({...})
minetest.register_tool("explorertools:shovel_explorer", {...})
end


Inventory tweak is unstable by itself. Here we have a different story, but I lost like a dozen of different tools while breaking them.
It was like this:
- I dig a node;
- My pick breaks down;
- Client predicts server behaviour and removes the broken tool;
- Inventory tweak replaces it with a new one;
- Server thinks that I'm holding the tool that's supposed to break and removes it;
- My new tool is gone.

I don't know how it was in reality and what client-server communication occurs here, but every time there are lags this happens to me if I'm using inventory tweak.
---------------------

Please, provide us a link to the Inventory tweak you're using.

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Wed Jun 11, 2014 04:24
by Kilarin
Explorer Tools is now correctly uploaded to the MineTest Mod Database https://forum.minetest.net/mmdb/mod/explorertools/

This should make it easy to install directly from MineTest. If you use it and like it (or not), please feel free to rate/review it there.

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Wed Jun 18, 2014 03:10
by Kilarin
Version 1.1 of Explorer Tools is uploaded. No significant changes for the users here. I made the dependency on default soft instead of hard, and I removed the limit that the explorer tool had to be in an inventory slot less than 8.
Without that limit, the explorer tools should work correctly even if you have a mod that changes the inventory width. And if you put the explorer tool in the very last slot in your inventory, it will still work, it will just place the first item from the next line of inventory items. Which is intuitive.

The big change here isn't Explorer Tools, but the new mod ExplorerToolsAll. 4aiman wrote this code and gave me permission to use a slightly modified version of it here. The ExplorerToolsAll mod gives the "place on right click" ability to every pick, axe, and shovel in the game. So you don't have to create special tools, instead you can use any tool as an explorer tool. (Big thanks to 4aiman for this very clever and elegant code!)

I don't think this will mess up game balance in any way, since the "place on right click" ability doesn't actually increase your power in the game, it just saves you some keystrokes and possible carpel tunnel syndrome. :)

But, obviously, some people will prefer that the explorer tool function remain in only a special recipe tool, and those people should use the ExplorerTool mod. But if you want all tools to work that way, use Explorer Tools All.

To browse source:
https://github.com/Kilarin/explorertoolsall

Download:
https://github.com/Kilarin/explorertoolsall/archive/master.zip

Have fun, and let me know if you run into any problems.

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Sun Oct 12, 2014 23:37
by Kilarin
explorertools and explorertoolsall have been updated with a change from kaeza: Force-update stack instead of relying on success indicator. This eliminates a problem where using explorertoolsall and an itemframe would allow you to duplicate items.

original problem thread: https://github.com/VanessaE/homedecor_m ... issues/126
Pull: https://github.com/Kilarin/explorertoolsall/pull/1

And, to my surprise, it does not seem to cause you to lose items when you can't place the stack.

If anyone could explain to me why I don't need to check for success on placing before removing the item from the itemstack, I would be much obliged.

Thanks folks!

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Mon Oct 13, 2014 04:56
by Kilarin
and donat-b answered my question. DUH!
since the Engine doesn't decrement the stack unless the place was successful, the update always has the right count.

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Mon Dec 29, 2014 21:10
by MykieDoesStuff
So now what???
https://www.youtube.com/watch?v=_mD-zaCdbi4&feature=youtu.be

*Edit*

Ok so basically i got it all installed but how do I use it? Run it? Lol look like I'm a total newbie at installing mods :P

*EDIT*

Alright for some reason all the other mods seems to work now... not sure what went wrong ... however this kind of mods doesn't seems to work.

Re: [Mod] Explorer Tools (place an item on right click) [exp

PostPosted: Mon Dec 29, 2014 22:11
by Kilarin
aha! problem is simple for this one.
There are TWO mods in this thread. ExplorerTools which adds a new set of special tools with the ability to place items on a right click. And ExplorerToolsAll which gives the same ability to every pick, axe, and shovel in the game.
You downloaded ExplorerToolsAll.

To test it, take ANY pick, put it in an active inventory slot. Then put a stack of items (torches, stone, whatever) in the inventory slot immediately to the right of it. Now you can dig with a left click, and place with a right click.

To test the original version with it's own recipe (which is what I think will make more sense to you for learning lua) download the FIRST link https://github.com/Kilarin/ExplorerTools/archive/master.zip
and install it the same way (in the mod folder, then rename to remove the -master)

Once you get the mod working, I'll be happy to answer any questions you have about the code, it's pretty simple.