mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-06-29 22:50:46 +02:00
Compare commits
250 Commits
Author | SHA1 | Date | |
---|---|---|---|
2f26fb7645 | |||
f1b6da3c20 | |||
418a30c89e | |||
2f535dd053 | |||
867cd6edc7 | |||
4918610c43 | |||
edd27636a6 | |||
7d0811fd47 | |||
4d08a1cc55 | |||
34844b2d38 | |||
0f5dcc790d | |||
37de177f72 | |||
f285a55dd5 | |||
9b26034aea | |||
963a9f6b96 | |||
5e8bfd5166 | |||
06a3b63578 | |||
5e47af8773 | |||
da51c688d2 | |||
ab93871877 | |||
116ae25ebd | |||
18444379a1 | |||
974dcaa918 | |||
abdecd4239 | |||
9c38b9f6ad | |||
7833b68c85 | |||
03bef18272 | |||
91d02f6f5b | |||
8feaf8a21d | |||
5bab991e0b | |||
9bb0ad0442 | |||
63a7069671 | |||
79097dc6c8 | |||
3bc7a0f97d | |||
45acf09e4a | |||
adab528f8a | |||
26b6682587 | |||
b4826aa821 | |||
a0181ea897 | |||
2a4aaae8a2 | |||
f6298d7b87 | |||
68f7bcc728 | |||
0919f7cab3 | |||
de566d2e3e | |||
cc897150f2 | |||
f39a8e264d | |||
da5abec273 | |||
ff53a71d58 | |||
0edcd1a59d | |||
a1b6a34e61 | |||
f589c988b1 | |||
f28d9b8d35 | |||
b8453a0e0b | |||
0a16f11d93 | |||
b50294d10c | |||
324eb556f6 | |||
3ffecdd9c4 | |||
40b49ee9bc | |||
4f2c7b18cc | |||
b2e086f9ec | |||
d1cbd420bb | |||
0aeee79af6 | |||
f242f2f722 | |||
f8e57559ec | |||
b2b2b9364d | |||
b37605943b | |||
f7256633c0 | |||
99fa0ebd75 | |||
a97cccd2a1 | |||
3322ef90c4 | |||
b259906fd0 | |||
12270dc094 | |||
415000e797 | |||
7b1deb1b61 | |||
4605596215 | |||
59dc2d34d9 | |||
283f47f10d | |||
35ad2f031d | |||
d572d769ce | |||
5bbb6b3909 | |||
d6a9b517b5 | |||
3c61759bae | |||
2f4eb19a3a | |||
2cb3fcde66 | |||
e680d8087e | |||
870873ad15 | |||
e356f4521c | |||
bf8e2a8233 | |||
6ceb56c3dc | |||
1fabe60d77 | |||
acc9188828 | |||
3240167b13 | |||
66b1fa032d | |||
a31f955fb1 | |||
38e9b42caf | |||
ea465f8fe4 | |||
0ce45a5900 | |||
56f77a2f27 | |||
610cd9981d | |||
c0f3bb6958 | |||
e49f717000 | |||
6e7b9a60be | |||
bcac45a476 | |||
426f3b949f | |||
78e4ba828e | |||
92fe95fab7 | |||
3a7fb5bf1e | |||
aa0e46d4e2 | |||
83288c969e | |||
f9311b2b15 | |||
15f0cea72e | |||
6e2e2385e9 | |||
152707a322 | |||
d040d324e8 | |||
df6b54d2f5 | |||
5abe1cee3d | |||
5afea424ba | |||
2aed498849 | |||
0b68b2aec6 | |||
f72abdb766 | |||
e18525d8c9 | |||
78890dde07 | |||
b922097e7a | |||
48f3f59fc3 | |||
f8f1f3b9cc | |||
d5e004be67 | |||
fad021d0ba | |||
f1fe0c6bba | |||
40cee99700 | |||
04d20de4cd | |||
859c6bd12a | |||
240380ff16 | |||
8d213d32a0 | |||
ae29a9f064 | |||
6cf8b92434 | |||
0b97a7c740 | |||
900b2f25aa | |||
f49663902c | |||
d475682d8f | |||
9e087ff995 | |||
b23e92921c | |||
61ab240cea | |||
b06e004d80 | |||
6dddc93ed7 | |||
b99a51f468 | |||
91c5053e67 | |||
f2f714c19e | |||
47712844a3 | |||
2bd4d6fa8f | |||
e9e8de385c | |||
2e2fcfdfa2 | |||
e0a2661700 | |||
7a19c5303b | |||
35b68c481b | |||
51158eca9f | |||
3aa315f134 | |||
3d30588a68 | |||
48f9c6c23f | |||
5f9efb1205 | |||
fc037e9c82 | |||
90d6b3d237 | |||
4bd5d56909 | |||
163dffccb3 | |||
6b2fe397e6 | |||
5c115e282c | |||
ab47385f7b | |||
78915d4a54 | |||
09de34aabf | |||
c1bd4986b0 | |||
bea38a116a | |||
4336e7ca14 | |||
eca54f0851 | |||
b0fbcf197f | |||
b468e24a20 | |||
bb8456b711 | |||
1f277147ca | |||
04fdf92aca | |||
7f580611f5 | |||
4799068551 | |||
5b03c83f6b | |||
e4d007199f | |||
fb49cc4bcc | |||
eb88bf6ade | |||
02c36c16d5 | |||
796aa3870d | |||
1024eace6f | |||
70c24c9501 | |||
18efe50e1e | |||
44c9576f8a | |||
e383e8ce00 | |||
82ef580fae | |||
38fbc0a046 | |||
4b178bf709 | |||
d8aa7e72a7 | |||
58d7a7134e | |||
420655bd94 | |||
ea84eee0e5 | |||
9ec1a799d8 | |||
f5b67c5bc2 | |||
6084db9335 | |||
b70fd16da4 | |||
9616c7d944 | |||
175ac211ca | |||
b32aadd7fa | |||
c22b556511 | |||
174416b010 | |||
2c4a791805 | |||
4660927ca0 | |||
2784a25561 | |||
b29523db4d | |||
0dddffa544 | |||
b8b8db42bf | |||
18417ff4fd | |||
84f0e23d6c | |||
be913e6d8b | |||
82f39460cc | |||
6b50025ccc | |||
829f9eef73 | |||
f8d3614a32 | |||
86d35e97bf | |||
277b57a82a | |||
d2635544c6 | |||
2ac049c823 | |||
d73b93d8dd | |||
8c0b61194c | |||
2e41f0076d | |||
2fcea5a3c0 | |||
df6ab06e74 | |||
4e78ced693 | |||
ad299cacc5 | |||
06cb2934b1 | |||
c48cf3c051 | |||
674d6473e4 | |||
3767ea84d2 | |||
36424e3dec | |||
3cffae4948 | |||
a4881225a4 | |||
0797c47afb | |||
89d4548595 | |||
6c03ab9c4a | |||
dbc2348014 | |||
3fa9dfd19c | |||
d4b39cba9b | |||
ac7430e02f | |||
b3ba6f2433 | |||
d5ec1bcefc | |||
203c3da2af | |||
272541c9da | |||
9ab52df56a | |||
4c43bf3600 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*~
|
||||
|
332
Chat Commands.md
332
Chat Commands.md
@ -1,332 +0,0 @@
|
||||
Chat Commands
|
||||
-------------
|
||||
For more information, see the [README](README.md).
|
||||
|
||||
### //inspect
|
||||
|
||||
Enable or disable node inspection.
|
||||
|
||||
//inspect on
|
||||
//inspect off
|
||||
//inspect 1
|
||||
//inspect 0
|
||||
//inspect true
|
||||
//inspect false
|
||||
//inspect yes
|
||||
//inspect no
|
||||
//inspect enable
|
||||
//inspect disable
|
||||
|
||||
### //reset
|
||||
|
||||
Reset the region so that it is empty.
|
||||
|
||||
//reset
|
||||
|
||||
### //mark
|
||||
|
||||
Show markers at the region positions.
|
||||
|
||||
//mark
|
||||
|
||||
### //unmark
|
||||
|
||||
Hide markers if currently shown.
|
||||
|
||||
//unmark
|
||||
|
||||
### //pos1
|
||||
|
||||
Set WorldEdit region position 1 to the player's location.
|
||||
|
||||
//pos1
|
||||
|
||||
### //pos2
|
||||
|
||||
Set WorldEdit region position 2 to the player's location.
|
||||
|
||||
//pos2
|
||||
|
||||
### //p set/set1/set2/get
|
||||
|
||||
Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region.
|
||||
|
||||
//p set
|
||||
//p set1
|
||||
//p set2
|
||||
//p get
|
||||
|
||||
### //fixedpos set1 x y z
|
||||
|
||||
Set a WorldEdit region position to the position at (<x>, <y>, <z>).
|
||||
|
||||
//fixedpos set1 0, 0, 0
|
||||
//fixedpos set1 -30, 5, 28
|
||||
//fixedpos set2 1004, -200, 432
|
||||
|
||||
### //volume
|
||||
|
||||
Display the volume of the current WorldEdit region.
|
||||
|
||||
//volume
|
||||
|
||||
### //set <node>
|
||||
|
||||
Set the current WorldEdit region to <node>.
|
||||
|
||||
//set air
|
||||
//set cactus
|
||||
//set Bronze Block
|
||||
//set mesecons:wire_00000000_off
|
||||
|
||||
### //replace <search node> <replace node>
|
||||
|
||||
Replace all instances of <search node> with <replace node> in the current WorldEdit region.
|
||||
|
||||
//replace Cobblestone air
|
||||
//replace lightstone_blue glass
|
||||
//replace dirt Bronze Block
|
||||
//replace mesecons:wire_00000000_off flowers:flower_tulip
|
||||
|
||||
### //replaceinverse <search node> <replace node>
|
||||
|
||||
Replace all nodes other than <search node> with <replace node> in the current WorldEdit region.
|
||||
|
||||
//replaceinverse Cobblestone air
|
||||
//replaceinverse flowers:flower_waterlily glass
|
||||
//replaceinverse dirt Bronze Block
|
||||
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip
|
||||
|
||||
### //hollowsphere <radius> <node>
|
||||
|
||||
Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>.
|
||||
|
||||
//hollowsphere 5 Diamond Block
|
||||
//hollowsphere 12 glass
|
||||
//hollowsphere 17 mesecons:wire_00000000_off
|
||||
|
||||
### //sphere <radius> <node>
|
||||
|
||||
Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>.
|
||||
|
||||
//sphere 5 Diamond Block
|
||||
//sphere 12 glass
|
||||
//sphere 17 mesecons:wire_00000000_off
|
||||
|
||||
### //hollowdome <radius> <node>
|
||||
|
||||
Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.
|
||||
|
||||
//hollowdome 5 Diamond Block
|
||||
//hollowdome -12 glass
|
||||
//hollowdome 17 mesecons:wire_00000000_off
|
||||
|
||||
### //dome <radius> <node>
|
||||
|
||||
Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.
|
||||
|
||||
//dome 5 Diamond Block
|
||||
//dome -12 glass
|
||||
//dome 17 mesecons:wire_00000000_off
|
||||
|
||||
### //hollowcylinder x/y/z/? <length> <radius> <node>
|
||||
|
||||
Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
|
||||
|
||||
//hollowcylinder x +5 8 Bronze Block
|
||||
//hollowcylinder y 28 10 glass
|
||||
//hollowcylinder z -12 3 mesecons:wire_00000000_off
|
||||
//hollowcylinder ? 2 4 default:stone
|
||||
|
||||
### //cylinder x/y/z/? <length> <radius> <node>
|
||||
|
||||
Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
|
||||
|
||||
//cylinder x +5 8 Bronze Block
|
||||
//cylinder y 28 10 glass
|
||||
//cylinder z -12 3 mesecons:wire_00000000_off
|
||||
//cylinder ? 2 4 default:stone
|
||||
|
||||
### //pyramid x/y/z? <height> <node>
|
||||
|
||||
Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>.
|
||||
|
||||
//pyramid x 8 Diamond Block
|
||||
//pyramid y -5 glass
|
||||
//pyramid z 2 mesecons:wire_00000000_off
|
||||
//pyramid ? 12 mesecons:wire_00000000_off
|
||||
|
||||
### //spiral <length> <height> <spacer> <node>
|
||||
|
||||
Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <spacer>, composed of <node>.
|
||||
|
||||
//spiral 20 5 3 Diamond Block
|
||||
//spiral 5 2 1 glass
|
||||
//spiral 7 1 5 mesecons:wire_00000000_off
|
||||
|
||||
### //copy x/y/z/? <amount>
|
||||
|
||||
Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes.
|
||||
|
||||
//copy x 15
|
||||
//copy y -7
|
||||
//copy z +4
|
||||
//copy ? 8
|
||||
|
||||
### //move x/y/z/? <amount>
|
||||
|
||||
Move the current WorldEdit positions and region along the x/y/z/? axis by <amount> nodes.
|
||||
|
||||
//move x 15
|
||||
//move y -7
|
||||
//move z +4
|
||||
//move ? -1
|
||||
|
||||
### //stack x/y/z/? <count>
|
||||
|
||||
Stack the current WorldEdit region along the x/y/z/? axis <count> times.
|
||||
|
||||
//stack x 3
|
||||
//stack y -1
|
||||
//stack z +5
|
||||
//stack ? 12
|
||||
|
||||
### //scale <factor>
|
||||
|
||||
Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin.
|
||||
|
||||
//scale 2
|
||||
//scale 1
|
||||
//scale 10
|
||||
|
||||
### //transpose x/y/z/? x/y/z/?
|
||||
|
||||
Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.
|
||||
|
||||
//transpose x y
|
||||
//transpose x z
|
||||
//transpose y z
|
||||
//transpose ? y
|
||||
|
||||
### //flip x/y/z/?
|
||||
|
||||
Flip the current WorldEdit region along the x/y/z/? axis.
|
||||
|
||||
//flip x
|
||||
//flip y
|
||||
//flip z
|
||||
//flip ?
|
||||
|
||||
### //rotate x/y/z/? <angle>
|
||||
|
||||
Rotate the current WorldEdit positions and region along the x/y/z/? axis by angle <angle> (90 degree increment).
|
||||
|
||||
//rotate x 90
|
||||
//rotate y 180
|
||||
//rotate z 270
|
||||
//rotate ? -90
|
||||
|
||||
### //orient <angle>
|
||||
|
||||
Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)
|
||||
|
||||
//orient 90
|
||||
//orient 180
|
||||
//orient 270
|
||||
//orient -90
|
||||
|
||||
### //fixlight
|
||||
|
||||
Fixes the lighting in the current WorldEdit region.
|
||||
|
||||
//fixlight
|
||||
|
||||
### //hide
|
||||
|
||||
Hide all nodes in the current WorldEdit region non-destructively.
|
||||
|
||||
//hide
|
||||
|
||||
### //suppress <node>
|
||||
|
||||
Suppress all <node> in the current WorldEdit region non-destructively.
|
||||
|
||||
//suppress Diamond Block
|
||||
//suppress glass
|
||||
//suppress mesecons:wire_00000000_off
|
||||
|
||||
### //highlight <node>
|
||||
|
||||
Highlight <node> in the current WorldEdit region by hiding everything else non-destructively.
|
||||
|
||||
//highlight Diamond Block
|
||||
//highlight glass
|
||||
//highlight mesecons:wire_00000000_off
|
||||
|
||||
### //restore
|
||||
|
||||
Restores nodes hidden with WorldEdit in the current WorldEdit region.
|
||||
|
||||
//restore
|
||||
|
||||
### //save <file>
|
||||
|
||||
Save the current WorldEdit region to "(world folder)/schems/<file>.we".
|
||||
|
||||
//save some random filename
|
||||
//save huge_base
|
||||
|
||||
### //allocate <file>
|
||||
|
||||
Set the region defined by nodes from "(world folder)/schems/<file>.we" as the current WorldEdit region.
|
||||
|
||||
//allocate some random filename
|
||||
//allocate huge_base
|
||||
|
||||
### //load <file>
|
||||
|
||||
Load nodes from "(world folder)/schems/<file>.we" with position 1 of the current WorldEdit region as the origin.
|
||||
|
||||
//load some random filename
|
||||
//load huge_base
|
||||
|
||||
### //lua <code>
|
||||
|
||||
Executes <code> as a Lua chunk in the global namespace.
|
||||
|
||||
//lua worldedit.pos1["singleplayer"] = {x=0, y=0, z=0}
|
||||
//lua worldedit.rotate(worldedit.pos1["singleplayer"], worldedit.pos2["singleplayer"], "y", 90)
|
||||
|
||||
### //luatransform <code>
|
||||
|
||||
Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region.
|
||||
|
||||
//luatransform minetest.add_node(pos, {name="default:stone"})
|
||||
//luatransform if minetest.get_node(pos).name == "air" then minetest.add_node(pos, {name="default:water_source"})
|
||||
|
||||
### //mtschemcreate <file>
|
||||
|
||||
Save the current WorldEdit region using the Minetest Schematic format to "(world folder)/schems/<file>.mts".
|
||||
|
||||
//mtschemcreate some random filename
|
||||
//mtschemcreate huge_base
|
||||
|
||||
### //mtschemplace <file>
|
||||
|
||||
Load nodes from "(world folder)/schems/<file>.mts" with position 1 of the current WorldEdit region as the origin.
|
||||
|
||||
//mtschemplace some random filename
|
||||
//mtschemplace huge_base
|
||||
|
||||
### //mtschemprob start/finish/get
|
||||
|
||||
After using //mtschemprob start all nodes punched will bring up a text field where a probablity can be entered.
|
||||
This mode can be left with //mtschemprob finish. //mtschemprob get will display the probabilities saved for the nodes.
|
||||
|
||||
//mtschemprob get
|
||||
|
||||
### //clearobjects
|
||||
|
||||
Clears all objects within the WorldEdit region.
|
||||
|
||||
//clearobjects
|
508
ChatCommands.md
Normal file
508
ChatCommands.md
Normal file
@ -0,0 +1,508 @@
|
||||
Chat Commands
|
||||
-------------
|
||||
For more information, see the [README](README.md).
|
||||
|
||||
Many commands also have shorter names that can be typed faster. For example, if we wanted to use `//move ? 5`, we could instead type `//m ? 5`. All shortened names are listed below:
|
||||
|
||||
| Short Name | Original Name |
|
||||
|:-----------|:-------------------|
|
||||
| `//i` | `//inspect` |
|
||||
| `//rst` | `//reset` |
|
||||
| `//mk` | `//mark` |
|
||||
| `//umk` | `//unmark` |
|
||||
| `//1` | `//pos1` |
|
||||
| `//2` | `//pos2` |
|
||||
| `//fp` | `//fixedpos` |
|
||||
| `//v` | `//volume` |
|
||||
| `//s` | `//set` |
|
||||
| `//r` | `//replace` |
|
||||
| `//ri` | `//replaceinverse` |
|
||||
| `//hcube` | `//hollowcube` |
|
||||
| `//hspr` | `//hollowsphere` |
|
||||
| `//spr` | `//sphere` |
|
||||
| `//hdo` | `//hollowdome` |
|
||||
| `//do` | `//dome` |
|
||||
| `//hcyl` | `//hollowcylinder` |
|
||||
| `//cyl` | `//cylinder` |
|
||||
| `//hpyr` | `//hollowpyramid` |
|
||||
| `//pyr` | `//pyramid` |
|
||||
|
||||
### `//about`
|
||||
|
||||
Get information about the WorldEdit mod.
|
||||
|
||||
//about
|
||||
|
||||
### `//help [all/<cmd>]`
|
||||
|
||||
Get help for WorldEdit commands. `all` shows all WorldEdit commands, `<cmd>`
|
||||
the help text for the given command.
|
||||
|
||||
//help
|
||||
//help all
|
||||
//help hollowpyramid
|
||||
|
||||
|
||||
### `//inspect [on/off/1/0/true/false/yes/no/enable/disable]`
|
||||
|
||||
Enable or disable node inspection.
|
||||
|
||||
//inspect on
|
||||
//inspect off
|
||||
//inspect
|
||||
|
||||
### `//reset`
|
||||
|
||||
Reset the region so that it is empty.
|
||||
|
||||
//reset
|
||||
|
||||
### `//mark`
|
||||
|
||||
Show markers at the region positions.
|
||||
|
||||
//mark
|
||||
|
||||
### `//unmark`
|
||||
|
||||
Hide markers if currently shown.
|
||||
|
||||
//unmark
|
||||
|
||||
### `//pos1`
|
||||
|
||||
Set WorldEdit region position 1 to the player's location.
|
||||
|
||||
//pos1
|
||||
|
||||
### `//pos2`
|
||||
|
||||
Set WorldEdit region position 2 to the player's location.
|
||||
|
||||
//pos2
|
||||
|
||||
### `//p set/set1/set2/get`
|
||||
|
||||
Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by
|
||||
punching nodes, or print the current WorldEdit region.
|
||||
|
||||
//p set
|
||||
//p set1
|
||||
//p set2
|
||||
//p get
|
||||
|
||||
### `//fixedpos set1/set2 <x> <y> <z>`
|
||||
|
||||
Set the WorldEdit region position 1 or 2 to the position (`<x>`, `<y>`, `<z>`).
|
||||
|
||||
//fixedpos set1 0 0 0
|
||||
//fixedpos set1 -30 5 28
|
||||
//fixedpos set2 1004 -200 432
|
||||
|
||||
### `//volume`
|
||||
|
||||
Display the volume of the current WorldEdit region.
|
||||
|
||||
//volume
|
||||
|
||||
### `//deleteblocks`
|
||||
|
||||
Delete the MapBlocks (16x16x16 units) that contain the selected region. This means that mapgen will be invoked for that area. As only whole MapBlocks get removed, the deleted area is usually larger than the selected one. Also, mapgen can trigger mechanisms like mud reflow or cavegen, which affects nodes (up to 112 nodes away) outside the MapBlock, so dont use this near buildings. Note that active entities are not part of a MapBlock and do not get deleted.
|
||||
|
||||
//deleteblocks
|
||||
|
||||
### `//set <node>`
|
||||
|
||||
Set the current WorldEdit region to `<node>`.
|
||||
|
||||
//set air
|
||||
//set cactus
|
||||
//set Blue Lightstone
|
||||
//set dirt with grass
|
||||
|
||||
### `//param2 <param2>`
|
||||
|
||||
Set the param2 value of all nodes in the current WorldEdit region to `<param2>`.
|
||||
|
||||
//param2 8
|
||||
|
||||
### `//mix <node1> [count1] <node2> [count2] ...`
|
||||
|
||||
Fill the current WorldEdit region with a random mix of `<node1>`, `<node2>`, `...`.
|
||||
Weightings can be optionally specified via the `[count1]`, `[count2]`, `...` parameters after a node name.
|
||||
|
||||
//mix air
|
||||
//mix cactus stone glass sandstone
|
||||
//mix Bronze
|
||||
//mix default:cobble air
|
||||
//mix stone 3 dirt 2
|
||||
//mix cobblestone 8 stoneblock 2 stonebrick
|
||||
|
||||
### `//replace <search node> <replace node>`
|
||||
|
||||
Replace all instances of `<search node>` with `<replace node>` in the current WorldEdit region.
|
||||
|
||||
//replace Cobblestone air
|
||||
//replace lightstone_blue glass
|
||||
//replace dirt Bronze Block
|
||||
//replace mesecons:wire_00000000_off flowers:flower_tulip
|
||||
|
||||
### `//replaceinverse <search node> <replace node>`
|
||||
|
||||
Replace all nodes other than `<search node>` with `<replace node>` in the current WorldEdit region.
|
||||
|
||||
//replaceinverse Cobblestone air
|
||||
//replaceinverse flowers:flower_waterlily glass
|
||||
//replaceinverse dirt Bronze Block
|
||||
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip
|
||||
|
||||
### `//hollowcube <width> <height> <length> <node>`
|
||||
|
||||
Adds a hollow cube with its ground level centered at WorldEdit position 1 with
|
||||
dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.
|
||||
|
||||
//hollowcube 6 5 6 Diamond Block
|
||||
|
||||
### `//cube <width> <height> <length> <node>`
|
||||
|
||||
Adds a cube with its ground level centered at WorldEdit position 1 with
|
||||
dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.
|
||||
|
||||
//cube 6 5 6 Diamond Block
|
||||
//cube 7 2 1 default:cobble
|
||||
|
||||
### `//hollowsphere <radius> <node>`
|
||||
|
||||
Add hollow sphere centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
||||
|
||||
//hollowsphere 5 Diamond Block
|
||||
//hollowsphere 12 glass
|
||||
//hollowsphere 17 mesecons:wire_00000000_off
|
||||
|
||||
### `//sphere <radius> <node>`
|
||||
|
||||
Add sphere centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
||||
|
||||
//sphere 5 Diamond Block
|
||||
//sphere 12 glass
|
||||
//sphere 17 mesecons:wire_00000000_off
|
||||
|
||||
### `//hollowdome <radius> <node>`
|
||||
|
||||
Add hollow dome centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
||||
|
||||
//hollowdome 5 Diamond Block
|
||||
//hollowdome -12 glass
|
||||
//hollowdome 17 mesecons:wire_00000000_off
|
||||
|
||||
### `//dome <radius> <node>`
|
||||
|
||||
Add dome centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
||||
|
||||
//dome 5 Diamond Block
|
||||
//dome -12 glass
|
||||
//dome 17 mesecons:wire_00000000_off
|
||||
|
||||
### `//hollowcylinder x/y/z/? <length> <radius1> [radius2] <node>`
|
||||
|
||||
Add hollow cylinder at WorldEdit position 1 along the given axis with length `<length>`,
|
||||
base radius `<radius1>` (and top radius `[radius2]`), composed of `<node>`.
|
||||
|
||||
Despite its name this command allows you to create cones (`radius2` = 0) as well as any shapes inbetween (0 < `radius2` < `radius1`).
|
||||
Swapping `radius1` and `radius2` will create the same object but upside-down.
|
||||
|
||||
//hollowcylinder x +5 8 Bronze Block
|
||||
//hollowcylinder y 28 10 glass
|
||||
//hollowcylinder z -12 3 mesecons:wire_00000000_off
|
||||
//hollowcylinder ? 2 4 default:stone
|
||||
|
||||
//hollowcylinder y 10 10 0 walls:cobble
|
||||
//hollowcylinder x 6 0 5 Dirt
|
||||
//hollowcylinder z 20 10 20 default:desert_stone
|
||||
|
||||
### `//cylinder x/y/z/? <length> <radius1> [radius2] <node>`
|
||||
|
||||
Add cylinder at WorldEdit position 1 along the given axis with length `<length>`,
|
||||
base radius `<radius1>` (and top radius `[radius2]`), composed of `<node>`.
|
||||
Can also create shapes other than cylinders, e.g. cones (see documentation above).
|
||||
|
||||
//cylinder x +5 8 Bronze Block
|
||||
//cylinder y 28 10 glass
|
||||
//cylinder z -12 3 mesecons:wire_00000000_off
|
||||
//cylinder ? 2 4 default:stone
|
||||
|
||||
//cylinder y 10 10 0 walls:cobble
|
||||
//cylinder x 6 0 5 Dirt
|
||||
//cylinder z 20 10 20 default:desert_stone
|
||||
|
||||
### `//hollowpyramid x/y/z/? <height> <node>`
|
||||
|
||||
Add hollow pyramid centered at WorldEdit position 1 along the given axis with height `<height>` composed of `<node>`.
|
||||
|
||||
//hollowpyramid x 8 Diamond Block
|
||||
//hollowpyramid y -5 glass
|
||||
//hollowpyramid z 2 mesecons:wire_00000000_off
|
||||
//hollowpyramid ? 12 mesecons:wire_00000000_off
|
||||
|
||||
### `//pyramid x/y/z/? <height> <node>`
|
||||
|
||||
Add pyramid centered at WorldEdit position 1 along the given axis with height `<height>` composed of `<node>`.
|
||||
|
||||
//pyramid x 8 Diamond Block
|
||||
//pyramid y -5 glass
|
||||
//pyramid z 2 mesecons:wire_00000000_off
|
||||
//pyramid ? 12 mesecons:wire_00000000_off
|
||||
|
||||
### `//spiral <length> <height> <spacer> <node>`
|
||||
|
||||
Add spiral centered at WorldEdit position 1 with side length `<length>`,
|
||||
height `<height>`, space between walls `<spacer>`, composed of `<node>`.
|
||||
|
||||
//spiral 20 5 3 Diamond Block
|
||||
//spiral 5 2 1 glass
|
||||
//spiral 7 1 5 mesecons:wire_00000000_off
|
||||
|
||||
### `//copy x/y/z/? <amount>`
|
||||
|
||||
Copy the current WorldEdit region along the given axis by `<amount>` nodes.
|
||||
|
||||
//copy x 15
|
||||
//copy y -7
|
||||
//copy z +4
|
||||
//copy ? 8
|
||||
|
||||
### `//move x/y/z/? <amount>`
|
||||
|
||||
Move the current WorldEdit positions and region along the given axis by `<amount>` nodes.
|
||||
|
||||
//move x 15
|
||||
//move y -7
|
||||
//move z +4
|
||||
//move ? -1
|
||||
|
||||
### `//stack x/y/z/? <count>`
|
||||
|
||||
Stack the current WorldEdit region along the given axis `<count>` times.
|
||||
|
||||
//stack x 3
|
||||
//stack y -1
|
||||
//stack z +5
|
||||
//stack ? 12
|
||||
|
||||
### `//stack2 <count> <x> <y> <z>`
|
||||
|
||||
Stack the current WorldEdit region `<count>` times by offset `<x>`, `<y>`, `<z>`.
|
||||
|
||||
//stack2 5 3 8 2
|
||||
//stack2 1 -1 -1 -1
|
||||
|
||||
### `//stretch <stretchx> <stretchy> <stretchz>`
|
||||
|
||||
Scale the current WorldEdit positions and region by a factor of
|
||||
`<stretchx>`, `<stretchy>`, `<stretchz>` along the X, Y, and Z axes,
|
||||
respectively, with position 1 as the origin.
|
||||
|
||||
//stretch 2 2 2
|
||||
//stretch 1 2 1
|
||||
//stretch 10 20 1
|
||||
|
||||
### `//transpose x/y/z/? x/y/z/?`
|
||||
|
||||
Transpose the current WorldEdit positions and region along given axes.
|
||||
|
||||
//transpose x y
|
||||
//transpose y z
|
||||
//transpose ? y
|
||||
|
||||
### `//flip x/y/z/?`
|
||||
|
||||
Flip the current WorldEdit region along the given axis.
|
||||
|
||||
//flip x
|
||||
//flip ?
|
||||
|
||||
### `//rotate x/y/z/? <angle>`
|
||||
|
||||
Rotate the current WorldEdit positions and region along the given axis by angle `<angle>` (90 degree increment).
|
||||
|
||||
//rotate x 90
|
||||
//rotate y 180
|
||||
//rotate z 270
|
||||
//rotate ? -90
|
||||
|
||||
### `//orient <angle>`
|
||||
|
||||
Rotate oriented nodes in the current WorldEdit region around the Y axis by angle `<angle>` (90 degree increment)
|
||||
|
||||
//orient 90
|
||||
//orient 180
|
||||
//orient 270
|
||||
//orient -90
|
||||
|
||||
### `//fixlight`
|
||||
|
||||
Fixes the lighting in the current WorldEdit region.
|
||||
|
||||
//fixlight
|
||||
|
||||
### `//drain`
|
||||
|
||||
Removes any fluid node within the current WorldEdit region.
|
||||
|
||||
//drain
|
||||
|
||||
### `//clearcut`
|
||||
|
||||
Removes any plant, tree or foilage-like nodes in the selected region.
|
||||
The idea is to remove anything that isn't part of the terrain, leaving a "natural" empty space ready for building.
|
||||
|
||||
//clearcut
|
||||
|
||||
### `//hide`
|
||||
|
||||
Hide all nodes in the current WorldEdit region non-destructively.
|
||||
|
||||
//hide
|
||||
|
||||
### `//suppress <node>`
|
||||
|
||||
Suppress all `<node>` in the current WorldEdit region non-destructively.
|
||||
|
||||
//suppress Diamond Block
|
||||
//suppress glass
|
||||
//suppress mesecons:wire_00000000_off
|
||||
|
||||
### `//highlight <node>`
|
||||
|
||||
Highlight `<node>` in the current WorldEdit region by hiding everything else non-destructively.
|
||||
|
||||
//highlight Diamond Block
|
||||
//highlight glass
|
||||
//highlight mesecons:wire_00000000_off
|
||||
|
||||
### `//restore`
|
||||
|
||||
Restores nodes hidden with WorldEdit in the current WorldEdit region.
|
||||
|
||||
//restore
|
||||
|
||||
### `//save <file>`
|
||||
|
||||
Save the current WorldEdit region to "(world folder)/schems/`<file>`.we".
|
||||
|
||||
//save some random filename
|
||||
//save huge_base
|
||||
|
||||
### `//allocate <file>`
|
||||
|
||||
Set the region defined by nodes from "(world folder)/schems/`<file>`.we" as the current WorldEdit region.
|
||||
|
||||
//allocate some random filename
|
||||
//allocate huge_base
|
||||
|
||||
### `//load <file>`
|
||||
|
||||
Load nodes from "(world folder)/schems/`<file>`.we" with position 1 of the current WorldEdit region as the origin.
|
||||
|
||||
//load some random filename
|
||||
//load huge_base
|
||||
|
||||
### `//lua <code>`
|
||||
|
||||
Executes `<code>` as a Lua chunk in the global namespace.
|
||||
|
||||
//lua worldedit.pos1["singleplayer"] = {x=0, y=0, z=0}
|
||||
//lua worldedit.rotate(worldedit.pos1["singleplayer"], worldedit.pos2["singleplayer"], "y", 90)
|
||||
|
||||
### `//luatransform <code>`
|
||||
|
||||
Executes `<code>` as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region.
|
||||
|
||||
//luatransform minetest.swap_node(pos, {name="default:stone"})
|
||||
//luatransform if minetest.get_node(pos).name == "air" then minetest.add_node(pos, {name="default:water_source"}) end
|
||||
|
||||
### `//mtschemcreate <file>`
|
||||
|
||||
Save the current WorldEdit region using the Minetest Schematic format to "(world folder)/schems/`<file>`.mts".
|
||||
|
||||
//mtschemcreate some random filename
|
||||
//mtschemcreate huge_base
|
||||
|
||||
### `//mtschemplace <file>`
|
||||
|
||||
Load nodes from "(world folder)/schems/`<file>`.mts" with position 1 of the current WorldEdit region as the origin.
|
||||
|
||||
//mtschemplace some random filename
|
||||
//mtschemplace huge_base
|
||||
|
||||
### `//mtschemprob start/finish/get`
|
||||
|
||||
After using `//mtschemprob start` all nodes punched will bring up a text field where a probablity can be entered.
|
||||
This mode can be left with `//mtschemprob finish`. `//mtschemprob get` will display the probabilities saved for the nodes.
|
||||
|
||||
//mtschemprob get
|
||||
|
||||
### `//clearobjects`
|
||||
|
||||
Clears all objects within the WorldEdit region.
|
||||
|
||||
//clearobjects
|
||||
|
||||
### `//shift x/y/z/?/up/down/left/right/front/back [+/-]<amount>`
|
||||
|
||||
Shifts the selection area by `[+|-]<amount>` without moving its contents.
|
||||
The shifting axis can be absolute (`x/y/z`) or relative (`up/down/left/right/front/back`).
|
||||
|
||||
//shift left 5
|
||||
|
||||
### `//expand [+/-]x/y/z/?/up/down/left/right/front/back <amount> [reverse amount]`
|
||||
|
||||
Expands the selection by `<amount>` in the selected absolute or relative axis.
|
||||
If specified, the selection can be expanded in the opposite direction over the same axis by `[reverse amount]`.
|
||||
|
||||
//expand right 7 5
|
||||
|
||||
### `//contract [+/-]x/y/z/?/up/down/left/right/front/back <amount> [reverse amount]`
|
||||
|
||||
Contracts the selection by `<amount>` in the selected absolute or relative axis.
|
||||
If specified, the selection can be contracted in the opposite direction over the same axis by `[reverse amount]`.
|
||||
|
||||
//expand right 7 5
|
||||
|
||||
### `//outset [h/v] <amount>`
|
||||
|
||||
Expands the selection in all directions by `<amount>`. If specified,
|
||||
the selection can be expanded horizontally in the x and z axes using `h`
|
||||
or vertically in the y axis using `v`.
|
||||
|
||||
//outset v 5
|
||||
|
||||
### `//inset [h/v] <amount>`
|
||||
|
||||
Contracts the selection in all directions by `<amount>`. If specified,
|
||||
the selection can be contracted horizontally in the x and z axes using `h`
|
||||
or vertically in the y axis using `v`.
|
||||
|
||||
//inset h 5
|
||||
|
||||
### `//brush none/(<command> [parameters])`
|
||||
|
||||
Assigns the given `<command>` to the currently held brush item, it will be ran with the first pointed solid node (as determined via raycast) as
|
||||
WorldEdit position 1 when using that specific brush item.
|
||||
Passing `none` instead clears the command assigned to the currently held brush item.
|
||||
Note that this functionality requires the `worldedit_brush` mod enabled.
|
||||
|
||||
//brush cube 8 8 8 Cobblestone
|
||||
//brush spr 12 glass
|
||||
//brush none
|
||||
|
||||
### `//cubeapply <size>/(<sizex> <sizey> <sizez>) <command> [parameters]`
|
||||
|
||||
Selects a cube with side length of `<size>` around the WorldEdit position 1 and runs the given `<command>` on the newly selected region.
|
||||
If `<sizex>`, `<sizey>` and `<sizez>` are given, they instead specify the length of the cuboid in X, Y, Z direction.
|
||||
This is mostly useful for brushes since it allows commands such as `//replace` to be ran, but it can also be used standalone.
|
||||
|
||||
//cubeapply 10 replaceinverse air default:water_source
|
||||
//brush cubeapply 15 drain
|
||||
//brush cubeapply 12 3 12 drain
|
||||
//brush cubeapply 1 deleteblocks
|
170
README.md
170
README.md
@ -1,62 +1,99 @@
|
||||
WorldEdit v1.0 for MineTest 0.4.8+
|
||||
==================================
|
||||
WorldEdit v1.3
|
||||
==============
|
||||
The ultimate in-game world editing tool for [Minetest](http://minetest.net/)! Tons of functionality to help with building, fixing, and more.
|
||||
|
||||
For more information, see the [forum topic](https://forum.minetest.net/viewtopic.php?id=572) at the Minetest forums.
|
||||
|
||||
# New users should see the [tutorial](Tutorial.md).
|
||||
|
||||

|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
There is a nice installation guide over at the [Minetest Wiki](http://wiki.minetest.com/wiki/Installing_mods). Here is a short summary:
|
||||
|
||||
1. Download the mod from the [official releases page](https://github.com/Uberi/Minetest-WorldEdit/releases). The download links are labelled "Source Code". If you are using Windows, you'll want to download the ZIP version.
|
||||
2. You should have a file named `Minetest-WorldEdit-x.x.zip`.
|
||||
3. Extract this file using your archiver of choice. If you are using Windows, open the ZIP file and move the folder inside to a safe place outside of the ZIP file.
|
||||
4. Make sure that you now have a folder with a file named README.md inside it. If you just have another folder inside this folder, use the nested folder instead.
|
||||
5. Move this folder into the `MINETEST_FOLDER/mods` folder, where `MINETEST_FOLDER` is the folder Minetest is located in.
|
||||
6. Open Minetest to a world selection screen.
|
||||
7. Select a world you want to use WorldEdit in by left clicking on it once and press the **Configure** button.
|
||||
8. You should have a mod selection screen. Select the one named something like `Minetest-WorldEdit` by left clicking once and press the **Enable Modpack** button.
|
||||
9. Press the **Save** button. You can now use WorldEdit in that world. Repeat steps 7 to 9 to enable WorldEdit for other worlds too.
|
||||
|
||||
If you are having trouble, try asking for help in the [IRC channel](https://webchat.freenode.net/?channels=#minetest) (faster but may not always have helpers online)
|
||||
or ask on the [forum topic](https://forum.minetest.net/viewtopic.php?id=572) (slower but more likely to get help).
|
||||
|
||||
Usage
|
||||
-----
|
||||
WorldEdit works primarily through chat commands. Depending on your key bindings, you can invoke chat entry with the "t" key, and open the chat console with the "F10" key.
|
||||
WorldEdit works primarily through the WorldEdit GUI and chat commands. Depending on your key bindings, you can invoke chat entry with the "T" key and open the chat console with the "F10" key.
|
||||
|
||||
WorldEdit has a huge potential for abuse by untrusted players. Therefore, users will not be able to use WorldEdit unless they have the "worldedit" privelege. This is available by default in single player, but in multiplayer the permission must be explicitly given by someone with the right credentials, using the follwoing chat command: `/grant <player name> worldedit`. This privelege can later be removed using the following chat command: `/revoke <player name> worldedit`.
|
||||
WorldEdit has a huge potential for abuse by untrusted players. Therefore, users will not be able to use WorldEdit unless they have the `worldedit` privilege.
|
||||
This is available by default in singleplayer, but in multiplayer the permission must be explicitly given by someone with the right credentials,
|
||||
using the following chat command: `/grant <player name> worldedit`. This privilege can later be removed using the following chat command: `/revoke <player name> worldedit`.
|
||||
|
||||
For in-game information about these commands, type `/help <command name>` in the chat. For example, to learn more about the `//copy` command, simply type `/help /copy` to display information relevant to copying a region.
|
||||
Certain functions/commands such as WorldEdit `//lua` and `//luatransform` chat commands additionally require the `server` privilege.
|
||||
This is because it is extremely dangerous to give access to these commands to untrusted players, since they essentially are able to control the computer the server is running on.
|
||||
Give this privilege only to people you trust with your computer.
|
||||
|
||||
Chat Commands
|
||||
-------------
|
||||
WorldEdit is accessed in-game through an interface. By default, the mod distribution includes a chat interface for this purpose. It is documented in the [Chat Commands Reference](Chat Commands.md).
|
||||
For in-game information about these commands, type `//help <command name>` in the chat. For example, to learn more about the `//copy` command, simply type `//help copy` to display information relevant to copying a region.
|
||||
|
||||
If visual manipulation of nodes is desired, the [WorldEdit GUI](https://forum.minetest.net/viewtopic.php?id=3112) mod provides a simple interface with buttons and text entry fields for this purpose.
|
||||
Interface
|
||||
---------
|
||||
WorldEdit is accessed in-game in two main ways.
|
||||
|
||||
The GUI adds a screen to each player's inventory that gives access to various WorldEdit functions. The [tutorial](Tutorial.md) may be helpful in learning to use it.
|
||||
|
||||
The chat interface adds many chat commands that perform various WorldEdit powered tasks. It is documented in the [Chat Commands Reference](ChatCommands.md).
|
||||
|
||||
Compatibility
|
||||
-------------
|
||||
This mod supports Minetest versions 0.4.8 and newer. Older versions of WorldEdit may work with older versions of Minetest, but are not recommended.
|
||||
This mod supports Minetest versions 5.0 and newer. Older versions of WorldEdit may work with older versions of Minetest, but are not recommended or supported.
|
||||
|
||||
WorldEdit works quite well with other mods, and does not have any known mod conflicts.
|
||||
WorldEdit works quite well with other mods and does not have any known mod conflicts.
|
||||
|
||||
WorldEdit GUI requires one of [sfinv](https://github.com/minetest/minetest_game/tree/master/mods/sfinv) (included in minetest_game),
|
||||
[Unified Inventory](https://forum.minetest.net/viewtopic.php?t=12767),
|
||||
[Inventory++](https://forum.minetest.net/viewtopic.php?id=6204) or [Smart Inventory](https://forum.minetest.net/viewtopic.php?t=16597).
|
||||
|
||||
If you use any other inventory manager mods, note that they may conflict with the WorldEdit GUI. If this is the case, it may be necessary to disable them.
|
||||
|
||||
WorldEdit API
|
||||
-------------
|
||||
WorldEdit exposes all significant functionality in a simple Lua interface. Adding WorldEdit to the file "depends.txt" in your mod gives you access to all of the `worldedit` functions. The API is useful for tasks such as high-performance node manipulation, alternative interfaces, and map creation.
|
||||
WorldEdit exposes all significant functionality in a simple Lua interface.
|
||||
|
||||
If you don't add WorldEdit to your "depends.txt" file, each file in the WorldEdit mod is also independent. For example, one may import the WorldEdit primitives API using the following code:
|
||||
Adding WorldEdit as a dependency to your mod gives you access to all of the `worldedit` functions. The API is useful for tasks such as high-performance node manipulation, alternative interfaces and map creation.
|
||||
|
||||
dofile(minetest.get_modpath("worldedit").."/primitives.lua")
|
||||
AGPLv3 compatible mods may further include WorldEdit files in their own mods. This can be useful if a modder wishes to completely avoid any dependency on WorldEdit. Note that it is required to give credit to the authors in this case.
|
||||
|
||||
AGPLv3 compatible mods may further include WorldEdit files in their own mods. This may be useful if a modder wishes to completely avoid any dependencies on WorldEdit. Note that it is required to give credit to the authors.
|
||||
|
||||
This API is documented in the [WorldEdit API Reference](WorldEdit API.md).
|
||||
This API is documented in the [WorldEdit API Reference](WorldEdit%20API.md).
|
||||
|
||||
Axes
|
||||
----
|
||||
The coordinate system is the same as that used by MineTest; Y is upwards, X is perpendicular, and Z is parallel.
|
||||
The coordinate system is the same as that used by Minetest; positive Y is upwards, positive X is rightwards, and positive Z is forwards, if a player is facing North (positive Z axis).
|
||||
|
||||
When an axis is specified in a WorldEdit command, it is specified as one of the following values: x, y, z, or ?.
|
||||
When an axis is specified in a WorldEdit chat command, it is specified as one of the following values: `x`, `y`, `z`, or `?`.
|
||||
|
||||
The value ? represents the axis the player is currently facing. If the player is facing more than one axis, the axis the player face direction is closest to will be used.
|
||||
In the GUI, there is a dropdown menu for this purpose. The "Look direction" option has the same effect as `?` does in chat commands.
|
||||
|
||||
The value `?` represents the axis the player is currently facing. If the player is facing more than one axis, the axis the player face direction is closest to will be used.
|
||||
|
||||
Nodes
|
||||
-----
|
||||
Node names are required for many types of commands that identify or modify specific types of nodes. They can be specified in a number of ways.
|
||||
|
||||
First, by description - the tooltip that appears when hovering over the item in an inventory. This is case insensitive and includes values such as "Cobblestone" and "bronze block". Note that certain commands (namely, `//replace` and `//replaceinverse`) do not support descriptions that contain spaces in the `<searchnode>` field.
|
||||
First, by description - the tooltip that appears when hovering over the item in an inventory. This is case insensitive and includes values such as "Cobblestone" and "bronze block".
|
||||
Note that certain commands (namely, `//replace` and `//replaceinverse`) do not support descriptions that contain spaces in the `<searchnode>` field.
|
||||
|
||||
Second, by name - the node name that is defined by code, but without the mod name prefix. This is case sensitive and includes values such as "piston_normal_off" and "cactus". Nodes defined in the `default` mod always take precedence over other nodes when searching for the correct one, and if there are multiple possible nodes (such as "a:celery" and "b:celery"), one is chosen in no particular order.
|
||||
Second, by name - the node name that is defined by code, but without the mod name prefix. This is case sensitive and includes values such as "piston_normal_off" and "cactus".
|
||||
If there are multiple possible nodes (such as "a:celery" and "b:celery"), one is chosen in no particular order.
|
||||
|
||||
Finally, by full name - the unambiguous identifier of the node, prefixes and all. This is case sensitive and includes values such as "default:stone" and "mesecons:wire_00000000_off".
|
||||
|
||||
The node name "air" can be used anywhere a normal node name can, and acts as a blank node. This is useful for clearing or removing nodes. For example, `//set air` would remove all the nodes in the current WorldEdit region. Similarly, `//sphere 10 air`, when WorldEdit position 1 underground, would dig a large sphere out of the ground.
|
||||
The node name "air" can be used anywhere a normal node name can and acts as a blank node. This is useful for clearing or removing nodes.
|
||||
For example, `//set air` would remove all the nodes in the current WorldEdit region. Similarly, `//sphere 10 air`, when WorldEdit position 1 underground, would dig a large sphere out of the ground.
|
||||
|
||||
Regions
|
||||
-------
|
||||
@ -64,11 +101,11 @@ Most WorldEdit commands operate on regions. Regions are a set of two positions t
|
||||
|
||||
Each positions together define two opposing corners of the cube. With two opposing corners it is possible to determine both the location and dimensions of the region.
|
||||
|
||||
Regions are not saved between server restarts. They start off as empty regions, and cannot be used with most WorldEdit commands until they are set to valid values.
|
||||
Regions are not saved between server restarts. They start off as empty regions and cannot be used with most WorldEdit commands until they are set to valid values.
|
||||
|
||||
Markers
|
||||
-------
|
||||
Entities are used to mark the location of the WorldEdit regions. They appear as boxes containing the number 1 or 2, and represent position 1 and 2 of the WorldEdit region, respectively.
|
||||
Entities are used to mark the location of the WorldEdit regions. They appear as boxes containing the number 1 or 2 and represent the first and second position of the WorldEdit region, respectively.
|
||||
|
||||
To remove the entities, simply punch them. This does not reset the positions themselves.
|
||||
|
||||
@ -76,35 +113,80 @@ Schematics
|
||||
----------
|
||||
WorldEdit supports two different types of schematics.
|
||||
|
||||
The first is the WorldEdit Schematic format, with the file extension ".we", and in some older versions, ".wem". There have been several previous versions of the WorldEdit Schematic format, but WorldEdit is capable of loading any past versions, and will always support them - there is no need to worry about schematics becoming obselete.
|
||||
The first is the WorldEdit Schematic format, with the file extension ".we", and in some older versions, ".wem".
|
||||
There have been several previous versions of the WorldEdit Schematic format, but WorldEdit is capable of loading any past versions, and will always support them - there is no need to worry about schematics becoming obsolete.
|
||||
|
||||
The current version of the WorldEdit Schematic format, internally known as version 4, is essentially an array of node data tables in Lua 5.2 table syntax. Specifically:
|
||||
As of version 5, WorldEdit schematics include a header. The header is seperated from the content by a colon (`:`). It may contain fields seperated by commas (`,`).
|
||||
Currently only one field is used, which contains the version as an ASCII decimal.
|
||||
|
||||
return {
|
||||
{
|
||||
["y"] = <y-axis coordinate>,
|
||||
["x"] = <x-axis coordinate>,
|
||||
["name"] = <node name>,
|
||||
["z"] = <z-axis coordinate>,
|
||||
["meta"] = <metadata table>,
|
||||
["param2"] = <param2 value>,
|
||||
["param1"] = <y-axis coordinate>,
|
||||
},
|
||||
<...>
|
||||
}
|
||||
The current version of the WorldEdit Schematic format is essentially an array of node data tables in Lua 5.1 table syntax preceded by a header.
|
||||
Specifically it looks like this:
|
||||
|
||||
Value ordering and minor aspects of the syntax, such as trailing commas or newlines, are not guaranteed.
|
||||
5:return {
|
||||
{
|
||||
y = <y-axis coordinate>,
|
||||
x = <x-axis coordinate>,
|
||||
z = <z-axis coordinate>,
|
||||
name = <node name>,
|
||||
param1 = <param1 value>,
|
||||
param2 = <param2 value>,
|
||||
meta = <metadata table>,
|
||||
},
|
||||
<...>
|
||||
}
|
||||
|
||||
|
||||
The ordering of the values and minor aspects of the syntax, such as trailing commas or newlines, are not guaranteed to stay the same in future versions.
|
||||
|
||||
The WorldEdit Schematic format is accessed via the WorldEdit API, or WorldEdit serialization chat commands such as `//serialize` and `//deserialize`.
|
||||
|
||||
The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document. Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`.
|
||||
The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document.
|
||||
Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`.
|
||||
|
||||
Authors
|
||||
-------
|
||||
WorldEdit would not be possible without the contributions of many developers and designers. Below, they are listed alphabetically:
|
||||
|
||||
Alexander Weber
|
||||
ANAND
|
||||
beyondlimits
|
||||
Carter Kolwey
|
||||
cornernote
|
||||
Cy
|
||||
Daniel Sosa
|
||||
electricface
|
||||
est31
|
||||
Eugen Wesseloh
|
||||
h3ndrik
|
||||
HybridDog
|
||||
Isidor Zeuner
|
||||
Jean-Patrick Guerrero
|
||||
Joseph Pickard
|
||||
kaeza
|
||||
kilbith
|
||||
KodexKy
|
||||
Kyle
|
||||
MT-Modder
|
||||
Niwla23
|
||||
Panquesito7
|
||||
Pedro Gimeno
|
||||
Rui
|
||||
Sebastien Ponce
|
||||
sfan5
|
||||
ShadowNinja
|
||||
shivajiva101
|
||||
spillz
|
||||
Starbeamrainbowlabs
|
||||
TalkLounge
|
||||
tenplus1
|
||||
Uberi/Temperest
|
||||
Wuzzy
|
||||
|
||||
License
|
||||
-------
|
||||
Copyright 2013 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote).
|
||||
Copyright (c) 2012 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote).
|
||||
|
||||
This mod is licensed under the [GNU Affero General Public License](http://www.gnu.org/licenses/agpl-3.0.html).
|
||||
This mod is licensed under the [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html).
|
||||
|
||||
Basically, this means everyone is free to use, modify, and distribute the files, as long as these modifications are also licensed the same way.
|
||||
|
||||
Most importantly, the Affero variant of the GPL requires you to publish your modifications in source form, even if the mod is run only on the server, and not distributed.
|
||||
|
79
Tutorial.md
79
Tutorial.md
@ -1,55 +1,118 @@
|
||||
WorldEdit Tutorial
|
||||
==================
|
||||
This is a step-by-step tutorial outlining the basic usage of WorldEdit. For more information, see the [README](README.md).
|
||||
This is a step-by-step tutorial outlining the basic usage of WorldEdit.
|
||||
|
||||
Let's start with a few assumptions:
|
||||
|
||||
* You have a compatible version of Minetest working.
|
||||
* See the [README](README.md) for compatibility information.
|
||||
* You have a compatible version of Minetest working, that is 5.0 or later.
|
||||
* You have WorldEdit installed as a mod.
|
||||
* If using Windows, [MODSTER](https://forum.minetest.net/viewtopic.php?pid=101463) makes installing mods totally painless.
|
||||
* Simply download the file, extract the archive, and move it to the correct mod folder for Minetest.
|
||||
* See the installation instructions in [README](README.md) if you need more details.
|
||||
* You are familiar with the basics of the game.
|
||||
* How to walk, jump, and climb.
|
||||
* How to dig, place, and punch blocks.
|
||||
* How to type into the chat and read text from it.
|
||||
* One of the following:
|
||||
* How to type into the chat and read text from it.
|
||||
* How to open the inventory screen and press buttons on it.
|
||||
|
||||
Overview
|
||||
--------
|
||||
WorldEdit has a "region", which is simply a cuboid area defined by two markers, both of which the player can move around. Every player can have their own region with their own two markers.
|
||||
|
||||
WorldEdit chat commands can work inside the region selected, or around the first marker.
|
||||
WorldEdit GUI buttons and chat commands generally work inside the region selected, or around the first marker.
|
||||
|
||||
If you are using the chat commands, follow the steps under **Chat Commands**. If you are using the WorldEdit GUI, follow the steps under **WorldEdit GUI**.
|
||||
|
||||
Step 1: Selecting a region
|
||||
--------------------------
|
||||
### Chat Commands
|
||||
|
||||
In the chat prompt, enter `//p set`. In the chat, you are prompted to punch two nodes to set the positions of the two markers.
|
||||
|
||||
Punch a nearby node. Be careful of breakable ones such as torches. A black cube reading "1" will appear around the node. This is the marker for WorldEdit position 1.
|
||||
|
||||
Walk away from the node you just punched. Now, punch another node. A black cube reading "2" will appear around the node. This is the marker for WorldEdit position 2.
|
||||
|
||||
### WorldEdit GUI
|
||||
|
||||
Open the main WorldEdit GUI from your inventory screen. The icon looks like a globe with a red dot in the center.
|
||||
|
||||
Press the "Get/Set Positions" button. On the new screen, press the "Set Position 1" button. The inventory screen should close.
|
||||
|
||||
Punch a nearby node. Be careful of breakable ones such as torches. A black cube reading "1" will appear around the node. This is the marker for WorldEdit position 1.
|
||||
|
||||
Walk away from the node you just punched. Open your inventory again. It should be on the same page as it was before.
|
||||
|
||||
Press the "Set Position 2" button. The inventory screen should close.
|
||||
|
||||
Now, punch another node. A black cube reading "2" will appear around the node. This is the marker for WorldEdit position 2.
|
||||
|
||||
Step 2: Region commands
|
||||
-----------------------
|
||||
### Chat Commands
|
||||
|
||||
In the chat prompt, enter `//set mese`. In the chat, you will see a message showing the number of nodes set after a small delay.
|
||||
|
||||
Look at the place between the two markers: it is now filled with MESE blocks!
|
||||
|
||||
The `//set <node>` command fills the region with whatever node you want. It is a region-oriented command, which means it works inside the WorldEdit region only.
|
||||
|
||||
Now, try a few different variations, such as `//set torch`, `//set cobble`, and `//set water`.
|
||||
Now, try a few different variations, such as `//set torch`, `//set cobble`, and `//set water source`.
|
||||
|
||||
### WorldEdit GUI
|
||||
|
||||
Open the main WorldEdit GUI from your inventory screen.
|
||||
|
||||
Press the "Set Nodes" button. You should see a new screen with various options for setting nodes.
|
||||
|
||||
Enter "mese" in the "Name" field. Press Search if you would like to see what the node you just entered looks like.
|
||||
|
||||
Press the "Set Nodes" button on this screen. In the chat, you will see a message showing the number of nodes set after a small delay.
|
||||
|
||||
Look at the place between the two markers: it is now filled with MESE blocks!
|
||||
|
||||
The "Set Nodes" function fills the region with whatever node you want. It is a region-oriented command, which means it works inside the WorldEdit region only.
|
||||
|
||||
Now, try a few different variations on the node name, such as "torch", "cobble", and "water source".
|
||||
|
||||
Step 3: Position commands
|
||||
-------------------------
|
||||
### Chat Commands
|
||||
|
||||
In the chat prompt, enter `//hollowdome 30 glass`. In the chat, you will see a message showing the number of nodes set after a small delay.
|
||||
|
||||
Look around marker 1: it is now surrounded by a hollow glass dome!
|
||||
|
||||
The `//hollowdome <radius> <node>` command creates a hollow dome centered around marker 1, made of any node you want. It is a position-oriented command, which means it works around marker 1 and can go outside the WorldEdit region.
|
||||
|
||||
### WorldEdit GUI
|
||||
|
||||
Open the main WorldEdit GUI from your inventory screen.
|
||||
|
||||
Press the "Sphere/Dome" button. You should see a new screen with various options for making spheres or domes.
|
||||
|
||||
Enter "glass" in the "Name" field. Press Search if you would like to see what the node you just entered looks like.
|
||||
|
||||
Enter "30" in the "Radius" field.
|
||||
|
||||
Press the "Hollow Dome" button on this screen. In the chat, you will see a message showing the number of nodes added after a small delay.
|
||||
|
||||
Look around marker 1: it is now surrounded by a hollow glass dome!
|
||||
|
||||
The "Hollow Dome" function creates a hollow dome centered around marker 1, made of any node you want. It is a position-oriented command, which means it works around marker 1 and can go outside the WorldEdit region.
|
||||
|
||||
Step 4: Other commands
|
||||
----------------------
|
||||
There are many more commands than what is shown here. See the [Chat Commands Reference](Chat Commands.md) for a detailed list of them, along with descriptions and examples for every single one.
|
||||
### Chat Commands
|
||||
|
||||
There are many more commands than what is shown here. See the [Chat Commands Reference](ChatCommands.md) for a detailed list of them, along with descriptions and examples for every single one.
|
||||
|
||||
If you're in-game and forgot how a command works, just use the `/help <command name>` command, without the first forward slash. For example, to see some information about the `//set <node>` command mentioned earlier, simply use `/help /set`.
|
||||
|
||||
A very useful command to check out is the `//save <schematic>` command, which can save everything inside the WorldEdit region to a file, stored on the computer hosting the server (the player's computer, in single player mode). You can then later use `//load <schematic>` to load the data in a file into a world, even another world on another computer.
|
||||
|
||||
### WorldEdit GUI
|
||||
|
||||
This only scratches the surface of what WorldEdit is capable of. Most of the functions in the WorldEdit GUI correspond to chat commands, and so the [Chat Commands Reference](ChatCommands.md) may be useful if you get stuck.
|
||||
|
||||
It is helpful to explore the various buttons in the interface and check out what they do. Learning the chat command interface is also useful if you use WorldEdit intensively - an experienced chat command user can usually work faster than an experienced WorldEdit GUI user.
|
||||
|
109
WorldEdit API.md
109
WorldEdit API.md
@ -6,13 +6,31 @@ If needed, individual modules such as visualization.lua can be removed without a
|
||||
|
||||
For more information, see the [README](README.md).
|
||||
|
||||
General
|
||||
-------
|
||||
|
||||
### value = worldedit.version
|
||||
|
||||
Contains the current version of WorldEdit in a table of the form `{major=MAJOR_INTEGER, minor=MINOR_INTEGER}`, where `MAJOR_INTEGER` is the major version (the number before the period) as an integer, and `MINOR_INTEGER` is the minor version (the number after the period) as an integer. This is intended for version checking purposes.
|
||||
|
||||
### value = worldedit.version_string
|
||||
|
||||
Contains the current version of WorldEdit in the form of a string `"MAJOR_INTEGER.MINOR_INTEGER"`, where `MAJOR_INTEGER` is the major version (the number before the period) as an integer, and `MINOR_INTEGER` is the minor version (the number after the period) as an integer. This is intended for display purposes.
|
||||
|
||||
Manipulations
|
||||
-------------
|
||||
Contained in manipulations.lua, this module allows several node operations to be applied over a region.
|
||||
|
||||
### count = worldedit.set(pos1, pos2, nodename)
|
||||
### count = worldedit.set(pos1, pos2, node_name)
|
||||
|
||||
Sets a region defined by positions `pos1` and `pos2` to `nodename`. To clear to region, use "air" as the value of `nodename`.
|
||||
Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a region, use "air" as the value of `node_name`.
|
||||
If `node_name` is a list of nodes, each set node is randomly picked from it.
|
||||
|
||||
Returns the number of nodes set.
|
||||
|
||||
### `count = worldedit.set_param2(pos1, pos2, param2)`
|
||||
|
||||
Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.
|
||||
|
||||
Returns the number of nodes set.
|
||||
|
||||
@ -34,6 +52,13 @@ Copies the region defined by positions `pos1` and `pos2` along the `axis` axis (
|
||||
|
||||
Returns the number of nodes copied.
|
||||
|
||||
### count = worldedit.copy2(pos1, pos2, off)
|
||||
|
||||
Copies the region defined by positions `pos1` and `pos2` by the offset vector `off`.
|
||||
Note that the offset needs to be big enough that there is no overlap.
|
||||
|
||||
Returns the number of nodes copied.
|
||||
|
||||
### count = worldedit.move(pos1, pos2, axis, amount)
|
||||
|
||||
Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
|
||||
@ -46,11 +71,18 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax
|
||||
|
||||
Returns the number of nodes stacked.
|
||||
|
||||
### count, newpos1, newpos2 = worldedit.scale(pos1, pos2, factor)
|
||||
### count = worldedit.stack2(pos1, pos2, direction, amount)
|
||||
|
||||
Scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin.
|
||||
Duplicates the region defined by positions `pos1` and `pos2` `amount` times with offset vector `direction`.
|
||||
Note that the offset vector needs to be big enough that there is no overlap.
|
||||
|
||||
Returns the number of nodes scaled, the new scaled position 1, and the new scaled position 2.
|
||||
Returns the number of nodes stacked.
|
||||
|
||||
### count, newpos1, newpos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)
|
||||
|
||||
Stretches the region defined by positions `pos1` and `pos2` by an factor of positive integers `stretchx`, `stretchy`. and `stretchz` along the X, Y, and Z axes, respectively, with `pos1` as the origin.
|
||||
|
||||
Returns the number of nodes stretched, the new scaled position 1, and the new scaled position 2.
|
||||
|
||||
### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
|
||||
|
||||
@ -92,51 +124,39 @@ Primitives
|
||||
----------
|
||||
Contained in primitives.lua, this module allows the creation of several geometric primitives.
|
||||
|
||||
### count = worldedit.hollow_sphere(pos, radius, nodename)
|
||||
### count = worldedit.cube(pos, width, height, length, node_name, hollow)
|
||||
|
||||
Adds a hollow sphere centered at `pos` with radius `radius`, composed of `nodename`.
|
||||
Adds a cube with its ground level centered at `pos`, the dimensions `width` x `height` x `length`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.sphere(pos, radius, nodename)
|
||||
### count = worldedit.sphere(pos, radius, node_name, hollow)
|
||||
|
||||
Adds a sphere centered at `pos` with radius `radius`, composed of `nodename`.
|
||||
Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.hollow_dome(pos, radius, nodename)
|
||||
### count = worldedit.dome(pos, radius, node_name, hollow)
|
||||
|
||||
Adds a hollow dome centered at `pos` with radius `radius`, composed of `nodename`.
|
||||
Adds a dome centered at `pos` with radius `radius`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.dome(pos, radius, nodename)
|
||||
### count = worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)
|
||||
|
||||
Adds a dome centered at `pos` with radius `radius`, composed of `nodename`.
|
||||
Adds a cylinder-like at `pos` along the `axis` axis ("x" or "y" or "z") with length `length`, base radius `radius1` and top radius `radius2`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)
|
||||
### count = worldedit.pyramid(pos, axis, height, node_name, hollow)
|
||||
|
||||
Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.
|
||||
Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.cylinder(pos, axis, length, radius, nodename)
|
||||
### count = worldedit.spiral(pos, length, height, spacer, node_name)
|
||||
|
||||
Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.pyramid(pos, axis, height, nodename)
|
||||
|
||||
Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.spiral(pos, length, height, spacer, nodename)
|
||||
|
||||
Adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `nodename`.
|
||||
Adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
@ -156,15 +176,15 @@ Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destru
|
||||
|
||||
Returns the number of nodes hidden.
|
||||
|
||||
### count = worldedit.suppress(pos1, pos2, nodename)
|
||||
### count = worldedit.suppress(pos1, pos2, node_name)
|
||||
|
||||
Suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.
|
||||
Suppresses all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.
|
||||
|
||||
Returns the number of nodes suppressed.
|
||||
|
||||
### count = worldedit.highlight(pos1, pos2, nodename)
|
||||
### count = worldedit.highlight(pos1, pos2, node_name)
|
||||
|
||||
Highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.
|
||||
Highlights all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.
|
||||
|
||||
Returns the number of nodes found.
|
||||
|
||||
@ -176,31 +196,32 @@ Returns the number of nodes restored.
|
||||
|
||||
Serialization
|
||||
-------------
|
||||
Contained in serialization.lua, this module allows regions of nodes to be serialized and deserialized to formats suitable for use outside MineTest.
|
||||
Contained in serialization.lua, this module allows regions of nodes to be serialized and deserialized to formats suitable for use outside Minetest.
|
||||
|
||||
### version = worldedit.valueversion(value)
|
||||
### version, extra_fields, content = worldedit.read_header(value)
|
||||
|
||||
Determines the version of serialized data `value`.
|
||||
Reads the header from serialized data `value`.
|
||||
|
||||
Returns the version as a positive integer or 0 for unknown versions.
|
||||
Returns the version as a positive integer (nil for unknown versions),
|
||||
extra header fields (nil if not supported), and the content after the header.
|
||||
|
||||
### data, count = worldedit.serialize(pos1, pos2)
|
||||
|
||||
Converts the region defined by positions `pos1` and `pos2` into a single string.
|
||||
|
||||
Returns the serialized data and the number of nodes serialized.
|
||||
Returns the serialized data and the number of nodes serialized, or nil.
|
||||
|
||||
### pos1, pos2, count = worldedit.allocate(originpos, value)
|
||||
### pos1, pos2, count = worldedit.allocate(origin_pos, value)
|
||||
|
||||
Determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`.
|
||||
Determines the volume the nodes represented by string `value` would occupy if deserialized at `origin_pos`.
|
||||
|
||||
Returns the two corner positions and the number of nodes.
|
||||
Returns the two corner positions and the number of nodes, or nil.
|
||||
|
||||
### count = worldedit.deserialize(originpos, value)
|
||||
### count = worldedit.deserialize(origin_pos, value)
|
||||
|
||||
Loads the nodes represented by string `value` at position `originpos`.
|
||||
Loads the nodes represented by string `value` at position `origin_pos`.
|
||||
|
||||
Returns the number of nodes deserialized.
|
||||
Returns the number of nodes deserialized or nil.
|
||||
|
||||
Code
|
||||
----
|
||||
|
12
config.ld
Normal file
12
config.ld
Normal file
@ -0,0 +1,12 @@
|
||||
project = "WorldEdit"
|
||||
title = "WorldEdit API Documentation"
|
||||
description = "Minetest mod to mass-modify nodes"
|
||||
format = "markdown"
|
||||
file = {"worldedit"}
|
||||
topics = {
|
||||
"README.md",
|
||||
"Tutorial.md",
|
||||
"ChatCommands.md",
|
||||
"LICENSE.txt"
|
||||
}
|
||||
|
2
modpack.conf
Normal file
2
modpack.conf
Normal file
@ -0,0 +1,2 @@
|
||||
name = Minetest-WorldEdit
|
||||
description = WorldEdit is an in-game world editor. Use it to repair griefing, or just create awesome buildings in seconds.
|
@ -1,32 +1,35 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest --local copy of global
|
||||
--- Lua code execution functions.
|
||||
-- @module worldedit.code
|
||||
|
||||
--executes `code` as a Lua chunk in the global namespace, returning an error if the code fails or nil otherwise
|
||||
worldedit.lua = function(code)
|
||||
local operation, message = loadstring(code)
|
||||
if operation == nil then --code parsing failed
|
||||
return message
|
||||
--- Executes `code` as a Lua chunk in the global namespace.
|
||||
-- @return An error message if the code fails, or nil on success.
|
||||
function worldedit.lua(code)
|
||||
local func, err = loadstring(code)
|
||||
if not func then -- Syntax error
|
||||
return err
|
||||
end
|
||||
local status, message = pcall(operation)
|
||||
if status == nil then --operation failed
|
||||
return message
|
||||
local good, err = pcall(func)
|
||||
if not good then -- Runtime error
|
||||
return err
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--executes `code` as a Lua chunk in the global namespace with the variable pos available, for each node in a region defined by positions `pos1` and `pos2`, returning an error if the code fails or nil otherwise
|
||||
worldedit.luatransform = function(pos1, pos2, code)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
local factory, message = loadstring("return function(pos) " .. code .. " end")
|
||||
if factory == nil then --code parsing failed
|
||||
return message
|
||||
--- Executes `code` as a Lua chunk in the global namespace with the variable
|
||||
-- pos available, for each node in a region defined by positions `pos1` and
|
||||
-- `pos2`.
|
||||
-- @return An error message if the code fails, or nil on success.
|
||||
function worldedit.luatransform(pos1, pos2, code)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
local factory, err = loadstring("return function(pos) " .. code .. " end")
|
||||
if not factory then -- Syntax error
|
||||
return err
|
||||
end
|
||||
local operation = factory()
|
||||
local func = factory()
|
||||
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local pos = {x=pos1.x, y=0, z=0}
|
||||
while pos.x <= pos2.x do
|
||||
@ -34,9 +37,9 @@ worldedit.luatransform = function(pos1, pos2, code)
|
||||
while pos.y <= pos2.y do
|
||||
pos.z = pos1.z
|
||||
while pos.z <= pos2.z do
|
||||
local status, message = pcall(operation, pos)
|
||||
if status == nil then --operation failed
|
||||
return message
|
||||
local good, err = pcall(func, pos)
|
||||
if not good then -- Runtime error
|
||||
return err
|
||||
end
|
||||
pos.z = pos.z + 1
|
||||
end
|
||||
@ -46,3 +49,4 @@ worldedit.luatransform = function(pos1, pos2, code)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
119
worldedit/common.lua
Normal file
119
worldedit/common.lua
Normal file
@ -0,0 +1,119 @@
|
||||
--- Common functions [INTERNAL]. All of these functions are internal!
|
||||
-- @module worldedit.common
|
||||
|
||||
--- Copies and modifies positions `pos1` and `pos2` so that each component of
|
||||
-- `pos1` is less than or equal to the corresponding component of `pos2`.
|
||||
-- Returns the new positions.
|
||||
function worldedit.sort_pos(pos1, pos2)
|
||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||
if pos1.x > pos2.x then
|
||||
pos2.x, pos1.x = pos1.x, pos2.x
|
||||
end
|
||||
if pos1.y > pos2.y then
|
||||
pos2.y, pos1.y = pos1.y, pos2.y
|
||||
end
|
||||
if pos1.z > pos2.z then
|
||||
pos2.z, pos1.z = pos1.z, pos2.z
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
|
||||
--- Determines the volume of the region defined by positions `pos1` and `pos2`.
|
||||
-- @return The volume.
|
||||
function worldedit.volume(pos1, pos2)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
return (pos2.x - pos1.x + 1) *
|
||||
(pos2.y - pos1.y + 1) *
|
||||
(pos2.z - pos1.z + 1)
|
||||
end
|
||||
|
||||
|
||||
--- Gets other axes given an axis.
|
||||
-- @raise Axis must be x, y, or z!
|
||||
function worldedit.get_axis_others(axis)
|
||||
if axis == "x" then
|
||||
return "y", "z"
|
||||
elseif axis == "y" then
|
||||
return "x", "z"
|
||||
elseif axis == "z" then
|
||||
return "x", "y"
|
||||
else
|
||||
error("Axis must be x, y, or z!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function worldedit.keep_loaded(pos1, pos2)
|
||||
-- Create a vmanip and read the area from map, this
|
||||
-- causes all MapBlocks to be loaded into memory.
|
||||
-- This doesn't actually *keep* them loaded, unlike the name implies.
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
end
|
||||
|
||||
|
||||
local mh = {}
|
||||
worldedit.manip_helpers = mh
|
||||
|
||||
|
||||
--- Generates an empty VoxelManip data table for an area.
|
||||
-- @return The empty data table.
|
||||
function mh.get_empty_data(area)
|
||||
-- Fill emerged area with ignore so that blocks in the area that are
|
||||
-- only partially modified aren't overwriten.
|
||||
local data = {}
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(area.MinEdge, area.MaxEdge) do
|
||||
data[i] = c_ignore
|
||||
end
|
||||
return data
|
||||
end
|
||||
|
||||
|
||||
function mh.init(pos1, pos2)
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
return manip, area
|
||||
end
|
||||
|
||||
|
||||
function mh.init_radius(pos, radius)
|
||||
local pos1 = vector.subtract(pos, radius)
|
||||
local pos2 = vector.add(pos, radius)
|
||||
return mh.init(pos1, pos2)
|
||||
end
|
||||
|
||||
|
||||
function mh.init_axis_radius(base_pos, axis, radius)
|
||||
return mh.init_axis_radius_length(base_pos, axis, radius, radius)
|
||||
end
|
||||
|
||||
|
||||
function mh.init_axis_radius_length(base_pos, axis, radius, length)
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
local pos1 = {
|
||||
[axis] = base_pos[axis],
|
||||
[other1] = base_pos[other1] - radius,
|
||||
[other2] = base_pos[other2] - radius
|
||||
}
|
||||
local pos2 = {
|
||||
[axis] = base_pos[axis] + length,
|
||||
[other1] = base_pos[other1] + radius,
|
||||
[other2] = base_pos[other2] + radius
|
||||
}
|
||||
return mh.init(pos1, pos2)
|
||||
end
|
||||
|
||||
|
||||
function mh.finish(manip, data)
|
||||
-- Update map
|
||||
if data ~= nil then
|
||||
manip:set_data(data)
|
||||
end
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
end
|
||||
|
@ -1,9 +1,21 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest --local copy of global
|
||||
--- Compatibility functions.
|
||||
-- @module worldedit.compatibility
|
||||
|
||||
local function deprecated(new_func)
|
||||
local info = debug.getinfo(1, "n")
|
||||
local msg = "worldedit." .. info.name .. "() is deprecated."
|
||||
if new_func then
|
||||
msg = msg .. " Use worldedit." .. new_func .. "() instead."
|
||||
end
|
||||
minetest.log("deprecated", msg)
|
||||
end
|
||||
|
||||
worldedit.allocate_old = worldedit.allocate
|
||||
|
||||
worldedit.deserialize_old = worldedit.deserialize
|
||||
worldedit.metasave = function(pos1, pos2, filename)
|
||||
|
||||
function worldedit.metasave(pos1, pos2, filename)
|
||||
deprecated("save")
|
||||
local file, err = io.open(filename, "wb")
|
||||
if err then return 0 end
|
||||
local data, count = worldedit.serialize(pos1, pos2)
|
||||
@ -11,10 +23,52 @@ worldedit.metasave = function(pos1, pos2, filename)
|
||||
file:close()
|
||||
return count
|
||||
end
|
||||
worldedit.metaload = function(originpos, filename)
|
||||
|
||||
function worldedit.metaload(originpos, filename)
|
||||
deprecated("load")
|
||||
filename = minetest.get_worldpath() .. "/schems/" .. file .. ".wem"
|
||||
local file, err = io.open(filename, "wb")
|
||||
if err then return 0 end
|
||||
local data = file:read("*a")
|
||||
return worldedit.deserialize(originpos, data)
|
||||
end
|
||||
|
||||
function worldedit.scale(pos1, pos2, factor)
|
||||
deprecated("stretch")
|
||||
return worldedit.stretch(pos1, pos2, factor, factor, factor)
|
||||
end
|
||||
|
||||
function worldedit.valueversion(value)
|
||||
deprecated("read_header")
|
||||
local version = worldedit.read_header(value)
|
||||
if not version or version > worldedit.LATEST_SERIALIZATION_VERSION then
|
||||
return 0
|
||||
end
|
||||
return version
|
||||
end
|
||||
|
||||
function worldedit.replaceinverse(pos1, pos2, search_node, replace_node)
|
||||
deprecated("replace")
|
||||
return worldedit.replace(pos1, pos2, search_node, replace_node, true)
|
||||
end
|
||||
|
||||
function worldedit.clearobjects(...)
|
||||
deprecated("clear_objects")
|
||||
return worldedit.clear_objects(...)
|
||||
end
|
||||
|
||||
function worldedit.hollow_sphere(pos, radius, node_name)
|
||||
deprecated("sphere")
|
||||
return worldedit.sphere(pos, radius, node_name, true)
|
||||
end
|
||||
|
||||
function worldedit.hollow_dome(pos, radius, node_name)
|
||||
deprecated("dome")
|
||||
return worldedit.dome(pos, radius, node_name, true)
|
||||
end
|
||||
|
||||
function worldedit.hollow_cylinder(pos, axis, length, radius, node_name)
|
||||
deprecated("cylinder")
|
||||
return worldedit.cylinder(pos, axis, length, radius, node_name, true)
|
||||
end
|
||||
|
||||
|
243
worldedit/cuboid.lua
Normal file
243
worldedit/cuboid.lua
Normal file
@ -0,0 +1,243 @@
|
||||
-- Expands or contracts the cuboid in all axes by amount (positive or negative)
|
||||
worldedit.cuboid_volumetric_expand = function(name, amount)
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
return false, "Undefined cuboid"
|
||||
end
|
||||
|
||||
local delta1 = vector.new()
|
||||
local delta2 = vector.new()
|
||||
local delta_dir1
|
||||
local delta_dir2
|
||||
|
||||
delta1 = vector.add(delta1, amount)
|
||||
delta2 = vector.add(delta2, amount)
|
||||
delta_dir1, delta_dir2 = worldedit.get_expansion_directions(pos1, pos2)
|
||||
delta1 = vector.multiply(delta1, delta_dir1)
|
||||
delta2 = vector.multiply(delta2, delta_dir2)
|
||||
worldedit.pos1[name] = vector.add(pos1, delta1)
|
||||
worldedit.pos2[name] = vector.add(pos2, delta2)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- Expands or contracts the cuboid in a single axis by amount (positive or negative)
|
||||
worldedit.cuboid_linear_expand = function(name, axis, direction, amount)
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
return false, "undefined cuboid"
|
||||
end
|
||||
|
||||
if direction ~= 1 and direction ~= -1 then
|
||||
return false, "invalid marker"
|
||||
end
|
||||
|
||||
local marker = worldedit.marker_get_closest_to_axis(name, axis, direction)
|
||||
local deltavect = vector.new()
|
||||
|
||||
if axis == 'x' then
|
||||
deltavect.x = amount * direction
|
||||
elseif axis == 'y' then
|
||||
deltavect.y = amount * direction
|
||||
elseif axis == 'z' then
|
||||
deltavect.z = amount * direction
|
||||
else
|
||||
return false, "invalid axis"
|
||||
end
|
||||
|
||||
worldedit.marker_move(name, marker, deltavect)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- Shifts the cuboid by '+-amount' in axis 'axis'
|
||||
worldedit.cuboid_shift = function(name, axis, amount)
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
return false, "undefined cuboid"
|
||||
end
|
||||
|
||||
if axis == 'x' then
|
||||
worldedit.pos1[name].x = pos1.x + amount
|
||||
worldedit.pos2[name].x = pos2.x + amount
|
||||
elseif axis == 'y' then
|
||||
worldedit.pos1[name].y = pos1.y + amount
|
||||
worldedit.pos2[name].y = pos2.y + amount
|
||||
elseif axis == 'z' then
|
||||
worldedit.pos1[name].z = pos1.z + amount
|
||||
worldedit.pos2[name].z = pos2.z + amount
|
||||
else
|
||||
return false, "invalid axis"
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- Moves the location of a single marker by adding deltavector
|
||||
worldedit.marker_move = function(name, marker, deltavector)
|
||||
if marker ~= 1 and marker ~= 2 then
|
||||
return false
|
||||
end
|
||||
|
||||
if marker == 1 then
|
||||
local pos = worldedit.pos1[name]
|
||||
worldedit.pos1[name] = vector.add(deltavector, pos)
|
||||
else
|
||||
local pos = worldedit.pos2[name]
|
||||
worldedit.pos2[name] = vector.add(deltavector, pos)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- Returns two vectors with the directions for volumetric expansion
|
||||
worldedit.get_expansion_directions = function(mark1, mark2)
|
||||
if mark1 == nil or mark2 == nil then
|
||||
return
|
||||
end
|
||||
local dir1 = vector.new()
|
||||
local dir2 = vector.new()
|
||||
|
||||
if mark1.x < mark2.x then
|
||||
dir1.x = -1
|
||||
dir2.x = 1
|
||||
else
|
||||
dir1.x = 1
|
||||
dir2.x = -1
|
||||
end
|
||||
if mark1.y < mark2.y then
|
||||
dir1.y = -1
|
||||
dir2.y = 1
|
||||
else
|
||||
dir1.y = 1
|
||||
dir2.y = -1
|
||||
end
|
||||
if mark1.z < mark2.z then
|
||||
dir1.z = -1
|
||||
dir2.z = 1
|
||||
else
|
||||
dir1.z = 1
|
||||
dir2.z = -1
|
||||
end
|
||||
return dir1, dir2
|
||||
end
|
||||
|
||||
|
||||
-- Return the marker that is closest to the player
|
||||
worldedit.marker_get_closest_to_player = function(name)
|
||||
local playerpos = minetest.get_player_by_name(name):get_pos()
|
||||
local dist1 = vector.distance(playerpos, worldedit.pos1[name])
|
||||
local dist2 = vector.distance(playerpos, worldedit.pos2[name])
|
||||
|
||||
if dist1 < dist2 then
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Returns the closest marker to the specified axis and direction
|
||||
worldedit.marker_get_closest_to_axis = function(name, axis, direction)
|
||||
local pos1 = vector.new()
|
||||
local pos2 = vector.new()
|
||||
|
||||
if direction ~= 1 and direction ~= -1 then
|
||||
return nil
|
||||
end
|
||||
|
||||
if axis == 'x' then
|
||||
pos1.x = worldedit.pos1[name].x * direction
|
||||
pos2.x = worldedit.pos2[name].x * direction
|
||||
if pos1.x > pos2.x then
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
end
|
||||
elseif axis == 'y' then
|
||||
pos1.y = worldedit.pos1[name].y * direction
|
||||
pos2.y = worldedit.pos2[name].y * direction
|
||||
if pos1.y > pos2.y then
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
end
|
||||
elseif axis == 'z' then
|
||||
pos1.z = worldedit.pos1[name].z * direction
|
||||
pos2.z = worldedit.pos2[name].z * direction
|
||||
if pos1.z > pos2.z then
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Translates up, down, left, right, front, back to their corresponding axes and
|
||||
-- directions according to faced direction
|
||||
worldedit.translate_direction = function(name, direction)
|
||||
local axis, dir = worldedit.player_axis(name)
|
||||
local resaxis, resdir
|
||||
|
||||
if direction == "up" then
|
||||
return 'y', 1
|
||||
end
|
||||
|
||||
if direction == "down" then
|
||||
return 'y', -1
|
||||
end
|
||||
|
||||
if direction == "front" then
|
||||
if axis == "y" then
|
||||
resaxis = nil
|
||||
resdir = nil
|
||||
else
|
||||
resaxis = axis
|
||||
resdir = dir
|
||||
end
|
||||
end
|
||||
|
||||
if direction == "back" then
|
||||
if axis == "y" then
|
||||
resaxis = nil
|
||||
resdir = nil
|
||||
else
|
||||
resaxis = axis
|
||||
resdir = -dir
|
||||
end
|
||||
end
|
||||
|
||||
if direction == "left" then
|
||||
if axis == 'x' then
|
||||
resaxis = 'z'
|
||||
resdir = dir
|
||||
elseif axis == 'z' then
|
||||
resaxis = 'x'
|
||||
resdir = -dir
|
||||
end
|
||||
end
|
||||
|
||||
if direction == "right" then
|
||||
if axis == 'x' then
|
||||
resaxis = 'z'
|
||||
resdir = -dir
|
||||
elseif axis == 'z' then
|
||||
resaxis = 'x'
|
||||
resdir = dir
|
||||
end
|
||||
end
|
||||
|
||||
return resaxis, resdir
|
||||
end
|
@ -1,19 +1,40 @@
|
||||
assert(minetest.get_voxel_manip, string.rep(">", 300) .. "HEY YOU! YES, YOU OVER THERE. THIS VERSION OF WORLDEDIT REQUIRES MINETEST 0.4.8 OR LATER! YOU HAVE AN OLD VERSION." .. string.rep("<", 300))
|
||||
--- WorldEdit mod for the Minetest engine
|
||||
-- @module worldedit
|
||||
-- @release 1.3
|
||||
-- @copyright 2012 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote)
|
||||
-- @license GNU Affero General Public License version 3 (AGPLv3)
|
||||
-- @author sfan5
|
||||
-- @author Anthony Zang (Uberi/Temperest)
|
||||
-- @author Bret O'Donnel (cornernote)
|
||||
-- @author ShadowNinja
|
||||
|
||||
|
||||
worldedit = {}
|
||||
|
||||
local ver = {major=1, minor=3}
|
||||
worldedit.version = ver
|
||||
worldedit.version_string = string.format("%d.%d", ver.major, ver.minor)
|
||||
|
||||
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
local loadmodule = function(path)
|
||||
local file = io.open(path)
|
||||
if not file then
|
||||
return
|
||||
end
|
||||
local function load_module(path)
|
||||
local file = io.open(path, "r")
|
||||
if not file then return end
|
||||
file:close()
|
||||
return dofile(path)
|
||||
end
|
||||
|
||||
loadmodule(path .. "/manipulations.lua")
|
||||
loadmodule(path .. "/primitives.lua")
|
||||
loadmodule(path .. "/visualization.lua")
|
||||
loadmodule(path .. "/serialization.lua")
|
||||
loadmodule(path .. "/code.lua")
|
||||
loadmodule(path .. "/compatibility.lua")
|
||||
dofile(path .. "/common.lua")
|
||||
load_module(path .. "/manipulations.lua")
|
||||
load_module(path .. "/primitives.lua")
|
||||
load_module(path .. "/visualization.lua")
|
||||
load_module(path .. "/serialization.lua")
|
||||
load_module(path .. "/code.lua")
|
||||
load_module(path .. "/compatibility.lua")
|
||||
load_module(path .. "/cuboid.lua")
|
||||
|
||||
|
||||
if minetest.settings:get_bool("log_mods") then
|
||||
print("[WorldEdit] Loaded!")
|
||||
end
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
2
worldedit/mod.conf
Normal file
2
worldedit/mod.conf
Normal file
@ -0,0 +1,2 @@
|
||||
name = worldedit
|
||||
description = WorldEdit main functionality & API
|
@ -1,478 +1,329 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest --local copy of global
|
||||
--- Functions for creating primitive shapes.
|
||||
-- @module worldedit.primitives
|
||||
|
||||
--adds a hollow sphere centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.hollow_sphere = function(pos, radius, nodename)
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {x=pos.x - radius, y=pos.y - radius, z=pos.z - radius}
|
||||
local pos2 = {x=pos.x + radius, y=pos.y + radius, z=pos.z + radius}
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
local mh = worldedit.manip_helpers
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||
local zstride, ystride = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
|
||||
for y = -radius, radius do
|
||||
local newy = newz + (y + offsety) * ystride
|
||||
for x = -radius, radius do
|
||||
local squared = x * x + y * y + z * z
|
||||
if squared >= min_radius and squared <= max_radius then --position is on surface of sphere
|
||||
local i = newy + (x + offsetx)
|
||||
nodes[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--- Adds a cube
|
||||
-- @param pos Position of ground level center of cube
|
||||
-- @param width Cube width. (x)
|
||||
-- @param height Cube height. (y)
|
||||
-- @param length Cube length. (z)
|
||||
-- @param node_name Name of node to make cube of.
|
||||
-- @param hollow Whether the cube should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
function worldedit.cube(pos, width, height, length, node_name, hollow)
|
||||
-- Set up voxel manipulator
|
||||
local basepos = vector.subtract(pos, {x=math.floor(width/2), y=0, z=math.floor(length/2)})
|
||||
local manip, area = mh.init(basepos, vector.add(basepos, {x=width, y=height, z=length}))
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a sphere centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.sphere = function(pos, radius, nodename)
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {x=pos.x - radius, y=pos.y - radius, z=pos.z - radius}
|
||||
local pos2 = {x=pos.x + radius, y=pos.y + radius, z=pos.z + radius}
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
local max_radius = radius * (radius + 1)
|
||||
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||
local zstride, ystride = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
|
||||
for y = -radius, radius do
|
||||
local newy = newz + (y + offsety) * ystride
|
||||
for x = -radius, radius do
|
||||
if x * x + y * y + z * z <= max_radius then --position is inside sphere
|
||||
local i = newy + (x + offsetx)
|
||||
nodes[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a hollow dome centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.hollow_dome = function(pos, radius, nodename)
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {x=pos.x - radius, y=pos.y, z=pos.z - radius}
|
||||
local pos2 = {x=pos.x + radius, y=pos.y + radius, z=pos.z + radius}
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
local miny, maxy = 0, radius
|
||||
if radius < 0 then
|
||||
radius = -radius
|
||||
miny, maxy = -radius, 0
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||
local zstride, ystride = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
|
||||
for y = miny, maxy do
|
||||
local newy = newz + (y + offsety) * ystride
|
||||
for x = -radius, radius do
|
||||
local squared = x * x + y * y + z * z
|
||||
if squared >= min_radius and squared <= max_radius then --position is on surface of sphere
|
||||
local i = newy + (x + offsetx)
|
||||
nodes[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a dome centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.dome = function(pos, radius, nodename)
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {x=pos.x - radius, y=pos.y, z=pos.z - radius}
|
||||
local pos2 = {x=pos.x + radius, y=pos.y + radius, z=pos.z + radius}
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
local miny, maxy = 0, radius
|
||||
if radius < 0 then
|
||||
radius = -radius
|
||||
miny, maxy = -radius, 0
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
local max_radius = radius * (radius + 1)
|
||||
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||
local zstride, ystride = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
|
||||
for y = miny, maxy do
|
||||
local newy = newz + (y + offsety) * ystride
|
||||
for x = -radius, radius do
|
||||
if x * x + y * y + z * z <= max_radius then --position is inside sphere
|
||||
local i = newy + (x + offsetx)
|
||||
nodes[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) --wip: rewrite this using voxelmanip
|
||||
local other1, other2
|
||||
if axis == "x" then
|
||||
other1, other2 = "y", "z"
|
||||
elseif axis == "y" then
|
||||
other1, other2 = "x", "z"
|
||||
else --axis == "z"
|
||||
other1, other2 = "x", "y"
|
||||
end
|
||||
|
||||
--handle negative lengths
|
||||
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
currentpos[axis] = currentpos[axis] - length
|
||||
end
|
||||
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {
|
||||
[axis]=currentpos[axis],
|
||||
[other1]=currentpos[other1] - radius,
|
||||
[other2]=currentpos[other2] - radius
|
||||
}
|
||||
local pos2 = {
|
||||
[axis]=currentpos[axis] + length - 1,
|
||||
[other1]=currentpos[other1] + radius,
|
||||
[other2]=currentpos[other2] + radius
|
||||
}
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
--create schematic for single node column along the axis
|
||||
local node = {name=nodename, param1=0, param2=0}
|
||||
local nodes = {}
|
||||
for i = 1, length do
|
||||
nodes[i] = node
|
||||
end
|
||||
local schematic = {size={[axis]=length, [other1]=1, [other2]=1}, data=nodes}
|
||||
|
||||
--add columns in a circle around axis to form cylinder
|
||||
local place_schematic = minetest.place_schematic
|
||||
local count = 0
|
||||
local offset1, offset2 = 0, radius
|
||||
local delta = -radius
|
||||
while offset1 <= offset2 do
|
||||
--add node at each octant
|
||||
local first1, first2 = pos[other1] + offset1, pos[other1] - offset1
|
||||
local second1, second2 = pos[other2] + offset2, pos[other2] - offset2
|
||||
currentpos[other1], currentpos[other2] = first1, second1
|
||||
place_schematic(currentpos, schematic) --octant 1
|
||||
currentpos[other1] = first2
|
||||
place_schematic(currentpos, schematic) --octant 4
|
||||
currentpos[other2] = second2
|
||||
place_schematic(currentpos, schematic) --octant 5
|
||||
currentpos[other1] = first1
|
||||
place_schematic(currentpos, schematic) --octant 8
|
||||
local first1, first2 = pos[other1] + offset2, pos[other1] - offset2
|
||||
local second1, second2 = pos[other2] + offset1, pos[other2] - offset1
|
||||
currentpos[other1], currentpos[other2] = first1, second1
|
||||
place_schematic(currentpos, schematic) --octant 2
|
||||
currentpos[other1] = first2
|
||||
place_schematic(currentpos, schematic) --octant 3
|
||||
currentpos[other2] = second2
|
||||
place_schematic(currentpos, schematic) --octant 6
|
||||
currentpos[other1] = first1
|
||||
place_schematic(currentpos, schematic) --octant 7
|
||||
|
||||
count = count + 8 --wip: broken because sometimes currentpos is repeated
|
||||
|
||||
--move to next location
|
||||
delta = delta + (offset1 * 2) + 1
|
||||
if delta >= 0 then
|
||||
offset2 = offset2 - 1
|
||||
delta = delta - (offset2 * 2)
|
||||
end
|
||||
offset1 = offset1 + 1
|
||||
end
|
||||
count = count * length --apply the length to the number of nodes
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.cylinder = function(pos, axis, length, radius, nodename)
|
||||
local other1, other2
|
||||
if axis == "x" then
|
||||
other1, other2 = "y", "z"
|
||||
elseif axis == "y" then
|
||||
other1, other2 = "x", "z"
|
||||
else --axis == "z"
|
||||
other1, other2 = "x", "y"
|
||||
end
|
||||
|
||||
--handle negative lengths
|
||||
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
currentpos[axis] = currentpos[axis] - length
|
||||
end
|
||||
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local pos1 = {
|
||||
[axis]=currentpos[axis],
|
||||
[other1]=currentpos[other1] - radius,
|
||||
[other2]=currentpos[other2] - radius
|
||||
}
|
||||
local pos2 = {
|
||||
[axis]=currentpos[axis] + length - 1,
|
||||
[other1]=currentpos[other1] + radius,
|
||||
[other2]=currentpos[other2] + radius
|
||||
}
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
local max_radius = radius * (radius + 1)
|
||||
-- Add cube
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||
local offset = {x=currentpos.x - emerged_pos1.x, y=currentpos.y - emerged_pos1.y, z=currentpos.z - emerged_pos1.z}
|
||||
local min_slice, max_slice = offset[axis], offset[axis] + length - 1
|
||||
local offset = vector.subtract(basepos, area.MinEdge)
|
||||
local count = 0
|
||||
for index2 = -radius, radius do
|
||||
local newindex2 = (index2 + offset[other1]) * stride[other1] + 1 --offset contributed by other axis 1 plus 1 to make it 1-indexed
|
||||
for index3 = -radius, radius do
|
||||
local newindex3 = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||
if index2 * index2 + index3 * index3 <= max_radius then
|
||||
for index1 = min_slice, max_slice do --add column along axis
|
||||
local i = newindex3 + index1 * stride[axis]
|
||||
nodes[i] = node_id
|
||||
|
||||
for z = 0, length-1 do
|
||||
local index_z = (offset.z + z) * stride.z + 1 -- +1 for 1-based indexing
|
||||
for y = 0, height-1 do
|
||||
local index_y = index_z + (offset.y + y) * stride.y
|
||||
for x = 0, width-1 do
|
||||
local is_wall = z == 0 or z == length-1
|
||||
or y == 0 or y == height-1
|
||||
or x == 0 or x == width-1
|
||||
if not hollow or is_wall then
|
||||
local i = index_y + (offset.x + x)
|
||||
data[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
count = count + length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
mh.finish(manip, data)
|
||||
return count
|
||||
end
|
||||
|
||||
--- Adds a sphere of `node_name` centered at `pos`.
|
||||
-- @param pos Position to center sphere at.
|
||||
-- @param radius Sphere radius.
|
||||
-- @param node_name Name of node to make shere of.
|
||||
-- @param hollow Whether the sphere should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
function worldedit.sphere(pos, radius, node_name, hollow)
|
||||
local manip, area = mh.init_radius(pos, radius)
|
||||
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
-- Fill selected area with node
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z
|
||||
local stride_z, stride_y = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
-- Offset contributed by z plus 1 to make it 1-indexed
|
||||
local new_z = (z + offset_z) * stride_z + 1
|
||||
for y = -radius, radius do
|
||||
local new_y = new_z + (y + offset_y) * stride_y
|
||||
for x = -radius, radius do
|
||||
local squared = x * x + y * y + z * z
|
||||
if squared <= max_radius and (not hollow or squared >= min_radius) then
|
||||
-- Position is on surface of sphere
|
||||
local i = new_y + (x + offset_x)
|
||||
data[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mh.finish(manip, data)
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a pyramid centered at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.pyramid = function(pos, axis, height, nodename)
|
||||
local other1, other2
|
||||
if axis == "x" then
|
||||
other1, other2 = "y", "z"
|
||||
elseif axis == "y" then
|
||||
other1, other2 = "x", "z"
|
||||
else --axis == "z"
|
||||
other1, other2 = "x", "y"
|
||||
|
||||
--- Adds a dome.
|
||||
-- @param pos Position to center dome at.
|
||||
-- @param radius Dome radius. Negative for concave domes.
|
||||
-- @param node_name Name of node to make dome of.
|
||||
-- @param hollow Whether the dome should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
-- TODO: Add axis option.
|
||||
function worldedit.dome(pos, radius, node_name, hollow)
|
||||
local min_y, max_y = 0, radius
|
||||
if radius < 0 then
|
||||
radius = -radius
|
||||
min_y, max_y = -radius, 0
|
||||
end
|
||||
|
||||
local pos1 = {x=pos.x - height, y=pos.y - height, z=pos.z - height}
|
||||
local pos2 = {x=pos.x + height, y=pos.y + height, z=pos.z + height}
|
||||
local manip, area = mh.init_axis_radius(pos, "y", radius)
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
--handle inverted pyramids
|
||||
local startaxis, endaxis, step
|
||||
-- Add dome
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z
|
||||
local stride_z, stride_y = area.zstride, area.ystride
|
||||
local count = 0
|
||||
for z = -radius, radius do
|
||||
local new_z = (z + offset_z) * stride_z + 1 --offset contributed by z plus 1 to make it 1-indexed
|
||||
for y = min_y, max_y do
|
||||
local new_y = new_z + (y + offset_y) * stride_y
|
||||
for x = -radius, radius do
|
||||
local squared = x * x + y * y + z * z
|
||||
if squared <= max_radius and (not hollow or squared >= min_radius) then
|
||||
-- Position is in dome
|
||||
local i = new_y + (x + offset_x)
|
||||
data[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mh.finish(manip, data)
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--- Adds a cylinder.
|
||||
-- @param pos Position to center base of cylinder at.
|
||||
-- @param axis Axis ("x", "y", or "z")
|
||||
-- @param length Cylinder length.
|
||||
-- @param radius1 Cylinder base radius.
|
||||
-- @param radius2 Cylinder top radius.
|
||||
-- @param node_name Name of node to make cylinder of.
|
||||
-- @param hollow Whether the cylinder should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
function worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
|
||||
-- Backwards compatibility
|
||||
if type(radius2) == "string" then
|
||||
hollow = node_name
|
||||
node_name = radius2
|
||||
radius2 = radius1 -- straight cylinder
|
||||
end
|
||||
|
||||
-- Handle negative lengths
|
||||
local current_pos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
current_pos[axis] = current_pos[axis] - length
|
||||
radius1, radius2 = radius2, radius1
|
||||
end
|
||||
|
||||
-- Set up voxel manipulator
|
||||
local manip, area = mh.init_axis_radius_length(current_pos, axis, math.max(radius1, radius2), length)
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
-- Add desired shape (anything inbetween cylinder & cone)
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||
local offset = {
|
||||
x = current_pos.x - area.MinEdge.x,
|
||||
y = current_pos.y - area.MinEdge.y,
|
||||
z = current_pos.z - area.MinEdge.z,
|
||||
}
|
||||
local count = 0
|
||||
for i = 0, length - 1 do
|
||||
-- Calulate radius for this "height" in the cylinder
|
||||
local radius = radius1 + (radius2 - radius1) * (i + 1) / length
|
||||
radius = math.floor(radius + 0.5) -- round
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
|
||||
for index2 = -radius, radius do
|
||||
-- Offset contributed by other axis 1 plus 1 to make it 1-indexed
|
||||
local new_index2 = (index2 + offset[other1]) * stride[other1] + 1
|
||||
for index3 = -radius, radius do
|
||||
local new_index3 = new_index2 + (index3 + offset[other2]) * stride[other2]
|
||||
local squared = index2 * index2 + index3 * index3
|
||||
if squared <= max_radius and (not hollow or squared >= min_radius) then
|
||||
-- Position is in cylinder, add node here
|
||||
local vi = new_index3 + (offset[axis] + i) * stride[axis]
|
||||
data[vi] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mh.finish(manip, data)
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
--- Adds a pyramid.
|
||||
-- @param pos Position to center base of pyramid at.
|
||||
-- @param axis Axis ("x", "y", or "z")
|
||||
-- @param height Pyramid height.
|
||||
-- @param node_name Name of node to make pyramid of.
|
||||
-- @param hollow Whether the pyramid should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
function worldedit.pyramid(pos, axis, height, node_name, hollow)
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
|
||||
-- Set up voxel manipulator
|
||||
-- FIXME: passing negative <radius> causes mis-sorted pos to be passed
|
||||
-- into mh.init() which is technically not allowed but works
|
||||
local manip, area = mh.init_axis_radius(pos, axis, height)
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
-- Handle inverted pyramids
|
||||
local step
|
||||
if height > 0 then
|
||||
height = height - 1
|
||||
step = 1
|
||||
pos1[axis] = pos[axis] --upper half of box
|
||||
else
|
||||
height = height + 1
|
||||
step = -1
|
||||
pos2[axis] = pos[axis] --lower half of box
|
||||
end
|
||||
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
--fill selected area with node
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
-- Add pyramid
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||
local offset = {x=pos.x - emerged_pos1.x, y=pos.y - emerged_pos1.y, z=pos.z - emerged_pos1.z}
|
||||
local size = height * step
|
||||
local offset = {
|
||||
x = pos.x - area.MinEdge.x,
|
||||
y = pos.y - area.MinEdge.y,
|
||||
z = pos.z - area.MinEdge.z,
|
||||
}
|
||||
local size = math.abs(height * step)
|
||||
local count = 0
|
||||
for index1 = 0, height, step do --go through each level of the pyramid
|
||||
local newindex1 = (index1 + offset[axis]) * stride[axis] + 1 --offset contributed by axis plus 1 to make it 1-indexed
|
||||
-- For each level of the pyramid
|
||||
for index1 = 0, height, step do
|
||||
-- Offset contributed by axis plus 1 to make it 1-indexed
|
||||
local new_index1 = (index1 + offset[axis]) * stride[axis] + 1
|
||||
for index2 = -size, size do
|
||||
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
||||
local new_index2 = new_index1 + (index2 + offset[other1]) * stride[other1]
|
||||
for index3 = -size, size do
|
||||
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||
nodes[i] = node_id
|
||||
local i = new_index2 + (index3 + offset[other2]) * stride[other2]
|
||||
if (not hollow or size - math.abs(index2) < 2 or size - math.abs(index3) < 2) then
|
||||
data[i] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
count = count + (size * 2 + 1) ^ 2
|
||||
size = size - 1
|
||||
end
|
||||
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
mh.finish(manip, data)
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
--adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
|
||||
worldedit.spiral = function(pos, length, height, spacer, nodename)
|
||||
--- Adds a spiral.
|
||||
-- @param pos Position to center spiral at.
|
||||
-- @param length Spral length.
|
||||
-- @param height Spiral height.
|
||||
-- @param spacer Space between walls.
|
||||
-- @param node_name Name of node to make spiral of.
|
||||
-- @return Number of nodes added.
|
||||
-- TODO: Add axis option.
|
||||
function worldedit.spiral(pos, length, height, spacer, node_name)
|
||||
local extent = math.ceil(length / 2)
|
||||
local pos1 = {x=pos.x - extent, y=pos.y, z=pos.z - extent}
|
||||
local pos2 = {x=pos.x + extent, y=pos.y + height, z=pos.z + extent}
|
||||
|
||||
--set up voxel manipulator
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||
local manip, area = mh.init_axis_radius_length(pos, "y", extent, height)
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
--fill emerged area with ignore
|
||||
local nodes = {}
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||
nodes[i] = ignore
|
||||
end
|
||||
|
||||
--
|
||||
local node_id = minetest.get_content_id(nodename)
|
||||
-- Set up variables
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||
local i = offsetz * stride.z + offsety * stride.y + offsetx + 1
|
||||
local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z
|
||||
local i = offset_z * stride.z + offset_y * stride.y + offset_x + 1
|
||||
|
||||
--add first column
|
||||
-- Add first column
|
||||
local count = height
|
||||
local column = i
|
||||
for y = 1, height do
|
||||
nodes[column] = node_id
|
||||
data[column] = node_id
|
||||
column = column + stride.y
|
||||
end
|
||||
|
||||
--add spiral segments
|
||||
local axis, other = "x", "z"
|
||||
local sign = 1
|
||||
local count = height
|
||||
for segment = 1, length / spacer - 1 do --go through each segment except the last
|
||||
for index = 1, segment * spacer do --fill segment
|
||||
i = i + stride[axis] * sign
|
||||
-- Add spiral segments
|
||||
local stride_axis, stride_other = stride.x, stride.z
|
||||
local sign = -1
|
||||
local segment_length = 0
|
||||
spacer = spacer + 1
|
||||
-- Go through each segment except the last
|
||||
for segment = 1, math.floor(length / spacer) * 2 do
|
||||
-- Change sign and length every other turn starting with the first
|
||||
if segment % 2 == 1 then
|
||||
sign = -sign
|
||||
segment_length = segment_length + spacer
|
||||
end
|
||||
-- Fill segment
|
||||
for index = 1, segment_length do
|
||||
-- Move along the direction of the segment
|
||||
i = i + stride_axis * sign
|
||||
local column = i
|
||||
for y = 1, height do --add column
|
||||
nodes[column] = node_id
|
||||
-- Add column
|
||||
for y = 1, height do
|
||||
data[column] = node_id
|
||||
column = column + stride.y
|
||||
end
|
||||
count = count + height
|
||||
end
|
||||
axis, other = other, axis --swap axes
|
||||
if segment % 2 == 1 then --change sign every other turn
|
||||
sign = -sign
|
||||
end
|
||||
count = count + segment_length * height
|
||||
stride_axis, stride_other = stride_other, stride_axis -- Swap axes
|
||||
end
|
||||
|
||||
--add shorter final segment
|
||||
for index = 1, (math.floor(length / spacer) - 2) * spacer do
|
||||
i = i + stride[axis] * sign
|
||||
-- Add shorter final segment
|
||||
sign = -sign
|
||||
for index = 1, segment_length do
|
||||
i = i + stride_axis * sign
|
||||
local column = i
|
||||
for y = 1, height do --add column
|
||||
nodes[column] = node_id
|
||||
-- Add column
|
||||
for y = 1, height do
|
||||
data[column] = node_id
|
||||
column = column + stride.y
|
||||
end
|
||||
count = count + height
|
||||
end
|
||||
print(minetest.serialize(nodes))
|
||||
--update map nodes
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map()
|
||||
count = count + segment_length * height
|
||||
|
||||
mh.finish(manip, data)
|
||||
|
||||
return count
|
||||
end
|
@ -1,48 +1,74 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest --local copy of global
|
||||
--- Schematic serialization and deserialiation.
|
||||
-- @module worldedit.serialization
|
||||
|
||||
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
|
||||
worldedit.sort_pos = function(pos1, pos2)
|
||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||
if pos1.x > pos2.x then
|
||||
pos2.x, pos1.x = pos1.x, pos2.x
|
||||
end
|
||||
if pos1.y > pos2.y then
|
||||
pos2.y, pos1.y = pos1.y, pos2.y
|
||||
end
|
||||
if pos1.z > pos2.z then
|
||||
pos2.z, pos1.z = pos1.z, pos2.z
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
worldedit.LATEST_SERIALIZATION_VERSION = 5
|
||||
local LATEST_SERIALIZATION_HEADER = worldedit.LATEST_SERIALIZATION_VERSION .. ":"
|
||||
|
||||
--determines the version of serialized data `value`, returning the version as a positive integer or 0 for unknown versions
|
||||
worldedit.valueversion = function(value)
|
||||
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then --previous list format
|
||||
return 3
|
||||
|
||||
--[[
|
||||
Serialization version history:
|
||||
1: Original format. Serialized Lua table with a weird linked format...
|
||||
2: Position and node seperated into sub-tables in fields `1` and `2`.
|
||||
3: List of nodes, one per line, with fields seperated by spaces.
|
||||
Format: <X> <Y> <Z> <Name> <Param1> <Param2>
|
||||
4: Serialized Lua table containing a list of nodes with `x`, `y`, `z`,
|
||||
`name`, `param1`, `param2`, and `meta` fields.
|
||||
5: Added header and made `param1`, `param2`, and `meta` fields optional.
|
||||
Header format: <Version>,<ExtraHeaderField1>,...:<Content>
|
||||
--]]
|
||||
|
||||
|
||||
--- Reads the header of serialized data.
|
||||
-- @param value Serialized WorldEdit data.
|
||||
-- @return The version as a positive natural number, or 0 for unknown versions.
|
||||
-- @return Extra header fields as a list of strings, or nil if not supported.
|
||||
-- @return Content (data after header).
|
||||
function worldedit.read_header(value)
|
||||
if value:find("^[0-9]+[,:]") then
|
||||
local header_end = value:find(":", 1, true)
|
||||
local header = value:sub(1, header_end - 1):split(",")
|
||||
local version = tonumber(header[1])
|
||||
table.remove(header, 1)
|
||||
local content = value:sub(header_end + 1)
|
||||
return version, header, content
|
||||
end
|
||||
-- Old versions that didn't include a header with a version number
|
||||
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then -- List format
|
||||
return 3, nil, value
|
||||
elseif value:find("^[^\"']+%{%d+%}") then
|
||||
if value:find("%[\"meta\"%]") then --previous meta flat table format
|
||||
return 2
|
||||
if value:find("%[\"meta\"%]") then -- Meta flat table format
|
||||
return 2, nil, value
|
||||
end
|
||||
return 1 --original flat table format
|
||||
elseif value:find("%{") then --current nested table format
|
||||
return 4
|
||||
return 1, nil, value -- Flat table format
|
||||
elseif value:find("%{") then -- Raw nested table format
|
||||
return 4, nil, value
|
||||
end
|
||||
return 0 --unknown format
|
||||
return nil
|
||||
end
|
||||
|
||||
--converts the region defined by positions `pos1` and `pos2` into a single string, returning the serialized data and the number of nodes serialized
|
||||
worldedit.serialize = function(pos1, pos2)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
--- Converts the region defined by positions `pos1` and `pos2`
|
||||
-- into a single string.
|
||||
-- @return The serialized data.
|
||||
-- @return The number of nodes serialized.
|
||||
function worldedit.serialize(pos1, pos2)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local get_node, get_meta, hash_node_position =
|
||||
minetest.get_node, minetest.get_meta, minetest.hash_node_position
|
||||
|
||||
-- Find the positions which have metadata
|
||||
local has_meta = {}
|
||||
local meta_positions = minetest.find_nodes_with_meta(pos1, pos2)
|
||||
for i = 1, #meta_positions do
|
||||
has_meta[hash_node_position(meta_positions[i])] = true
|
||||
end
|
||||
|
||||
local pos = {x=pos1.x, y=0, z=0}
|
||||
local count = 0
|
||||
local result = {}
|
||||
local get_node, get_meta = minetest.get_node, minetest.get_meta
|
||||
while pos.x <= pos2.x do
|
||||
pos.y = pos1.y
|
||||
while pos.y <= pos2.y do
|
||||
@ -51,12 +77,19 @@ worldedit.serialize = function(pos1, pos2)
|
||||
local node = get_node(pos)
|
||||
if node.name ~= "air" and node.name ~= "ignore" then
|
||||
count = count + 1
|
||||
local meta = get_meta(pos):to_table()
|
||||
|
||||
--convert metadata itemstacks to itemstrings
|
||||
for name, inventory in pairs(meta.inventory) do
|
||||
for index, stack in ipairs(inventory) do
|
||||
inventory[index] = stack.to_string and stack:to_string() or stack
|
||||
local meta
|
||||
if has_meta[hash_node_position(pos)] then
|
||||
meta = get_meta(pos):to_table()
|
||||
|
||||
-- Convert metadata item stacks to item strings
|
||||
for _, invlist in pairs(meta.inventory) do
|
||||
for index = 1, #invlist do
|
||||
local itemstack = invlist[index]
|
||||
if itemstack.to_string then
|
||||
invlist[index] = itemstack:to_string()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -65,8 +98,8 @@ worldedit.serialize = function(pos1, pos2)
|
||||
y = pos.y - pos1.y,
|
||||
z = pos.z - pos1.z,
|
||||
name = node.name,
|
||||
param1 = node.param1,
|
||||
param2 = node.param2,
|
||||
param1 = node.param1 ~= 0 and node.param1 or nil,
|
||||
param2 = node.param2 ~= 0 and node.param2 or nil,
|
||||
meta = meta,
|
||||
}
|
||||
end
|
||||
@ -76,198 +109,147 @@ worldedit.serialize = function(pos1, pos2)
|
||||
end
|
||||
pos.x = pos.x + 1
|
||||
end
|
||||
result = minetest.serialize(result) --convert entries to a string
|
||||
return result, count
|
||||
-- Serialize entries
|
||||
result = minetest.serialize(result)
|
||||
return LATEST_SERIALIZATION_HEADER .. result, count
|
||||
end
|
||||
|
||||
--determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`, returning the two corner positions and the number of nodes
|
||||
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
|
||||
worldedit.allocate = function(originpos, value)
|
||||
-- Contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile)
|
||||
-- by ChillCode, available under the MIT license.
|
||||
local function deserialize_workaround(content)
|
||||
local nodes
|
||||
if not jit then
|
||||
nodes = minetest.deserialize(content, true)
|
||||
else
|
||||
-- XXX: This is a filthy hack that works surprisingly well
|
||||
-- in LuaJIT, `minetest.deserialize` will fail due to the register limit
|
||||
nodes = {}
|
||||
content = content:gsub("^%s*return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data
|
||||
-- remove string contents strings while preserving their length
|
||||
local escaped = content:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
local startpos, startpos1 = 1, 1
|
||||
local endpos
|
||||
while true do -- go through each individual node entry (except the last)
|
||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||
if not startpos then
|
||||
break
|
||||
end
|
||||
local current = content:sub(startpos1, startpos)
|
||||
local entry = minetest.deserialize("return " .. current, true)
|
||||
table.insert(nodes, entry)
|
||||
startpos, startpos1 = endpos, endpos
|
||||
end
|
||||
local entry = minetest.deserialize("return " .. content:sub(startpos1), true) -- process the last entry
|
||||
table.insert(nodes, entry)
|
||||
end
|
||||
return nodes
|
||||
end
|
||||
|
||||
--- Loads the schematic in `value` into a node list in the latest format.
|
||||
-- @return A node list in the latest format, or nil on failure.
|
||||
local function load_schematic(value)
|
||||
local version, header, content = worldedit.read_header(value)
|
||||
local nodes = {}
|
||||
if version == 1 or version == 2 then -- Original flat table format
|
||||
local tables = minetest.deserialize(content, true)
|
||||
if not tables then return nil end
|
||||
|
||||
-- Transform the node table into an array of nodes
|
||||
for i = 1, #tables do
|
||||
for j, v in pairs(tables[i]) do
|
||||
if type(v) == "table" then
|
||||
tables[i][j] = tables[v[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
nodes = tables[1]
|
||||
|
||||
if version == 1 then --original flat table format
|
||||
for i, entry in ipairs(nodes) do
|
||||
local pos = entry[1]
|
||||
entry.x, entry.y, entry.z = pos.x, pos.y, pos.z
|
||||
entry[1] = nil
|
||||
local node = entry[2]
|
||||
entry.name, entry.param1, entry.param2 = node.name, node.param1, node.param2
|
||||
entry[2] = nil
|
||||
end
|
||||
end
|
||||
elseif version == 3 then -- List format
|
||||
for x, y, z, name, param1, param2 in content:gmatch(
|
||||
"([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+" ..
|
||||
"([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do
|
||||
param1, param2 = tonumber(param1), tonumber(param2)
|
||||
table.insert(nodes, {
|
||||
x = tonumber(x),
|
||||
y = tonumber(y),
|
||||
z = tonumber(z),
|
||||
name = name,
|
||||
param1 = param1 ~= 0 and param1 or nil,
|
||||
param2 = param2 ~= 0 and param2 or nil,
|
||||
})
|
||||
end
|
||||
elseif version == 4 or version == 5 then -- Nested table format
|
||||
nodes = deserialize_workaround(content)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
return nodes
|
||||
end
|
||||
|
||||
--- Determines the volume the nodes represented by string `value` would occupy
|
||||
-- if deserialized at `origin_pos`.
|
||||
-- @return Low corner position.
|
||||
-- @return High corner position.
|
||||
-- @return The number of nodes.
|
||||
function worldedit.allocate(origin_pos, value)
|
||||
local nodes = load_schematic(value)
|
||||
if not nodes or #nodes == 0 then return nil end
|
||||
return worldedit.allocate_with_nodes(origin_pos, nodes)
|
||||
end
|
||||
|
||||
|
||||
-- Internal
|
||||
function worldedit.allocate_with_nodes(origin_pos, nodes)
|
||||
local huge = math.huge
|
||||
local pos1x, pos1y, pos1z = huge, huge, huge
|
||||
local pos2x, pos2y, pos2z = -huge, -huge, -huge
|
||||
local originx, originy, originz = originpos.x, originpos.y, originpos.z
|
||||
local count = 0
|
||||
local version = worldedit.valueversion(value)
|
||||
if version == 1 or version == 2 then --flat table format
|
||||
--obtain the node table
|
||||
local get_tables = loadstring(value)
|
||||
if get_tables then --error loading value
|
||||
return originpos, originpos, count
|
||||
end
|
||||
local tables = get_tables()
|
||||
|
||||
--transform the node table into an array of nodes
|
||||
for i = 1, #tables do
|
||||
for j, v in pairs(tables[i]) do
|
||||
if type(v) == "table" then
|
||||
tables[i][j] = tables[v[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
local nodes = tables[1]
|
||||
|
||||
--check the node array
|
||||
count = #nodes
|
||||
if version == 1 then --original flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local pos = entry[1]
|
||||
local x, y, z = originx - pos.x, originy - pos.y, originz - pos.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
else --previous meta flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local x, y, z = originx - entry.x, originy - entry.y, originz - entry.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
end
|
||||
elseif version == 3 then --previous list format
|
||||
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
|
||||
x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
count = count + 1
|
||||
end
|
||||
elseif version == 4 then --current nested table format
|
||||
--wip: this is a filthy hack that works surprisingly well
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
local startpos, startpos1, endpos = 1, 1
|
||||
local nodes = {}
|
||||
while true do
|
||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||
if not startpos then
|
||||
break
|
||||
end
|
||||
local current = value:sub(startpos1, startpos)
|
||||
table.insert(nodes, minetest.deserialize("return " .. current))
|
||||
startpos, startpos1 = endpos, endpos
|
||||
end
|
||||
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
|
||||
|
||||
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
|
||||
|
||||
count = #nodes
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z
|
||||
for i, entry in ipairs(nodes) do
|
||||
local x, y, z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
|
||||
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
|
||||
return pos1, pos2, count
|
||||
return pos1, pos2, #nodes
|
||||
end
|
||||
|
||||
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
|
||||
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
|
||||
worldedit.deserialize = function(originpos, value)
|
||||
--make area stay loaded --wip: not very performant
|
||||
local pos1, pos2 = worldedit.allocate(originpos, value)
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
local originx, originy, originz = originpos.x, originpos.y, originpos.z
|
||||
--- Loads the nodes represented by string `value` at position `origin_pos`.
|
||||
-- @return The number of nodes deserialized.
|
||||
function worldedit.deserialize(origin_pos, value)
|
||||
local nodes = load_schematic(value)
|
||||
if not nodes then return nil end
|
||||
if #nodes == 0 then return #nodes end
|
||||
|
||||
local pos1, pos2 = worldedit.allocate_with_nodes(origin_pos, nodes)
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z
|
||||
local count = 0
|
||||
local add_node, get_meta = minetest.add_node, minetest.get_meta
|
||||
local version = worldedit.valueversion(value)
|
||||
if version == 1 or version == 2 then --original flat table format
|
||||
--obtain the node table
|
||||
local get_tables = loadstring(value)
|
||||
if not get_tables then --error loading value
|
||||
return count
|
||||
end
|
||||
local tables = get_tables()
|
||||
|
||||
--transform the node table into an array of nodes
|
||||
for i = 1, #tables do
|
||||
for j, v in pairs(tables[i]) do
|
||||
if type(v) == "table" then
|
||||
tables[i][j] = tables[v[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
local nodes = tables[1]
|
||||
|
||||
--load the node array
|
||||
count = #nodes
|
||||
if version == 1 then --original flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local pos = entry[1]
|
||||
pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z
|
||||
add_node(pos, entry[2])
|
||||
end
|
||||
else --previous meta flat table format
|
||||
for index = 1, #nodes do
|
||||
local entry = nodes[index]
|
||||
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
add_node(entry, entry) --entry acts both as position and as node
|
||||
get_meta(entry):from_table(entry.meta)
|
||||
end
|
||||
end
|
||||
elseif version == 3 then --previous list format
|
||||
local pos = {x=0, y=0, z=0}
|
||||
local node = {name="", param1=0, param2=0}
|
||||
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
|
||||
pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
|
||||
node.name, node.param1, node.param2 = name, param1, param2
|
||||
add_node(pos, node)
|
||||
count = count + 1
|
||||
end
|
||||
elseif version == 4 then --current nested table format
|
||||
--wip: this is a filthy hack that works surprisingly well
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
local startpos, startpos1, endpos = 1, 1
|
||||
local nodes = {}
|
||||
while true do
|
||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||
if not startpos then
|
||||
break
|
||||
end
|
||||
local current = value:sub(startpos1, startpos)
|
||||
table.insert(nodes, minetest.deserialize("return " .. current))
|
||||
startpos, startpos1 = endpos, endpos
|
||||
end
|
||||
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
|
||||
|
||||
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
|
||||
|
||||
--load the nodes
|
||||
count = #nodes
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
add_node(entry, entry) --entry acts both as position and as node
|
||||
end
|
||||
|
||||
--load the metadata
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
for i, entry in ipairs(nodes) do
|
||||
entry.x, entry.y, entry.z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z
|
||||
-- Entry acts as both position and node
|
||||
add_node(entry, entry)
|
||||
if entry.meta then
|
||||
get_meta(entry):from_table(entry.meta)
|
||||
end
|
||||
end
|
||||
return count
|
||||
return #nodes
|
||||
end
|
||||
|
||||
|
BIN
worldedit/textures/worldedit_wand.png
Normal file
BIN
worldedit/textures/worldedit_wand.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 442 B |
@ -1,57 +1,39 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest --local copy of global
|
||||
|
||||
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
|
||||
worldedit.sort_pos = function(pos1, pos2)
|
||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||
if pos1.x > pos2.x then
|
||||
pos2.x, pos1.x = pos1.x, pos2.x
|
||||
end
|
||||
if pos1.y > pos2.y then
|
||||
pos2.y, pos1.y = pos1.y, pos2.y
|
||||
end
|
||||
if pos1.z > pos2.z then
|
||||
pos2.z, pos1.z = pos1.z, pos2.z
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
--determines the volume of the region defined by positions `pos1` and `pos2`, returning the volume
|
||||
worldedit.volume = function(pos1, pos2)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
return (pos2.x - pos1.x + 1) * (pos2.y - pos1.y + 1) * (pos2.z - pos1.z + 1)
|
||||
end
|
||||
--- Functions for visibly hiding nodes
|
||||
-- @module worldedit.visualization
|
||||
|
||||
minetest.register_node("worldedit:placeholder", {
|
||||
drawtype = "airlike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
diggable = false,
|
||||
pointable = false,
|
||||
walkable = false,
|
||||
groups = {not_in_creative_inventory=1},
|
||||
})
|
||||
|
||||
--hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes hidden
|
||||
worldedit.hide = function(pos1, pos2)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
--- Hides all nodes in a region defined by positions `pos1` and `pos2` by
|
||||
-- non-destructively replacing them with invisible nodes.
|
||||
-- @return The number of nodes hidden.
|
||||
function worldedit.hide(pos1, pos2)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
local pos = {x=pos1.x, y=0, z=0}
|
||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||
local get_node, get_meta, swap_node = minetest.get_node,
|
||||
minetest.get_meta, minetest.swap_node
|
||||
while pos.x <= pos2.x do
|
||||
pos.y = pos1.y
|
||||
while pos.y <= pos2.y do
|
||||
pos.z = pos1.z
|
||||
while pos.z <= pos2.z do
|
||||
local node = get_node(pos)
|
||||
if node.name ~= "worldedit:placeholder" then
|
||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||
node.name = "worldedit:placeholder" --set node name
|
||||
add_node(pos, node) --add placeholder node
|
||||
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||
if node.name ~= "air" and node.name ~= "worldedit:placeholder" then
|
||||
-- Save the node's original name
|
||||
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
||||
-- Swap in placeholder node
|
||||
node.name = "worldedit:placeholder"
|
||||
swap_node(pos, node)
|
||||
end
|
||||
pos.z = pos.z + 1
|
||||
end
|
||||
@ -62,40 +44,44 @@ worldedit.hide = function(pos1, pos2)
|
||||
return worldedit.volume(pos1, pos2)
|
||||
end
|
||||
|
||||
--suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes suppressed
|
||||
worldedit.suppress = function(pos1, pos2, nodename)
|
||||
--ignore placeholder supression
|
||||
if nodename == "worldedit:placeholder" then
|
||||
--- Suppresses all instances of `node_name` in a region defined by positions
|
||||
-- `pos1` and `pos2` by non-destructively replacing them with invisible nodes.
|
||||
-- @return The number of nodes suppressed.
|
||||
function worldedit.suppress(pos1, pos2, node_name)
|
||||
-- Ignore placeholder supression
|
||||
if node_name == "worldedit:placeholder" then
|
||||
return 0
|
||||
end
|
||||
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
local nodes = minetest.find_nodes_in_area(pos1, pos2, nodename)
|
||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local nodes = minetest.find_nodes_in_area(pos1, pos2, node_name)
|
||||
local get_node, get_meta, swap_node = minetest.get_node,
|
||||
minetest.get_meta, minetest.swap_node
|
||||
for _, pos in ipairs(nodes) do
|
||||
local node = get_node(pos)
|
||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||
node.name = "worldedit:placeholder" --set node name
|
||||
add_node(pos, node) --add placeholder node
|
||||
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||
-- Save the node's original name
|
||||
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
||||
-- Swap in placeholder node
|
||||
node.name = "worldedit:placeholder"
|
||||
swap_node(pos, node)
|
||||
end
|
||||
return #nodes
|
||||
end
|
||||
|
||||
--highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes, returning the number of nodes found
|
||||
worldedit.highlight = function(pos1, pos2, nodename)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
--- Highlights all instances of `node_name` in a region defined by positions
|
||||
-- `pos1` and `pos2` by non-destructively hiding all other nodes.
|
||||
-- @return The number of nodes found.
|
||||
function worldedit.highlight(pos1, pos2, node_name)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
local pos = {x=pos1.x, y=0, z=0}
|
||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||
local get_node, get_meta, swap_node = minetest.get_node,
|
||||
minetest.get_meta, minetest.swap_node
|
||||
local count = 0
|
||||
while pos.x <= pos2.x do
|
||||
pos.y = pos1.y
|
||||
@ -103,14 +89,14 @@ worldedit.highlight = function(pos1, pos2, nodename)
|
||||
pos.z = pos1.z
|
||||
while pos.z <= pos2.z do
|
||||
local node = get_node(pos)
|
||||
if node.name == nodename then --node found
|
||||
if node.name == node_name then -- Node found
|
||||
count = count + 1
|
||||
elseif node.name ~= "worldedit:placeholder" then --hide other nodes
|
||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||
node.name = "worldedit:placeholder" --set node name
|
||||
add_node(pos, node) --add placeholder node
|
||||
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||
elseif node.name ~= "worldedit:placeholder" then -- Hide other nodes
|
||||
-- Save the node's original name
|
||||
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
||||
-- Swap in placeholder node
|
||||
node.name = "worldedit:placeholder"
|
||||
swap_node(pos, node)
|
||||
end
|
||||
pos.z = pos.z + 1
|
||||
end
|
||||
@ -121,22 +107,26 @@ worldedit.highlight = function(pos1, pos2, nodename)
|
||||
return count
|
||||
end
|
||||
|
||||
--restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`, returning the number of nodes restored
|
||||
worldedit.restore = function(pos1, pos2)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
-- Restores all nodes hidden with WorldEdit functions in a region defined
|
||||
-- by positions `pos1` and `pos2`.
|
||||
-- @return The number of nodes restored.
|
||||
function worldedit.restore(pos1, pos2)
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local nodes = minetest.find_nodes_in_area(pos1, pos2, "worldedit:placeholder")
|
||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||
local get_node, get_meta, swap_node = minetest.get_node,
|
||||
minetest.get_meta, minetest.swap_node
|
||||
for _, pos in ipairs(nodes) do
|
||||
local node = get_node(pos)
|
||||
local data = get_meta(pos):to_table() --obtain node metadata
|
||||
node.name = data.fields.worldedit_placeholder --set node name
|
||||
data.fields.worldedit_placeholder = nil --delete old nodename
|
||||
add_node(pos, node) --add original node
|
||||
get_meta(pos):from_table(data) --set original node metadata
|
||||
local meta = get_meta(pos)
|
||||
local data = meta:to_table()
|
||||
node.name = data.fields.worldedit_placeholder
|
||||
data.fields.worldedit_placeholder = nil
|
||||
meta:from_table(data)
|
||||
swap_node(pos, node)
|
||||
end
|
||||
return #nodes
|
||||
end
|
||||
|
||||
|
125
worldedit_brush/init.lua
Normal file
125
worldedit_brush/init.lua
Normal file
@ -0,0 +1,125 @@
|
||||
if minetest.raycast == nil then
|
||||
error(
|
||||
"worldedit_brush requires at least Minetest 5.0"
|
||||
)
|
||||
end
|
||||
|
||||
local BRUSH_MAX_DIST = 150
|
||||
local brush_on_use = function(itemstack, placer)
|
||||
local meta = itemstack:get_meta()
|
||||
local name = placer:get_player_name()
|
||||
|
||||
local cmd = meta:get_string("command")
|
||||
if cmd == "" then
|
||||
worldedit.player_notify(name,
|
||||
"This brush is not bound, use //brush to bind a command to it.")
|
||||
return false
|
||||
end
|
||||
|
||||
local cmddef = worldedit.registered_commands[cmd]
|
||||
if cmddef == nil then return false end -- shouldn't happen as //brush checks this
|
||||
|
||||
local has_privs, missing_privs = minetest.check_player_privs(name, cmddef.privs)
|
||||
if not has_privs then
|
||||
worldedit.player_notify(name,
|
||||
"Missing privileges: " .. table.concat(missing_privs, ", "))
|
||||
return false
|
||||
end
|
||||
|
||||
local raybegin = vector.add(placer:get_pos(),
|
||||
{x=0, y=placer:get_properties().eye_height, z=0})
|
||||
local rayend = vector.add(raybegin, vector.multiply(placer:get_look_dir(), BRUSH_MAX_DIST))
|
||||
local ray = minetest.raycast(raybegin, rayend, false, true)
|
||||
local pointed_thing = ray:next()
|
||||
if pointed_thing == nil then
|
||||
worldedit.player_notify(name, "Too far away.")
|
||||
return false
|
||||
end
|
||||
|
||||
assert(pointed_thing.type == "node")
|
||||
worldedit.pos1[name] = pointed_thing.under
|
||||
worldedit.pos2[name] = nil
|
||||
worldedit.marker_update(name)
|
||||
|
||||
-- this isn't really clean...
|
||||
local player_notify_old = worldedit.player_notify
|
||||
worldedit.player_notify = function(name, msg)
|
||||
if string.match(msg, "^%d") then return end -- discard "1234 nodes added."
|
||||
return player_notify_old(name, msg)
|
||||
end
|
||||
|
||||
assert(cmddef.require_pos < 2)
|
||||
local parsed = {cmddef.parse(meta:get_string("params"))}
|
||||
if not table.remove(parsed, 1) then return false end -- shouldn't happen
|
||||
|
||||
minetest.log("action", string.format("%s uses WorldEdit brush (//%s) at %s",
|
||||
name, cmd, minetest.pos_to_string(pointed_thing.under)))
|
||||
cmddef.func(name, unpack(parsed))
|
||||
|
||||
worldedit.player_notify = player_notify_old
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_tool(":worldedit:brush", {
|
||||
description = "WorldEdit Brush",
|
||||
inventory_image = "worldedit_brush.png",
|
||||
stack_max = 1, -- no need to stack these (metadata prevents this anyway)
|
||||
range = 0,
|
||||
on_use = function(itemstack, placer, pointed_thing)
|
||||
brush_on_use(itemstack, placer)
|
||||
return itemstack -- nothing consumed, nothing changed
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_command("brush", {
|
||||
privs = {worldedit=true},
|
||||
params = "none/<cmd> [parameters]",
|
||||
description = "Assign command to WorldEdit brush item",
|
||||
parse = function(param)
|
||||
local found, _, cmd, params = param:find("^([^%s]+)%s+(.+)$")
|
||||
if not found then
|
||||
params = ""
|
||||
found, _, cmd = param:find("^(.+)$")
|
||||
end
|
||||
if not found then
|
||||
return false
|
||||
end
|
||||
return true, cmd, params
|
||||
end,
|
||||
func = function(name, cmd, params)
|
||||
local itemstack = minetest.get_player_by_name(name):get_wielded_item()
|
||||
if itemstack == nil or itemstack:get_name() ~= "worldedit:brush" then
|
||||
worldedit.player_notify(name, "Not holding brush item.")
|
||||
return
|
||||
end
|
||||
|
||||
cmd = cmd:lower()
|
||||
local meta = itemstack:get_meta()
|
||||
if cmd == "none" then
|
||||
meta:from_table(nil)
|
||||
worldedit.player_notify(name, "Brush assignment cleared.")
|
||||
else
|
||||
local cmddef = worldedit.registered_commands[cmd]
|
||||
if cmddef == nil or cmddef.require_pos ~= 1 then
|
||||
worldedit.player_notify(name, "//" .. cmd .. " cannot be used with brushes")
|
||||
return
|
||||
end
|
||||
|
||||
-- Try parsing command params so we can give the user feedback
|
||||
local ok, err = cmddef.parse(params)
|
||||
if not ok then
|
||||
err = err or "invalid usage"
|
||||
worldedit.player_notify(name, "Error with brush command: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
meta:set_string("command", cmd)
|
||||
meta:set_string("params", params)
|
||||
local fullcmd = "//" .. cmd .. " " .. params
|
||||
meta:set_string("description",
|
||||
minetest.registered_tools["worldedit:brush"].description .. ": " .. fullcmd)
|
||||
worldedit.player_notify(name, "Brush assigned to command: " .. fullcmd)
|
||||
end
|
||||
minetest.get_player_by_name(name):set_wielded_item(itemstack)
|
||||
end,
|
||||
})
|
3
worldedit_brush/mod.conf
Normal file
3
worldedit_brush/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = worldedit_brush
|
||||
description = WorldEdit brush
|
||||
depends = worldedit, worldedit_commands
|
BIN
worldedit_brush/textures/worldedit_brush.png
Normal file
BIN
worldedit_brush/textures/worldedit_brush.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 337 B |
1
worldedit_commands/.gitignore
vendored
Normal file
1
worldedit_commands/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*~
|
266
worldedit_commands/cuboid.lua
Normal file
266
worldedit_commands/cuboid.lua
Normal file
@ -0,0 +1,266 @@
|
||||
worldedit.register_command("outset", {
|
||||
params = "[h/v] <amount>",
|
||||
description = "Outset the selected region.",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
|
||||
if find == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local hv_test = dir:find("[^hv]+")
|
||||
if hv_test ~= nil then
|
||||
return false, "Invalid direction."
|
||||
end
|
||||
|
||||
return true, dir, tonumber(amount)
|
||||
end,
|
||||
func = function(name, dir, amount)
|
||||
if dir == "" or dir == "hv" or dir == "vh" then
|
||||
assert(worldedit.cuboid_volumetric_expand(name, amount))
|
||||
elseif dir == "h" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', -1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', -1, amount))
|
||||
elseif dir == "v" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', -1, amount))
|
||||
else
|
||||
return false, "Invalid number of arguments"
|
||||
end
|
||||
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region outset by " .. amount .. " blocks"
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
worldedit.register_command("inset", {
|
||||
params = "[h/v] <amount>",
|
||||
description = "Inset the selected region.",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
|
||||
if find == nil then
|
||||
return false
|
||||
end
|
||||
if dir:find("[^hv]") ~= nil then
|
||||
return false, "Invalid direction."
|
||||
end
|
||||
|
||||
return true, dir, tonumber(amount)
|
||||
end,
|
||||
func = function(name, dir, amount)
|
||||
if dir == "" or dir == "vh" or dir == "hv" then
|
||||
assert(worldedit.cuboid_volumetric_expand(name, -amount))
|
||||
elseif dir == "h" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', -1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', -1, -amount))
|
||||
elseif dir == "v" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', -1, -amount))
|
||||
else
|
||||
return false, "Invalid number of arguments"
|
||||
end
|
||||
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region inset by " .. amount .. " blocks"
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
worldedit.register_command("shift", {
|
||||
params = "x/y/z/?/up/down/left/right/front/back [+/-]<amount>",
|
||||
description = "Shifts the selection area without moving its contents",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
|
||||
if find == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
return true, direction, tonumber(amount)
|
||||
end,
|
||||
func = function(name, direction, amount)
|
||||
local axis, dir
|
||||
if direction == "x" or direction == "y" or direction == "z" then
|
||||
axis, dir = direction, 1
|
||||
elseif direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
end
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
|
||||
assert(worldedit.cuboid_shift(name, axis, amount * dir))
|
||||
worldedit.marker_update(name)
|
||||
|
||||
return true, "Region shifted by " .. amount .. " nodes"
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
worldedit.register_command("expand", {
|
||||
params = "[+/-]x/y/z/?/up/down/left/right/front/back <amount> [reverse amount]",
|
||||
description = "Expands the selection in the selected absolute or relative axis",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local find, _, sign, direction, amount,
|
||||
rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
|
||||
if find == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if rev_amount == "" then
|
||||
rev_amount = "0"
|
||||
end
|
||||
|
||||
return true, sign, direction, tonumber(amount), tonumber(rev_amount)
|
||||
end,
|
||||
func = function(name, sign, direction, amount, rev_amount)
|
||||
local absolute = direction:find("[xyz?]")
|
||||
local dir, axis
|
||||
|
||||
if absolute == nil then
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
else
|
||||
if direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis = direction
|
||||
dir = 1
|
||||
end
|
||||
end
|
||||
|
||||
if sign == "-" then
|
||||
dir = -dir
|
||||
end
|
||||
|
||||
worldedit.cuboid_linear_expand(name, axis, dir, amount)
|
||||
worldedit.cuboid_linear_expand(name, axis, -dir, rev_amount)
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region expanded by " .. (amount + rev_amount) .. " nodes"
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
worldedit.register_command("contract", {
|
||||
params = "[+/-]x/y/z/?/up/down/left/right/front/back <amount> [reverse amount]",
|
||||
description = "Contracts the selection in the selected absolute or relative axis",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local find, _, sign, direction, amount,
|
||||
rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
|
||||
if find == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if rev_amount == "" then
|
||||
rev_amount = "0"
|
||||
end
|
||||
|
||||
return true, sign, direction, tonumber(amount), tonumber(rev_amount)
|
||||
end,
|
||||
func = function(name, sign, direction, amount, rev_amount)
|
||||
local absolute = direction:find("[xyz?]")
|
||||
local dir, axis
|
||||
|
||||
if absolute == nil then
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
else
|
||||
if direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis = direction
|
||||
dir = 1
|
||||
end
|
||||
end
|
||||
|
||||
if sign == "-" then
|
||||
dir = -dir
|
||||
end
|
||||
|
||||
worldedit.cuboid_linear_expand(name, axis, dir, -amount)
|
||||
worldedit.cuboid_linear_expand(name, axis, -dir, -rev_amount)
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region contracted by " .. (amount + rev_amount) .. " nodes"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_command("cubeapply", {
|
||||
params = "<size>/(<sizex> <sizey> <sizez>) <command> [parameters]",
|
||||
description = "Select a cube with side length <size> around position 1 and run <command> on region",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 1,
|
||||
parse = function(param)
|
||||
local found, _, sidex, sidey, sidez, cmd, args =
|
||||
param:find("^(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)%s*(.*)$")
|
||||
if found == nil then
|
||||
found, _, sidex, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$")
|
||||
if found == nil then
|
||||
return false
|
||||
end
|
||||
sidey = sidex
|
||||
sidez = sidex
|
||||
end
|
||||
sidex = tonumber(sidex)
|
||||
sidey = tonumber(sidey)
|
||||
sidez = tonumber(sidez)
|
||||
if sidex < 1 or sidey < 1 or sidez < 1 then
|
||||
return false
|
||||
end
|
||||
local cmddef = worldedit.registered_commands[cmd]
|
||||
if cmddef == nil or cmddef.require_pos ~= 2 then
|
||||
return false, "invalid usage: //" .. cmd .. " cannot be used with cubeapply"
|
||||
end
|
||||
-- run parsing of target command
|
||||
local parsed = {cmddef.parse(args)}
|
||||
if not table.remove(parsed, 1) then
|
||||
return false, parsed[1]
|
||||
end
|
||||
return true, sidex, sidey, sidez, cmd, parsed
|
||||
end,
|
||||
nodes_needed = function(name, sidex, sidey, sidez, cmd, parsed)
|
||||
-- its not possible to defer to the target command at this point
|
||||
return sidex * sidey * sidez
|
||||
end,
|
||||
func = function(name, sidex, sidey, sidez, cmd, parsed)
|
||||
local cmddef = assert(worldedit.registered_commands[cmd])
|
||||
local success, missing_privs = minetest.check_player_privs(name, cmddef.privs)
|
||||
if not success then
|
||||
worldedit.player_notify(name, "Missing privileges: " ..
|
||||
table.concat(missing_privs, ", "))
|
||||
return
|
||||
end
|
||||
|
||||
-- update region to be the cuboid the user wanted
|
||||
local half = vector.divide(vector.new(sidex, sidey, sidez), 2)
|
||||
local sizea, sizeb = vector.apply(half, math.floor), vector.apply(half, math.ceil)
|
||||
local center = worldedit.pos1[name]
|
||||
worldedit.pos1[name] = vector.subtract(center, sizea)
|
||||
worldedit.pos2[name] = vector.add(center, vector.subtract(sizeb, 1))
|
||||
worldedit.marker_update(name)
|
||||
|
||||
-- actually run target command
|
||||
return cmddef.func(name, unpack(parsed))
|
||||
end,
|
||||
})
|
@ -1 +0,0 @@
|
||||
worldedit
|
File diff suppressed because it is too large
Load Diff
@ -1,85 +1,128 @@
|
||||
worldedit.marker1 = {}
|
||||
worldedit.marker2 = {}
|
||||
worldedit.marker = {}
|
||||
worldedit.marker_region = {}
|
||||
|
||||
--wip: use this as a huge entity to make a full worldedit region box
|
||||
minetest.register_entity(":worldedit:region_cube", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=1.1, y=1.1},
|
||||
textures = {"worldedit_pos1.png"},
|
||||
visual_size = {x=10, y=10},
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
--wip: remove the entire region marker
|
||||
end,
|
||||
})
|
||||
local init_sentinel = "new" .. tostring(math.random(99999))
|
||||
|
||||
--marks worldedit region position 1
|
||||
worldedit.mark_pos1 = function(name)
|
||||
worldedit.mark_pos1 = function(name, region_too)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
|
||||
if pos1 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos1)
|
||||
end
|
||||
if worldedit.marker1[name] ~= nil then --marker already exists
|
||||
worldedit.marker1[name]:remove() --remove marker
|
||||
worldedit.marker1[name] = nil
|
||||
end
|
||||
if pos1 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos1)
|
||||
|
||||
--add marker
|
||||
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
|
||||
worldedit.marker1[name]:get_luaentity().active = true
|
||||
if pos2 ~= nil then --region defined
|
||||
worldedit.mark_region(pos1, pos2)
|
||||
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1", init_sentinel)
|
||||
if worldedit.marker1[name] ~= nil then
|
||||
worldedit.marker1[name]:get_luaentity().player_name = name
|
||||
end
|
||||
end
|
||||
if region_too == nil or region_too then
|
||||
worldedit.mark_region(name)
|
||||
end
|
||||
end
|
||||
|
||||
--marks worldedit region position 2
|
||||
worldedit.mark_pos2 = function(name)
|
||||
worldedit.mark_pos2 = function(name, region_too)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
|
||||
if pos2 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos2, pos2)
|
||||
end
|
||||
if worldedit.marker2[name] ~= nil then --marker already exists
|
||||
worldedit.marker2[name]:remove() --remove marker
|
||||
worldedit.marker2[name] = nil
|
||||
end
|
||||
if pos2 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos2, pos2)
|
||||
|
||||
--add marker
|
||||
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
|
||||
worldedit.marker2[name]:get_luaentity().active = true
|
||||
if pos1 ~= nil then --region defined
|
||||
worldedit.mark_region(pos1, pos2)
|
||||
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2", init_sentinel)
|
||||
if worldedit.marker2[name] ~= nil then
|
||||
worldedit.marker2[name]:get_luaentity().player_name = name
|
||||
end
|
||||
end
|
||||
if region_too == nil or region_too then
|
||||
worldedit.mark_region(name)
|
||||
end
|
||||
end
|
||||
|
||||
worldedit.mark_region = function(pos1, pos2)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
worldedit.mark_region = function(name)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
|
||||
if worldedit.marker[name] ~= nil then --marker already exists
|
||||
--wip: remove markers
|
||||
if worldedit.marker_region[name] ~= nil then --marker already exists
|
||||
for _, entity in ipairs(worldedit.marker_region[name]) do
|
||||
entity:remove()
|
||||
end
|
||||
worldedit.marker_region[name] = nil
|
||||
end
|
||||
|
||||
if pos1 ~= nil and pos2 ~= nil then
|
||||
--wip: place markers
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
local vec = vector.subtract(pos2, pos1)
|
||||
local maxside = math.max(vec.x, math.max(vec.y, vec.z))
|
||||
local limit = tonumber(minetest.settings:get("active_object_send_range_blocks")) * 16
|
||||
if maxside > limit * 1.5 then
|
||||
-- The client likely won't be able to see the plane markers as intended anyway,
|
||||
-- thus don't place them and also don't load the area into memory
|
||||
return
|
||||
end
|
||||
|
||||
local thickness = 0.2
|
||||
local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
|
||||
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
local markers = {}
|
||||
|
||||
--XY plane markers
|
||||
for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
|
||||
local entpos = {x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}
|
||||
local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel)
|
||||
if marker ~= nil then
|
||||
marker:set_properties({
|
||||
visual_size={x=sizex * 2, y=sizey * 2},
|
||||
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
|
||||
})
|
||||
marker:get_luaentity().player_name = name
|
||||
table.insert(markers, marker)
|
||||
end
|
||||
end
|
||||
|
||||
--YZ plane markers
|
||||
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
|
||||
local entpos = {x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}
|
||||
local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel)
|
||||
if marker ~= nil then
|
||||
marker:set_properties({
|
||||
visual_size={x=sizez * 2, y=sizey * 2},
|
||||
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
|
||||
})
|
||||
marker:set_yaw(math.pi / 2)
|
||||
marker:get_luaentity().player_name = name
|
||||
table.insert(markers, marker)
|
||||
end
|
||||
end
|
||||
|
||||
worldedit.marker_region[name] = markers
|
||||
end
|
||||
end
|
||||
|
||||
--convenience function that calls everything
|
||||
worldedit.marker_update = function(name)
|
||||
worldedit.mark_pos1(name, false)
|
||||
worldedit.mark_pos2(name, false)
|
||||
worldedit.mark_region(name)
|
||||
end
|
||||
|
||||
minetest.register_entity(":worldedit:pos1", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
@ -89,16 +132,20 @@ minetest.register_entity(":worldedit:pos1", {
|
||||
"worldedit_pos1.png", "worldedit_pos1.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
physical = false,
|
||||
static_save = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
if staticdata ~= init_sentinel then
|
||||
-- we were loaded from before static_save = false was added
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
local name = hitter:get_player_name()
|
||||
worldedit.marker1[name] = nil
|
||||
worldedit.marker1[self.player_name] = nil
|
||||
end,
|
||||
on_blast = function(self, damage)
|
||||
return false, false, {} -- don't damage or knockback
|
||||
end,
|
||||
})
|
||||
|
||||
@ -111,15 +158,49 @@ minetest.register_entity(":worldedit:pos2", {
|
||||
"worldedit_pos2.png", "worldedit_pos2.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
physical = false,
|
||||
static_save = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
if staticdata ~= init_sentinel then
|
||||
-- we were loaded from before static_save = false was added
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
local name = hitter:get_player_name()
|
||||
worldedit.marker2[name] = nil
|
||||
worldedit.marker2[self.player_name] = nil
|
||||
end,
|
||||
on_blast = function(self, damage)
|
||||
return false, false, {} -- don't damage or knockback
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity(":worldedit:region_cube", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = {"worldedit_cube.png"},
|
||||
visual_size = {x=10, y=10},
|
||||
physical = false,
|
||||
static_save = false,
|
||||
},
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
if staticdata ~= init_sentinel then
|
||||
-- we were loaded from before static_save = false was added
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
local markers = worldedit.marker_region[self.player_name]
|
||||
if not markers then
|
||||
return
|
||||
end
|
||||
for _, entity in ipairs(markers) do
|
||||
entity:remove()
|
||||
end
|
||||
worldedit.marker_region[self.player_name] = nil
|
||||
end,
|
||||
on_blast = function(self, damage)
|
||||
return false, false, {} -- don't damage or knockback
|
||||
end,
|
||||
})
|
||||
|
||||
|
3
worldedit_commands/mod.conf
Normal file
3
worldedit_commands/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = worldedit_commands
|
||||
description = WorldEdit chat commands
|
||||
depends = worldedit
|
48
worldedit_commands/safe.lua
Normal file
48
worldedit_commands/safe.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local safe_region_callback = {}
|
||||
|
||||
--`count` is the number of nodes that would possibly be modified
|
||||
--`callback` is a callback to run when the user confirms
|
||||
local function safe_region(name, count, callback)
|
||||
if count < 20000 then
|
||||
return callback()
|
||||
end
|
||||
|
||||
--save callback to call later
|
||||
safe_region_callback[name] = callback
|
||||
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
|
||||
end
|
||||
|
||||
local function reset_pending(name)
|
||||
safe_region_callback[name] = nil
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/y", {
|
||||
params = "",
|
||||
description = "Confirm a pending operation",
|
||||
func = function(name)
|
||||
local callback = safe_region_callback[name]
|
||||
if not callback then
|
||||
worldedit.player_notify(name, "no operation pending")
|
||||
return
|
||||
end
|
||||
|
||||
reset_pending(name)
|
||||
callback(name)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/n", {
|
||||
params = "",
|
||||
description = "Abort a pending operation",
|
||||
func = function(name)
|
||||
if not safe_region_callback[name] then
|
||||
worldedit.player_notify(name, "no operation pending")
|
||||
return
|
||||
end
|
||||
|
||||
reset_pending(name)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
return safe_region, reset_pending
|
BIN
worldedit_commands/textures/worldedit_cube.png
Normal file
BIN
worldedit_commands/textures/worldedit_cube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 147 B |
65
worldedit_commands/wand.lua
Normal file
65
worldedit_commands/wand.lua
Normal file
@ -0,0 +1,65 @@
|
||||
local function above_or_under(placer, pointed_thing)
|
||||
if placer:get_player_control().sneak then
|
||||
return pointed_thing.above
|
||||
else
|
||||
return pointed_thing.under
|
||||
end
|
||||
end
|
||||
|
||||
local punched_air_time = {}
|
||||
|
||||
minetest.register_tool(":worldedit:wand", {
|
||||
description = "WorldEdit Wand tool\nLeft-click to set 1st position, right-click to set 2nd",
|
||||
inventory_image = "worldedit_wand.png",
|
||||
stack_max = 1, -- there is no need to have more than one
|
||||
liquids_pointable = true, -- ground with only water on can be selected as well
|
||||
|
||||
on_use = function(itemstack, placer, pointed_thing)
|
||||
if placer == nil or pointed_thing == nil then return end
|
||||
local name = placer:get_player_name()
|
||||
if pointed_thing.type == "node" then
|
||||
-- set and mark pos1
|
||||
worldedit.pos1[name] = above_or_under(placer, pointed_thing)
|
||||
worldedit.mark_pos1(name)
|
||||
elseif pointed_thing.type == "nothing" then
|
||||
local now = minetest.get_us_time()
|
||||
if now - (punched_air_time[name] or 0) < 1000 * 1000 then
|
||||
-- reset markers
|
||||
worldedit.registered_commands["reset"].func(name)
|
||||
end
|
||||
punched_air_time[name] = now
|
||||
elseif pointed_thing.type == "object" then
|
||||
local entity = pointed_thing.ref:get_luaentity()
|
||||
if entity and entity.name == "worldedit:pos2" then
|
||||
-- set pos1 = pos2
|
||||
worldedit.pos1[name] = worldedit.pos2[name]
|
||||
worldedit.mark_pos1(name)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if placer == nil or (pointed_thing or {}).type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
local name = placer:get_player_name()
|
||||
-- set and mark pos2
|
||||
worldedit.pos2[name] = above_or_under(placer, pointed_thing)
|
||||
worldedit.mark_pos2(name)
|
||||
return itemstack -- nothing consumed, nothing changed
|
||||
end,
|
||||
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
if user == nil or (pointed_thing or {}).type ~= "object" then
|
||||
return itemstack
|
||||
end
|
||||
local name = user:get_player_name()
|
||||
local entity = pointed_thing.ref:get_luaentity()
|
||||
if entity and entity.name == "worldedit:pos1" then
|
||||
-- set pos2 = pos1
|
||||
worldedit.pos2[name] = worldedit.pos1[name]
|
||||
worldedit.mark_pos2(name)
|
||||
end
|
||||
return itemstack -- nothing consumed, nothing changed
|
||||
end,
|
||||
})
|
906
worldedit_gui/functionality.lua
Normal file
906
worldedit_gui/functionality.lua
Normal file
@ -0,0 +1,906 @@
|
||||
--saved state for each player
|
||||
local gui_nodename1 = {} --mapping of player names to node names
|
||||
local gui_nodename2 = {} --mapping of player names to node names
|
||||
local gui_axis1 = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
|
||||
local gui_axis2 = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
|
||||
local gui_distance1 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
|
||||
local gui_distance2 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
|
||||
local gui_distance3 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
|
||||
local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
|
||||
local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
|
||||
local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
|
||||
local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise)
|
||||
local gui_filename = {} --mapping of player names to file names
|
||||
|
||||
--set default values
|
||||
setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end})
|
||||
setmetatable(gui_nodename2, {__index = function() return "Stone" end})
|
||||
setmetatable(gui_axis1, {__index = function() return 4 end})
|
||||
setmetatable(gui_axis2, {__index = function() return 1 end})
|
||||
setmetatable(gui_distance1, {__index = function() return "10" end})
|
||||
setmetatable(gui_distance2, {__index = function() return "5" end})
|
||||
setmetatable(gui_distance3, {__index = function() return "2" end})
|
||||
setmetatable(gui_count1, {__index = function() return "3" end})
|
||||
setmetatable(gui_count2, {__index = function() return "6" end})
|
||||
setmetatable(gui_count3, {__index = function() return "4" end})
|
||||
setmetatable(gui_angle, {__index = function() return 90 end})
|
||||
setmetatable(gui_filename, {__index = function() return "building" end})
|
||||
|
||||
local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4}
|
||||
local axis_values = {"x", "y", "z", "?"}
|
||||
setmetatable(axis_indices, {__index = function () return 4 end})
|
||||
setmetatable(axis_values, {__index = function () return "?" end})
|
||||
|
||||
local angle_indices = {["90 degrees"]=1, ["180 degrees"]=2, ["270 degrees"]=3}
|
||||
local angle_values = {90, 180, 270}
|
||||
setmetatable(angle_indices, {__index = function () return 1 end})
|
||||
setmetatable(angle_values, {__index = function () return 90 end})
|
||||
|
||||
-- given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time
|
||||
local combine_privs = function(...)
|
||||
local result = {}
|
||||
for i, privs in ipairs({...}) do
|
||||
for name, value in pairs(privs) do
|
||||
if result[name] ~= nil and result[name] ~= value then --the priv must be both true and false, which can never happen
|
||||
return {__fake_priv_that_nobody_has__=true} --privilege table that can never be satisfied
|
||||
end
|
||||
result[name] = value
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- display node (or unknown_node image otherwise) at specified pos in formspec
|
||||
local formspec_node = function(pos, nodename)
|
||||
local ndef = nodename and minetest.registered_nodes[nodename]
|
||||
if nodename and ndef then
|
||||
return string.format("item_image[%s;1,1;%s]", pos, nodename) ..
|
||||
string.format("tooltip[%s;1,1;%s]", pos, minetest.formspec_escape(ndef.description))
|
||||
else
|
||||
return string.format("image[%s;1,1;worldedit_gui_unknown.png]", pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- two further priv helpers
|
||||
local function we_privs(command)
|
||||
return worldedit.registered_commands[command].privs
|
||||
end
|
||||
|
||||
local function combine_we_privs(list)
|
||||
local args = {}
|
||||
for _, t in ipairs(list) do
|
||||
table.insert(args, we_privs(t))
|
||||
end
|
||||
return combine_privs(unpack(args))
|
||||
end
|
||||
|
||||
-- functions that handle value changing & page reshowing (without submitting)
|
||||
local function copy_changes(name, fields, def)
|
||||
for field, into in pairs(def) do
|
||||
if into ~= true and fields[field] then
|
||||
local value = tostring(fields[field])
|
||||
if into == gui_axis1 or into == gui_axis2 then
|
||||
into[name] = axis_indices[value]
|
||||
elseif into == gui_angle then
|
||||
into[name] = angle_indices[value]
|
||||
else
|
||||
into[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_changes(name, identifier, fields, def)
|
||||
local any = false
|
||||
for field, into in pairs(def) do
|
||||
if fields.key_enter_field == field then
|
||||
any = true
|
||||
end
|
||||
-- first condition: buttons (value not saved)
|
||||
-- others: dropdowns which will be sent when their value changes
|
||||
if into == true or into == gui_axis1 or into == gui_axis2 or into == gui_angle then
|
||||
if fields[field] then
|
||||
any = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if not any then
|
||||
return false
|
||||
end
|
||||
|
||||
any = false
|
||||
for field, into in pairs(def) do
|
||||
if into ~= true and fields[field] then
|
||||
local value = tostring(fields[field])
|
||||
if into == gui_axis1 or into == gui_axis2 then
|
||||
into[name] = axis_indices[value]
|
||||
elseif into == gui_angle then
|
||||
into[name] = angle_indices[value]
|
||||
else
|
||||
into[name] = value
|
||||
end
|
||||
|
||||
if into == gui_nodename1 or into == gui_nodename2 then
|
||||
any = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Only nodename fields change based on the value, so only re-show the page if necessary
|
||||
if any then
|
||||
worldedit.show_page(name, identifier)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- This has the same behaviour as the player invoking the chat command
|
||||
local function execute_worldedit_command(command_name, player_name, params)
|
||||
local chatcmd = minetest.registered_chatcommands["/" .. command_name]
|
||||
assert(chatcmd, "unknown command: " .. command_name)
|
||||
local _, msg = chatcmd.func(player_name, params)
|
||||
if msg then
|
||||
worldedit.player_notify(player_name, msg)
|
||||
end
|
||||
end
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_about", {
|
||||
name = "About",
|
||||
privs = {interact=true},
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("about", name, "")
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_inspect", {
|
||||
name = "Toggle Inspect",
|
||||
privs = we_privs("inspect"),
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("inspect", name,
|
||||
worldedit.inspect[name] and "disable" or "enable")
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_region", {
|
||||
name = "Get/Set Region",
|
||||
privs = combine_we_privs({"p", "pos1", "pos2", "reset", "mark", "unmark", "volume", "fixedpos"}),
|
||||
get_formspec = function(name)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
return "size[9,7]" .. worldedit.get_formspec_header("worldedit_gui_region") ..
|
||||
"button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" ..
|
||||
"button_exit[3,1;3,0.8;worldedit_gui_p_set1;Choose Position 1]" ..
|
||||
"button_exit[6,1;3,0.8;worldedit_gui_p_set2;Choose Position 2]" ..
|
||||
"button_exit[0,2;3,0.8;worldedit_gui_pos1;Position 1 Here]" ..
|
||||
"button_exit[3,2;3,0.8;worldedit_gui_pos2;Position 2 Here]" ..
|
||||
"button_exit[6,2;3,0.8;worldedit_gui_reset;Reset Region]" ..
|
||||
"button_exit[0,3;3,0.8;worldedit_gui_mark;Mark Region]" ..
|
||||
"button_exit[3,3;3,0.8;worldedit_gui_unmark;Unmark Region]" ..
|
||||
"button_exit[6,3;3,0.8;worldedit_gui_volume;Region Volume]" ..
|
||||
"label[0,4.7;Position 1]" ..
|
||||
string.format("field[2,5;1.5,0.8;worldedit_gui_fixedpos_pos1x;X ;%s]", pos1 and pos1.x or "") ..
|
||||
string.format("field[3.5,5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Y ;%s]", pos1 and pos1.y or "") ..
|
||||
string.format("field[5,5;1.5,0.8;worldedit_gui_fixedpos_pos1z;Z ;%s]", pos1 and pos1.z or "") ..
|
||||
"button_exit[6.5,4.68;2.5,0.8;worldedit_gui_fixedpos_pos1_submit;Set Position 1]" ..
|
||||
"label[0,6.2;Position 2]" ..
|
||||
string.format("field[2,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;X ;%s]", pos2 and pos2.x or "") ..
|
||||
string.format("field[3.5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Y ;%s]", pos2 and pos2.y or "") ..
|
||||
string.format("field[5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Z ;%s]", pos2 and pos2.z or "") ..
|
||||
"button_exit[6.5,6.18;2.5,0.8;worldedit_gui_fixedpos_pos2_submit;Set Position 2]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_region", function(name, fields)
|
||||
if fields.worldedit_gui_p_get then
|
||||
execute_worldedit_command("p", name, "get")
|
||||
return true
|
||||
elseif fields.worldedit_gui_p_set1 then
|
||||
execute_worldedit_command("p", name, "set1")
|
||||
return true
|
||||
elseif fields.worldedit_gui_p_set2 then
|
||||
execute_worldedit_command("p", name, "set2")
|
||||
return true
|
||||
elseif fields.worldedit_gui_pos1 then
|
||||
execute_worldedit_command("pos1", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_pos2 then
|
||||
execute_worldedit_command("pos2", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_reset then
|
||||
execute_worldedit_command("reset", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_mark then
|
||||
execute_worldedit_command("mark", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_unmark then
|
||||
execute_worldedit_command("unmark", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_volume then
|
||||
execute_worldedit_command("volume", name, "")
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_fixedpos_pos1_submit then
|
||||
execute_worldedit_command("fixedpos", name, ("set1 %s %s %s"):format(
|
||||
tostring(fields.worldedit_gui_fixedpos_pos1x),
|
||||
tostring(fields.worldedit_gui_fixedpos_pos1y),
|
||||
tostring(fields.worldedit_gui_fixedpos_pos1z)))
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
elseif fields.worldedit_gui_fixedpos_pos2_submit then
|
||||
execute_worldedit_command("fixedpos", name, ("set2 %s %s %s"):format(
|
||||
tostring(fields.worldedit_gui_fixedpos_pos2x),
|
||||
tostring(fields.worldedit_gui_fixedpos_pos2y),
|
||||
tostring(fields.worldedit_gui_fixedpos_pos2z)))
|
||||
worldedit.show_page(name, "worldedit_gui_region")
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_set", {
|
||||
name = "Set Nodes",
|
||||
privs = we_privs("set"),
|
||||
get_formspec = function(name)
|
||||
local node = gui_nodename1[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_set_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_set_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_set", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_set_search = true,
|
||||
worldedit_gui_set_node = gui_nodename1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_set", fields, cg)
|
||||
if fields.worldedit_gui_set_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_set")
|
||||
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command("set", name, n)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_replace", {
|
||||
name = "Replace Nodes",
|
||||
privs = combine_we_privs({"replace", "replaceinverse"}),
|
||||
get_formspec = function(name)
|
||||
local search, replace = gui_nodename1[name], gui_nodename2[name]
|
||||
local search_nodename, replace_nodename = worldedit.normalize_nodename(search), worldedit.normalize_nodename(replace)
|
||||
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) ..
|
||||
"field_close_on_enter[worldedit_gui_replace_search;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..
|
||||
formspec_node("5.5,1.1", search_nodename) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) ..
|
||||
"field_close_on_enter[worldedit_gui_replace_replace;false]" ..
|
||||
"button[4,2.18;1.5,0.8;worldedit_gui_replace_replace_search;Search]" ..
|
||||
formspec_node("5.5,2.1", replace_nodename) ..
|
||||
"button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" ..
|
||||
"button_exit[3.5,3.5;3,0.8;worldedit_gui_replace_submit_inverse;Replace Inverse]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_replace_search_search = true,
|
||||
worldedit_gui_replace_replace_search = true,
|
||||
worldedit_gui_replace_search = gui_nodename1,
|
||||
worldedit_gui_replace_replace = gui_nodename2,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_replace", fields, cg)
|
||||
if fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_replace")
|
||||
|
||||
local submit = "replace"
|
||||
if fields.worldedit_gui_replace_submit_inverse then
|
||||
submit = "replaceinverse"
|
||||
end
|
||||
local n1 = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
local n2 = worldedit.normalize_nodename(gui_nodename2[name])
|
||||
if n1 and n2 then
|
||||
execute_worldedit_command(submit, name, n1 .. " " .. n2)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_sphere_dome", {
|
||||
name = "Sphere/Dome",
|
||||
privs = combine_we_privs({"hollowsphere", "sphere", "hollowdome", "dome"}),
|
||||
get_formspec = function(name)
|
||||
local node, radius = gui_nodename1[name], gui_distance2[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,5]" .. worldedit.get_formspec_header("worldedit_gui_sphere_dome") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_sphere_dome_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_sphere_dome_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_sphere_dome_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_sphere_dome_radius;Radius;%s]", minetest.formspec_escape(radius)) ..
|
||||
"field_close_on_enter[worldedit_gui_sphere_dome_radius;false]" ..
|
||||
"button_exit[0,3.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow;Hollow Sphere]" ..
|
||||
"button_exit[3.5,3.5;3,0.8;worldedit_gui_sphere_dome_submit_solid;Solid Sphere]" ..
|
||||
"button_exit[0,4.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow_dome;Hollow Dome]" ..
|
||||
"button_exit[3.5,4.5;3,0.8;worldedit_gui_sphere_dome_submit_solid_dome;Solid Dome]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_sphere_dome", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_sphere_dome_search = true,
|
||||
worldedit_gui_sphere_dome_node = gui_nodename1,
|
||||
worldedit_gui_sphere_dome_radius = gui_distance2,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_sphere_dome", fields, cg)
|
||||
if fields.worldedit_gui_sphere_dome_submit_hollow or fields.worldedit_gui_sphere_dome_submit_solid
|
||||
or fields.worldedit_gui_sphere_dome_submit_hollow_dome or fields.worldedit_gui_sphere_dome_submit_solid_dome then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_sphere_dome")
|
||||
|
||||
local submit = "hollowsphere"
|
||||
if fields.worldedit_gui_sphere_dome_submit_solid then
|
||||
submit = "sphere"
|
||||
elseif fields.worldedit_gui_sphere_dome_submit_hollow_dome then
|
||||
submit = "hollowdome"
|
||||
elseif fields.worldedit_gui_sphere_dome_submit_solid_dome then
|
||||
submit = "dome"
|
||||
end
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command(submit, name,
|
||||
gui_distance2[name] .. " " .. n)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_cylinder", {
|
||||
name = "Cylinder",
|
||||
privs = combine_we_privs({"hollowcylinder", "cylinder"}),
|
||||
get_formspec = function(name)
|
||||
local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]
|
||||
local radius1, radius2 = gui_distance2[name], gui_distance3[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_cylinder_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_cylinder_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_cylinder_length;Length;%s]", minetest.formspec_escape(length)) ..
|
||||
string.format("dropdown[4,2.18;2.5;worldedit_gui_cylinder_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
string.format("field[0.5,3.5;2,0.8;worldedit_gui_cylinder_radius1;Base Radius;%s]", minetest.formspec_escape(radius1)) ..
|
||||
string.format("field[2.5,3.5;2,0.8;worldedit_gui_cylinder_radius2;Top Radius;%s]", minetest.formspec_escape(radius2)) ..
|
||||
"field_close_on_enter[worldedit_gui_cylinder_length;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_cylinder_radius1;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_cylinder_radius2;false]" ..
|
||||
"label[0.25,4;Equal base and top radius creates a cylinder,\n"..
|
||||
"zero top radius creates a cone.\nConsult documentation for more information.]"..
|
||||
"button_exit[0,5.5;3,0.8;worldedit_gui_cylinder_submit_hollow;Hollow Cylinder]" ..
|
||||
"button_exit[3.5,5.5;3,0.8;worldedit_gui_cylinder_submit_solid;Solid Cylinder]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_cylinder_search = true,
|
||||
worldedit_gui_cylinder_node = gui_nodename1,
|
||||
worldedit_gui_cylinder_axis = gui_axis1,
|
||||
worldedit_gui_cylinder_length = gui_distance1,
|
||||
worldedit_gui_cylinder_radius1 = gui_distance2,
|
||||
worldedit_gui_cylinder_radius2 = gui_distance3,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_cylinder", fields, cg)
|
||||
if fields.worldedit_gui_cylinder_submit_hollow or fields.worldedit_gui_cylinder_submit_solid then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_cylinder")
|
||||
|
||||
local submit = "hollowcylinder"
|
||||
if fields.worldedit_gui_cylinder_submit_solid then
|
||||
submit = "cylinder"
|
||||
end
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
local args = string.format("%s %s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], gui_distance3[name], n)
|
||||
execute_worldedit_command(submit, name, args)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_pyramid", {
|
||||
name = "Pyramid",
|
||||
privs = we_privs("pyramid"),
|
||||
get_formspec = function(name)
|
||||
local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_pyramid") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_pyramid_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_pyramid_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_pyramid_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..
|
||||
string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
"field_close_on_enter[worldedit_gui_pyramid_length;false]" ..
|
||||
"button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit_hollow;Hollow Pyramid]" ..
|
||||
"button_exit[3.5,3.5;3,0.8;worldedit_gui_pyramid_submit_solid;Solid Pyramid]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_pyramid_search = true,
|
||||
worldedit_gui_pyramid_node = gui_nodename1,
|
||||
worldedit_gui_pyramid_axis = gui_axis1,
|
||||
worldedit_gui_pyramid_length = gui_distance1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_pyramid", fields, cg)
|
||||
if fields.worldedit_gui_pyramid_submit_solid or fields.worldedit_gui_pyramid_submit_hollow then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_pyramid")
|
||||
|
||||
local submit = "pyramid"
|
||||
if fields.worldedit_gui_pyramid_submit_hollow then
|
||||
submit = "hollowpyramid"
|
||||
end
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command(submit, name,
|
||||
string.format("%s %s %s", axis_values[gui_axis1[name]],
|
||||
gui_distance1[name], n))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_spiral", {
|
||||
name = "Spiral",
|
||||
privs = we_privs("spiral"),
|
||||
get_formspec = function(name)
|
||||
local node, length, height, space = gui_nodename1[name], gui_distance1[name], gui_distance2[name], gui_distance3[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_spiral") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_spiral_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_spiral_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_spiral_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_spiral_length;Side Length;%s]", minetest.formspec_escape(length)) ..
|
||||
string.format("field[0.5,3.5;4,0.8;worldedit_gui_spiral_height;Height;%s]", minetest.formspec_escape(height)) ..
|
||||
string.format("field[0.5,4.5;4,0.8;worldedit_gui_spiral_space;Wall Spacing;%s]", minetest.formspec_escape(space)) ..
|
||||
"field_close_on_enter[worldedit_gui_spiral_length;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_spiral_height;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_spiral_space;false]" ..
|
||||
"button_exit[0,5.5;3,0.8;worldedit_gui_spiral_submit;Spiral]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_spiral", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_spiral_search = true,
|
||||
worldedit_gui_spiral_node = gui_nodename1,
|
||||
worldedit_gui_spiral_length = gui_distance1,
|
||||
worldedit_gui_spiral_height = gui_distance2,
|
||||
worldedit_gui_spiral_space = gui_distance3,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)
|
||||
if fields.worldedit_gui_spiral_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_spiral")
|
||||
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command("spiral", name,
|
||||
string.format("%s %s %s %s", gui_distance1[name],
|
||||
gui_distance2[name], gui_distance3[name], n))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_copy_move", {
|
||||
name = "Copy/Move",
|
||||
privs = combine_we_privs({"copy", "move"}),
|
||||
get_formspec = function(name)
|
||||
local axis = gui_axis1[name] or 4
|
||||
local amount = gui_distance1[name] or "10"
|
||||
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_copy_move") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]", minetest.formspec_escape(amount)) ..
|
||||
string.format("dropdown[4,1.18;2.5;worldedit_gui_copy_move_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
"field_close_on_enter[worldedit_gui_copy_move_amount;false]" ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_copy_move_copy;Copy Region]" ..
|
||||
"button_exit[3.5,2.5;3,0.8;worldedit_gui_copy_move_move;Move Region]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_copy_move", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_copy_move_amount = gui_distance1,
|
||||
worldedit_gui_copy_move_axis = gui_axis1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)
|
||||
if fields.worldedit_gui_copy_move_copy or fields.worldedit_gui_copy_move_move then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_copy_move")
|
||||
|
||||
local submit = "copy"
|
||||
if fields.worldedit_gui_copy_move_move then
|
||||
submit = "move"
|
||||
end
|
||||
execute_worldedit_command(submit, name,
|
||||
axis_values[gui_axis1[name]] .. " " .. gui_distance1[name])
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_stack", {
|
||||
name = "Stack",
|
||||
privs = we_privs("stack"),
|
||||
get_formspec = function(name)
|
||||
local axis, count = gui_axis1[name], gui_count1[name]
|
||||
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_stack") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_stack_count;Count;%s]", minetest.formspec_escape(count)) ..
|
||||
string.format("dropdown[4,1.18;2.5;worldedit_gui_stack_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
"field_close_on_enter[worldedit_gui_stack_count;false]" ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_stack_submit;Stack]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_stack", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_stack_axis = gui_axis1,
|
||||
worldedit_gui_stack_count = gui_count1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_stack", fields, cg)
|
||||
if fields.worldedit_gui_stack_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_stack")
|
||||
|
||||
execute_worldedit_command("stack", name,
|
||||
axis_values[gui_axis1[name]] .. " " .. gui_count1[name])
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_stretch", {
|
||||
name = "Stretch",
|
||||
privs = we_privs("stretch"),
|
||||
get_formspec = function(name)
|
||||
local stretchx, stretchy, stretchz = gui_count1[name], gui_count2[name], gui_count3[name]
|
||||
return "size[5,5]" .. worldedit.get_formspec_header("worldedit_gui_stretch") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_stretch_x;Stretch X;%s]", minetest.formspec_escape(stretchx)) ..
|
||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_stretch_y;Stretch Y;%s]", minetest.formspec_escape(stretchy)) ..
|
||||
string.format("field[0.5,3.5;4,0.8;worldedit_gui_stretch_z;Stretch Z;%s]", minetest.formspec_escape(stretchz)) ..
|
||||
"field_close_on_enter[worldedit_gui_stretch_x;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_stretch_y;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_stretch_z;false]" ..
|
||||
"button_exit[0,4.5;3,0.8;worldedit_gui_stretch_submit;Stretch]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_stretch", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_stretch_x = gui_count1,
|
||||
worldedit_gui_stretch_y = gui_count2,
|
||||
worldedit_gui_stretch_z = gui_count3,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_stretch", fields, cg)
|
||||
if fields.worldedit_gui_stretch_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_stretch")
|
||||
|
||||
execute_worldedit_command("stretch", name, string.format("%s %s %s",
|
||||
gui_count1[name], gui_count2[name], gui_count3[name]))
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_transpose", {
|
||||
name = "Transpose",
|
||||
privs = we_privs("transpose"),
|
||||
get_formspec = function(name)
|
||||
local axis1, axis2 = gui_axis1[name], gui_axis2[name]
|
||||
return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_transpose") ..
|
||||
string.format("dropdown[0,1;2.5;worldedit_gui_transpose_axis1;X axis,Y axis,Z axis,Look direction;%d]", axis1) ..
|
||||
string.format("dropdown[3,1;2.5;worldedit_gui_transpose_axis2;X axis,Y axis,Z axis,Look direction;%d]", axis2) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_transpose_submit;Transpose]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_transpose", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_transpose_axis1 = gui_axis1,
|
||||
worldedit_gui_transpose_axis2 = gui_axis2,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_transpose", fields, cg)
|
||||
if fields.worldedit_gui_transpose_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
|
||||
execute_worldedit_command("transpose", name,
|
||||
axis_values[gui_axis1[name]] .. " " .. axis_values[gui_axis2[name]])
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_flip", {
|
||||
name = "Flip",
|
||||
privs = we_privs("flip"),
|
||||
get_formspec = function(name)
|
||||
local axis = gui_axis1[name]
|
||||
return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_flip") ..
|
||||
string.format("dropdown[0,1;2.5;worldedit_gui_flip_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_flip_submit;Flip]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_flip", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_flip_axis = gui_axis1
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_flip", fields, cg)
|
||||
if fields.worldedit_gui_flip_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_flip")
|
||||
|
||||
execute_worldedit_command("flip", name, axis_values[gui_axis1[name]])
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_rotate", {
|
||||
name = "Rotate",
|
||||
privs = we_privs("rotate"),
|
||||
get_formspec = function(name)
|
||||
local axis, angle = gui_axis1[name], gui_angle[name]
|
||||
return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_rotate") ..
|
||||
string.format("dropdown[0,1;2.5;worldedit_gui_rotate_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
|
||||
string.format("dropdown[3,1;2.5;worldedit_gui_rotate_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_rotate_submit;Rotate]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_rotate", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_rotate_axis = gui_axis1,
|
||||
worldedit_gui_rotate_angle = gui_angle,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_rotate", fields, cg)
|
||||
if fields.worldedit_gui_rotate_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_rotate")
|
||||
|
||||
execute_worldedit_command("rotate", name,
|
||||
axis_values[gui_axis1[name]] .. " " .. angle_values[gui_angle[name]])
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_orient", {
|
||||
name = "Orient",
|
||||
privs = we_privs("orient"),
|
||||
get_formspec = function(name)
|
||||
local angle = gui_angle[name]
|
||||
return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..
|
||||
string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_orient_angle = gui_angle,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_orient", fields, cg)
|
||||
if fields.worldedit_gui_orient_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_orient")
|
||||
|
||||
execute_worldedit_command("orient", name,
|
||||
tostring(angle_values[gui_angle[name]]))
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_fixlight", {
|
||||
name = "Fix Lighting",
|
||||
privs = we_privs("fixlight"),
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("fixlight", name, "")
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_hide", {
|
||||
name = "Hide Region",
|
||||
privs = we_privs("hide"),
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("hide", name, "")
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_suppress", {
|
||||
name = "Suppress Nodes",
|
||||
privs = we_privs("suppress"),
|
||||
get_formspec = function(name)
|
||||
local node = gui_nodename1[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_suppress") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_suppress_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_suppress_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_suppress_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_suppress_submit;Suppress Nodes]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_suppress", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_suppress_search = true,
|
||||
worldedit_gui_suppress_node = gui_nodename1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_suppress", fields, cg)
|
||||
if fields.worldedit_gui_suppress_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_suppress")
|
||||
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command("suppress", name, n)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_highlight", {
|
||||
name = "Highlight Nodes",
|
||||
privs = we_privs("highlight"),
|
||||
get_formspec = function(name)
|
||||
local node = gui_nodename1[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_highlight") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_highlight_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_highlight_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_highlight_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_highlight_submit;Highlight Nodes]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_highlight", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_highlight_search = true,
|
||||
worldedit_gui_highlight_node = gui_nodename1,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_highlight", fields, cg)
|
||||
if fields.worldedit_gui_highlight_submit then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_highlight")
|
||||
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
execute_worldedit_command("highlight", name, n)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_restore", {
|
||||
name = "Restore Region",
|
||||
privs = we_privs("restore"),
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("restore", name, "")
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_save_load", {
|
||||
name = "Save/Load",
|
||||
privs = combine_we_privs({"save", "allocate", "load"}),
|
||||
get_formspec = function(name)
|
||||
local filename = gui_filename[name]
|
||||
return "size[6,4]" .. worldedit.get_formspec_header("worldedit_gui_save_load") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_save_filename;Filename;%s]", minetest.formspec_escape(filename)) ..
|
||||
"field_close_on_enter[worldedit_gui_save_filename;false]" ..
|
||||
"button_exit[0,2.5;3,0.8;worldedit_gui_save_load_submit_save;Save]" ..
|
||||
"button_exit[3,2.5;3,0.8;worldedit_gui_save_load_submit_allocate;Allocate]" ..
|
||||
"button_exit[0,3.5;3,0.8;worldedit_gui_save_load_submit_load;Load]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_save_load", function(name, fields)
|
||||
if fields.worldedit_gui_save_load_submit_save or fields.worldedit_gui_save_load_submit_allocate or fields.worldedit_gui_save_load_submit_load then
|
||||
gui_filename[name] = tostring(fields.worldedit_gui_save_filename)
|
||||
worldedit.show_page(name, "worldedit_gui_save_load")
|
||||
|
||||
if fields.worldedit_gui_save_load_submit_save then
|
||||
execute_worldedit_command("save", name, gui_filename[name])
|
||||
elseif fields.worldedit_gui_save_load_submit_allocate then
|
||||
execute_worldedit_command("allocate", name, gui_filename[name])
|
||||
else --fields.worldedit_gui_save_load_submit_load
|
||||
execute_worldedit_command("load", name, gui_filename[name])
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_cube", {
|
||||
name = "Cube",
|
||||
privs = combine_we_privs({"hollowcube", "cube"}),
|
||||
get_formspec = function(name)
|
||||
local width, height, length = gui_distance1[name], gui_distance2[name], gui_distance3[name]
|
||||
local node = gui_nodename1[name]
|
||||
local nodename = worldedit.normalize_nodename(node)
|
||||
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_cube") ..
|
||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_cube_node;Name;%s]", minetest.formspec_escape(node)) ..
|
||||
"field_close_on_enter[worldedit_gui_cube_node;false]" ..
|
||||
"button[4,1.18;1.5,0.8;worldedit_gui_cube_search;Search]" ..
|
||||
formspec_node("5.5,1.1", nodename) ..
|
||||
string.format("field[0.5,2.5;1,0.8;worldedit_gui_cube_width;Width;%s]", minetest.formspec_escape(width)) ..
|
||||
string.format("field[1.5,2.5;1,0.8;worldedit_gui_cube_height;Height;%s]", minetest.formspec_escape(height)) ..
|
||||
string.format("field[2.5,2.5;1,0.8;worldedit_gui_cube_length;Length;%s]", minetest.formspec_escape(length)) ..
|
||||
"field_close_on_enter[worldedit_gui_cube_width;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_cube_height;false]" ..
|
||||
"field_close_on_enter[worldedit_gui_cube_length;false]" ..
|
||||
"button_exit[0,3.5;3,0.8;worldedit_gui_cube_submit_hollow;Hollow Cuboid]" ..
|
||||
"button_exit[3.5,3.5;3,0.8;worldedit_gui_cube_submit_solid;Solid Cuboid]"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_cube", function(name, fields)
|
||||
local cg = {
|
||||
worldedit_gui_cube_search = true,
|
||||
worldedit_gui_cube_node = gui_nodename1,
|
||||
worldedit_gui_cube_width = gui_distance1,
|
||||
worldedit_gui_cube_height = gui_distance2,
|
||||
worldedit_gui_cube_length = gui_distance3,
|
||||
}
|
||||
local ret = handle_changes(name, "worldedit_gui_cube", fields, cg)
|
||||
if fields.worldedit_gui_cube_submit_hollow or fields.worldedit_gui_cube_submit_solid then
|
||||
copy_changes(name, fields, cg)
|
||||
worldedit.show_page(name, "worldedit_gui_cube")
|
||||
|
||||
local submit = "hollowcube"
|
||||
if fields.worldedit_gui_cube_submit_solid then
|
||||
submit = "cube"
|
||||
end
|
||||
local n = worldedit.normalize_nodename(gui_nodename1[name])
|
||||
if n then
|
||||
local args = string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n)
|
||||
execute_worldedit_command(submit, name, args)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return ret
|
||||
end)
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_clearobjects", {
|
||||
name = "Clear Objects",
|
||||
privs = we_privs("clearobjects"),
|
||||
on_select = function(name)
|
||||
execute_worldedit_command("clearobjects", name, "")
|
||||
end,
|
||||
})
|
280
worldedit_gui/init.lua
Normal file
280
worldedit_gui/init.lua
Normal file
@ -0,0 +1,280 @@
|
||||
worldedit = worldedit or {}
|
||||
|
||||
--[[
|
||||
Example:
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui_hollow_cylinder", {
|
||||
name = "Make Hollow Cylinder",
|
||||
privs = {worldedit=true},
|
||||
get_formspec = function(name) return "some formspec here" end,
|
||||
on_select = function(name) print(name .. " clicked the button!") end,
|
||||
})
|
||||
|
||||
Use `nil` for the `options` parameter to unregister the function associated with the given identifier.
|
||||
|
||||
Use `nil` for the `get_formspec` field to denote that the function does not have its own screen.
|
||||
|
||||
The `privs` field may not be `nil`.
|
||||
|
||||
If the identifier is already registered to another function, it will be replaced by the new one.
|
||||
|
||||
The `on_select` function must not call `worldedit.show_page`
|
||||
]]
|
||||
|
||||
worldedit.pages = {} --mapping of identifiers to options
|
||||
local identifiers = {} --ordered list of identifiers
|
||||
worldedit.register_gui_function = function(identifier, options)
|
||||
if options.privs == nil or next(options.privs) == nil then
|
||||
error("privs unset")
|
||||
end
|
||||
worldedit.pages[identifier] = options
|
||||
table.insert(identifiers, identifier)
|
||||
end
|
||||
|
||||
--[[
|
||||
Example:
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui_hollow_cylinder", function(name, fields)
|
||||
print(minetest.serialize(fields))
|
||||
end)
|
||||
]]
|
||||
|
||||
worldedit.register_gui_handler = function(identifier, handler)
|
||||
local enabled = true
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not enabled then return false end
|
||||
enabled = false
|
||||
minetest.after(0.2, function() enabled = true end)
|
||||
local name = player:get_player_name()
|
||||
|
||||
--ensure the player has permission to perform the action
|
||||
local entry = worldedit.pages[identifier]
|
||||
if entry and minetest.check_player_privs(name, entry.privs) then
|
||||
return handler(name, fields)
|
||||
end
|
||||
return false
|
||||
end)
|
||||
end
|
||||
|
||||
worldedit.get_formspec_header = function(identifier)
|
||||
local entry = worldedit.pages[identifier] or {}
|
||||
return "button[0,0;2,0.5;worldedit_gui;Back]" ..
|
||||
string.format("label[2,0;WorldEdit GUI > %s]", entry.name or "")
|
||||
end
|
||||
|
||||
local get_formspec = function(name, identifier)
|
||||
if worldedit.pages[identifier] then
|
||||
return worldedit.pages[identifier].get_formspec(name)
|
||||
end
|
||||
return worldedit.pages["worldedit_gui"].get_formspec(name) --default to showing main page if an unknown page is given
|
||||
end
|
||||
|
||||
--implement worldedit.show_page(name, page) in different ways depending on the available APIs
|
||||
if minetest.global_exists("unified_inventory") then -- unified inventory installed
|
||||
local old_func = worldedit.register_gui_function
|
||||
worldedit.register_gui_function = function(identifier, options)
|
||||
old_func(identifier, options)
|
||||
unified_inventory.register_page(identifier, {get_formspec=function(player) return {formspec=options.get_formspec(player:get_player_name())} end})
|
||||
end
|
||||
|
||||
unified_inventory.register_button("worldedit_gui", {
|
||||
type = "image",
|
||||
image = "inventory_plus_worldedit_gui.png",
|
||||
condition = function(player)
|
||||
return minetest.check_player_privs(player:get_player_name(), {worldedit=true})
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if fields.worldedit_gui then --main page
|
||||
worldedit.show_page(name, "worldedit_gui")
|
||||
return true
|
||||
elseif fields.worldedit_gui_exit then --return to original page
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
unified_inventory.set_inventory_formspec(player, "craft")
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
worldedit.show_page = function(name, page)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player:set_inventory_formspec(get_formspec(name, page))
|
||||
end
|
||||
end
|
||||
elseif minetest.global_exists("inventory_plus") then -- inventory++ installed
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local can_worldedit = minetest.check_player_privs(player:get_player_name(), {worldedit=true})
|
||||
if can_worldedit then
|
||||
inventory_plus.register_button(player, "worldedit_gui", "WorldEdit")
|
||||
end
|
||||
end)
|
||||
|
||||
--show the form when the button is pressed and hide it when done
|
||||
local gui_player_formspecs = {}
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if fields.worldedit_gui then --main page
|
||||
gui_player_formspecs[name] = player:get_inventory_formspec()
|
||||
worldedit.show_page(name, "worldedit_gui")
|
||||
return true
|
||||
elseif fields.worldedit_gui_exit then --return to original page
|
||||
if gui_player_formspecs[name] then
|
||||
inventory_plus.set_inventory_formspec(player, inventory_plus.get_formspec(player, "main"))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
worldedit.show_page = function(name, page)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
inventory_plus.set_inventory_formspec(player, get_formspec(name, page))
|
||||
end
|
||||
end
|
||||
elseif minetest.global_exists("smart_inventory") then -- smart_inventory installed
|
||||
-- redefinition: Update the code element on inventory page to show the we-page
|
||||
function worldedit.show_page(name, page)
|
||||
local state = smart_inventory.get_page_state("worldedit_gui", name)
|
||||
if state then
|
||||
state:get("code"):set_we_formspec(page)
|
||||
state.location.rootState:show() -- update inventory page
|
||||
end
|
||||
end
|
||||
|
||||
-- smart_inventory page callback. Contains just a "custom code" element
|
||||
local function smart_worldedit_gui_callback(state)
|
||||
local codebox = state:element("code", { name = "code", code = "" })
|
||||
function codebox:set_we_formspec(we_page)
|
||||
local new_formspec = get_formspec(state.location.rootState.location.player, we_page)
|
||||
new_formspec = new_formspec:gsub('button_exit','button') --no inventory closing
|
||||
self.data.code = "container[1,1]".. new_formspec .. "container_end[]"
|
||||
end
|
||||
codebox:set_we_formspec("worldedit_gui")
|
||||
|
||||
-- process input (the back button)
|
||||
state:onInput(function(state, fields, player)
|
||||
if fields.worldedit_gui then --main page
|
||||
state:get("code"):set_we_formspec("worldedit_gui")
|
||||
elseif fields.worldedit_gui_exit then --return to original page
|
||||
state:get("code"):set_we_formspec("worldedit_gui")
|
||||
state.location.parentState:get("crafting_button"):submit() -- switch to the crafting tab
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- all handler should return false to force inventory UI update
|
||||
local orig_register_gui_handler = worldedit.register_gui_handler
|
||||
worldedit.register_gui_handler = function(identifier, handler)
|
||||
local wrapper = function(...)
|
||||
handler(...)
|
||||
return false
|
||||
end
|
||||
orig_register_gui_handler(identifier, wrapper)
|
||||
end
|
||||
|
||||
-- register the inventory button
|
||||
smart_inventory.register_page({
|
||||
name = "worldedit_gui",
|
||||
tooltip = "Edit your World!",
|
||||
icon = "inventory_plus_worldedit_gui.png",
|
||||
smartfs_callback = smart_worldedit_gui_callback,
|
||||
sequence = 99
|
||||
})
|
||||
elseif minetest.global_exists("sfinv") then -- sfinv installed
|
||||
assert(sfinv.enabled)
|
||||
local orig_get = sfinv.pages["sfinv:crafting"].get
|
||||
sfinv.override_page("sfinv:crafting", {
|
||||
get = function(self, player, context)
|
||||
local can_worldedit = minetest.check_player_privs(player, {worldedit=true})
|
||||
local fs = orig_get(self, player, context)
|
||||
return fs .. (can_worldedit and "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" or "")
|
||||
end
|
||||
})
|
||||
|
||||
--show the form when the button is pressed and hide it when done
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if fields.worldedit_gui then --main page
|
||||
worldedit.show_page(player:get_player_name(), "worldedit_gui")
|
||||
return true
|
||||
elseif fields.worldedit_gui_exit then --return to original page
|
||||
sfinv.set_page(player, "sfinv:crafting")
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
worldedit.show_page = function(name, page)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player:set_inventory_formspec(get_formspec(name, page))
|
||||
end
|
||||
end
|
||||
else
|
||||
error(
|
||||
"worldedit_gui requires a supported gui management mod to be installed.\n"..
|
||||
"To use the it you need to either:\n"..
|
||||
"* use minetest_game or another sfinv-compatible subgame\n"..
|
||||
"* install Unified Inventory, Inventory++ or Smart Inventory\n"..
|
||||
"If you don't want to use worldedit_gui, disable it by editing world.mt or from the main menu."
|
||||
)
|
||||
end
|
||||
|
||||
worldedit.register_gui_function("worldedit_gui", {
|
||||
name = "WorldEdit GUI",
|
||||
privs = {interact=true},
|
||||
get_formspec = function(name)
|
||||
--create a form with all the buttons arranged in a grid
|
||||
local buttons, x, y, index = {}, 0, 1, 0
|
||||
local width, height = 3, 0.8
|
||||
local columns = 5
|
||||
for i, identifier in pairs(identifiers) do
|
||||
if identifier ~= "worldedit_gui" then
|
||||
local entry = worldedit.pages[identifier]
|
||||
table.insert(buttons, string.format((entry.get_formspec and "button" or "button_exit") ..
|
||||
"[%g,%g;%g,%g;%s;%s]", x, y, width, height, identifier, minetest.formspec_escape(entry.name)))
|
||||
|
||||
index, x = index + 1, x + width
|
||||
if index == columns then --row is full
|
||||
x, y = 0, y + height
|
||||
index = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
if index == 0 then --empty row
|
||||
y = y - height
|
||||
end
|
||||
return string.format("size[%g,%g]", math.max(columns * width, 5), math.max(y + 0.5, 3)) ..
|
||||
"button[0,0;2,0.5;worldedit_gui_exit;Back]" ..
|
||||
"label[2,0;WorldEdit GUI]" ..
|
||||
table.concat(buttons)
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_gui_handler("worldedit_gui", function(name, fields)
|
||||
for identifier, entry in pairs(worldedit.pages) do --check for WorldEdit GUI main formspec button selection
|
||||
if fields[identifier] and identifier ~= "worldedit_gui" then
|
||||
--ensure player has permission to perform action
|
||||
local has_privs, missing_privs = minetest.check_player_privs(name, entry.privs)
|
||||
if not has_privs then
|
||||
worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")")
|
||||
return false
|
||||
end
|
||||
if entry.on_select then
|
||||
entry.on_select(name)
|
||||
end
|
||||
if entry.get_formspec then
|
||||
worldedit.show_page(name, identifier)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/functionality.lua")
|
4
worldedit_gui/mod.conf
Normal file
4
worldedit_gui/mod.conf
Normal file
@ -0,0 +1,4 @@
|
||||
name = worldedit_gui
|
||||
description = WorldEdit GUI
|
||||
depends = worldedit, worldedit_commands
|
||||
optional_depends = unified_inventory, inventory_plus, sfinv, creative, smart_inventory
|
BIN
worldedit_gui/textures/inventory_plus_worldedit_gui.png
Normal file
BIN
worldedit_gui/textures/inventory_plus_worldedit_gui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
worldedit_gui/textures/worldedit_gui_unknown.png
Normal file
BIN
worldedit_gui/textures/worldedit_gui_unknown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 597 B |
52
worldedit_shortcommands/init.lua
Normal file
52
worldedit_shortcommands/init.lua
Normal file
@ -0,0 +1,52 @@
|
||||
--provides shorter names for the commands in `worldedit_commands`
|
||||
|
||||
worldedit.alias_command = function(alias, original)
|
||||
if not worldedit.registered_commands[original] then
|
||||
minetest.log("error", "worldedit_shortcommands: original " .. original .. " does not exist")
|
||||
return
|
||||
end
|
||||
if minetest.chatcommands["/" .. alias] then
|
||||
minetest.log("error", "worldedit_shortcommands: alias " .. alias .. " already exists")
|
||||
return
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/" .. alias, minetest.chatcommands["/" .. original])
|
||||
worldedit.registered_commands[alias] = worldedit.registered_commands[original]
|
||||
end
|
||||
|
||||
worldedit.alias_command("i", "inspect")
|
||||
worldedit.alias_command("rst", "reset")
|
||||
worldedit.alias_command("mk", "mark")
|
||||
worldedit.alias_command("umk", "unmark")
|
||||
worldedit.alias_command("1", "pos1")
|
||||
worldedit.alias_command("2", "pos2")
|
||||
worldedit.alias_command("fp", "fixedpos")
|
||||
worldedit.alias_command("v", "volume")
|
||||
worldedit.alias_command("s", "set")
|
||||
worldedit.alias_command("r", "replace")
|
||||
worldedit.alias_command("ri", "replaceinverse")
|
||||
worldedit.alias_command("hcube", "hollowcube")
|
||||
worldedit.alias_command("hspr", "hollowsphere")
|
||||
worldedit.alias_command("spr", "sphere")
|
||||
worldedit.alias_command("hdo", "hollowdome")
|
||||
worldedit.alias_command("do", "dome")
|
||||
worldedit.alias_command("hcyl", "hollowcylinder")
|
||||
worldedit.alias_command("cyl", "cylinder")
|
||||
worldedit.alias_command("hpyr", "hollowpyramid")
|
||||
worldedit.alias_command("pyr", "pyramid")
|
||||
worldedit.alias_command("spl", "spiral")
|
||||
worldedit.alias_command("m", "move")
|
||||
worldedit.alias_command("c", "copy")
|
||||
worldedit.alias_command("stk", "stack")
|
||||
worldedit.alias_command("sch", "stretch")
|
||||
worldedit.alias_command("tps", "transpose")
|
||||
worldedit.alias_command("fl", "flip")
|
||||
worldedit.alias_command("rot", "rotate")
|
||||
worldedit.alias_command("ort", "orient")
|
||||
worldedit.alias_command("hi", "hide")
|
||||
worldedit.alias_command("sup", "suppress")
|
||||
worldedit.alias_command("hlt", "highlight")
|
||||
worldedit.alias_command("rsr", "restore")
|
||||
worldedit.alias_command("l", "lua")
|
||||
worldedit.alias_command("lt", "luatransform")
|
||||
worldedit.alias_command("clro", "clearobjects")
|
3
worldedit_shortcommands/mod.conf
Normal file
3
worldedit_shortcommands/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = worldedit_shortcommands
|
||||
description = WorldEdit command short aliases
|
||||
depends = worldedit_commands
|
Reference in New Issue
Block a user