[Mod] instafill [1.30] - create cuboids

Post Reply
User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

[Mod] instafill [1.30] - create cuboids

by bdjnk » Post

This is currently a work in progess. It does the right thing in single player.

A mod for Minetest which allows players to create a solid cube of a given type of node by placing two nodes of that type at opposite corners of the desired cube. This enables the easy creation of lines, planes, and rectagles of nodes.

Instafill is toggled by means of the "/f" command. Chat messages will let you know what state you're in.


Code license : GPLv2/later

Mod dependencies: default

Download link: 1.30

Github link: instafill source

Video demos: Changelog:

Code: Select all

1.30 - better safety (single player) and messaging
1.20 - supports creative mode properly + removed "env:" (requires >= 4.7)
1.10 - now pulls from multiple inventory stacks correctly
1.00 - feature complete, adds taking nodes from inventory only
0.91 - fix to ensure dug nodes no longer act as instafill corners
0.90 - initial release, missing taking nodes from inventory only
Last edited by bdjnk on Mon Sep 26, 2016 19:33, edited 4 times in total.

User avatar
Tedypig
Member
Posts: 286
Joined: Tue Mar 05, 2013 12:33
IRC: Piggybear87
In-game: Piggybear
Location: Largo, FL, USA

by Tedypig » Post

This would be useful to a creative only server. +0.5
01010100 01100101 01100100 01111001 01110000 01101001 01100111

User avatar
Traxie21
Member
Posts: 753
Joined: Mon Dec 31, 2012 10:48
Location: McKinney, Texas U.S.A.
Contact:

by Traxie21 » Post

It could also be useful for any server owner who wanted to rapidly build his server.

However, the WorldEdit mod has this and more.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

Changes in 1.0
Only nodes from your inventory are placed.


Hey Tedypig,
I was mostly thinking it was useful in the context of my creative, single-player environment. Still, with the latest changes it should be fine for stricter environments :)

Hey Traxie21,
Someone else also mentioned WorldEdit, but that is a tool outside of regular gameplay (and very complex). This is a simple tool to remove some of the tedium involved in larger scale building project.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

Okay, so 1.0 doesn't work perfectly. If I have several ItemStacks of the relevant node type in my inventory, only the one currently in hand gets used. I've been looking at the documentation and reading the forum, and I could use some help. Here is the relevant snippets of code where I attempt to handle the issue:

Code: Select all

        local inv = placer:get_inventory()
...
                        minetest.debug('before take   '..itemstack:to_string())
                        itemstack:take_item(1)
                        minetest.debug(' after take   '..itemstack:to_string())
                        if not itemstack:is_empty() then
                            minetest.env:add_node(npos, {name = pname})
                        elseif inv:contains_item("main", pname) then
                            minetest.debug('before remove '..itemstack:to_string())
                            itemstack = inv:remove_item("main", {name=pname, count=99})
                            minetest.debug(' after remove '..itemstack:to_string())
...
        minetest.debug('before add    '..itemstack:to_string())
        inv:add_item("main", itemstack)
        minetest.debug(' after add    '..itemstack:to_string())
Let's say I have four glass in my hand, and four elsewhere in my inventory. The output of placing those four in a shape requiring five nodes is as follows:

Code: Select all

before take   default:glass 3
 after take   default:glass 2
before take   default:glass 2
 after take   default:glass
before take   default:glass
 after take   
before remove 
 after remove default:glass 7
before add    default:glass 7
 after add    default:glass 7
Everything up to 'after remove' makes sense to me. Once we do 'after remove', I completely lose track. I've already placed four glass, so all I should have is four, unless the other nodes have been taken from the itemstack but remain in the inventory. And what about the failure to add the items back to the inventory. Indeed, the second stack of glass is gone from the inventory.

I must be reading the documentation badly, but I've even been delving into the source and I can't see where I'm going wrong. Any assistance is appreciated.

User avatar
prestidigitator
Member
Posts: 640
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

You asked the player's inventory to remove up to 99 items from its "main" list. Apparently it could only find 7 (I THINK this should try to find all "default:glass" stacks and pull from multiple if necessary, but you could try putting it in a loop until you either fill your whole request or get nothing back). Note that InvRef:add_item(...) isn't going to change the ItemStack you pass into it; instead it returns the leftovers (which would presumably be none in this case. So for your "after add" result to be different from your "before add" result, you'll need to do:

Code: Select all

itemstack = inv:add_item("main", itemstack)
EDIT: Oh. I see. Your other problem is that ItemStacks are NOT live objects. They are simply a structure used to keep track of a list of items. If you change an ItemStack you got back from an inventory (InvRef), the inventory is NOT changed. To change the inventory you have to send the changed ItemStack back to it somehow. So you have to do something with the ItemStack you originally called take_item() on in order to actually push that change back to the inventory. For example, if this was on the placer's wielded item list, you'd have to call:

Code: Select all

itemstack = placer:get_wielded_item()
...
itemstack.take_item(...)
...
placer:set_wielded_item(itemstack)
This seems to be a common mistake, so I've added notes about this in the dev. wiki articles for InvRef and ObjectRef.
Last edited by prestidigitator on Mon Mar 25, 2013 19:27, edited 1 time in total.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

Changes in 1.10 - Now pulls from multiple inventory stacks correctly.

Thanks prestidigitator!

I still think, even with the additional notes in the documentation, the concept is not so intuitive. My code now works, but I may have an excess of set_wielded_item() calls. If you're bored you can take a quick look and let me know if I'm doing things in a sensible way.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

Changes in 1.20 - Creative mode is now properly supported. I've also removed "env:" from all relevant calls, so instafill now requires minetest 4.7 or greater.

User avatar
mahmutelmas06
Member
Posts: 367
Joined: Mon Mar 02, 2015 13:10
GitHub: mahmutelmas06
IRC: mahmutelmas06
In-game: masum

Re: [Mod] instafill [1.20] - create cuboids (save time, buil

by mahmutelmas06 » Post

Amazing mod and still works well after all years :)
My Mods:

Beverage

User avatar
Joseph16
Member
Posts: 308
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph16

Re: [Mod] instafill [1.30] - create cuboids

by Joseph16 » Post

For some reason it duplicates all ores when you mine them. So this needs fixing.
EDIT: Wrong topic I did not mean to post this here
Testin' mines since 1989

Post Reply

Who is online

Users browsing this forum: Emojiminetest, Skamiz Kazzarch and 2 guests