@@ -4,6 +4,10 @@ worldedit.set_pos = {}
4
4
5
5
worldedit .pos1 = {}
6
6
worldedit .pos2 = {}
7
+ if minetest .place_schematic then
8
+ worldedit .prob_pos = {}
9
+ worldedit .prob_list = {}
10
+ end
7
11
8
12
dofile (minetest .get_modpath (" worldedit_commands" ) .. " /mark.lua" )
9
13
@@ -161,6 +165,9 @@ minetest.register_on_punchnode(function(pos, node, puncher)
161
165
worldedit .mark_pos2 (name )
162
166
worldedit .set_pos [name ] = nil -- finished setting positions
163
167
worldedit .player_notify (name , " position 2 set to " .. minetest .pos_to_string (pos ))
168
+ elseif worldedit .set_pos [name ] == " prob" then -- setting Minetest schematic node probabilities
169
+ worldedit .prob_pos [name ] = pos
170
+ minetest .show_formspec (puncher :get_player_name (), " prob_val_enter" , " field[text;;]" )
164
171
end
165
172
end
166
173
end )
@@ -1071,3 +1078,100 @@ minetest.register_chatcommand("/luatransform", {
1071
1078
end
1072
1079
end ,
1073
1080
})
1081
+
1082
+ if minetest .place_schematic then
1083
+ minetest .register_chatcommand (" /mtschemcreate" , {
1084
+ params = " <filename>" ,
1085
+ description = " Creates a Minetest schematic of the box defined by position 1 and position 2, and saves it to <filename>" ,
1086
+ privs = {worldedit = true },
1087
+ func = function (name , param )
1088
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
1089
+ if pos1 == nil or pos2 == nil then
1090
+ worldedit .player_notify (name , " No region selected" )
1091
+ return
1092
+ end
1093
+ if param == nil then
1094
+ worldedit .player_notify (name , " No filename specified" )
1095
+ return
1096
+ end
1097
+
1098
+ local path = minetest .get_worldpath () .. " /schems"
1099
+ local filename = path .. " /" .. param .. " .mts"
1100
+ os.execute (" mkdir \" " .. path .. " \" " ) -- create directory if it does not already exist
1101
+
1102
+ local ret = minetest .create_schematic (pos1 , pos2 , worldedit .prob_list [name ], filename )
1103
+ if ret == nil then
1104
+ worldedit .player_notify (name , " Failed to create Minetest schematic" , false )
1105
+ else
1106
+ worldedit .player_notify (name , " Saved Minetest schematic to " .. param , false )
1107
+ end
1108
+ worldedit .prob_list [name ] = {}
1109
+ end ,
1110
+ })
1111
+
1112
+ minetest .register_chatcommand (" /mtschemplace" , {
1113
+ params = " <filename>" ,
1114
+ description = " Places the Minetest schematic identified by <filename> at WorldEdit position 1" ,
1115
+ privs = {worldedit = true },
1116
+ func = function (name , param )
1117
+ local pos = worldedit .pos1 [name ]
1118
+ if pos == nil then
1119
+ worldedit .player_notify (name , " No position selected" )
1120
+ return
1121
+ end
1122
+ if param == nil then
1123
+ worldedit .player_notify (name , " No filename specified" )
1124
+ return
1125
+ end
1126
+
1127
+ local path = minetest .get_worldpath () .. " /schems/" .. param .. " .mts"
1128
+ if minetest .place_schematic (pos , path ) == nil then
1129
+ worldedit .player_notify (name , " Failed to place Minetest schematic" , false )
1130
+ else
1131
+ worldedit .player_notify (name , " Placed Minetest schematic " .. param ..
1132
+ " at " .. minetest .pos_to_string (pos ), false )
1133
+ end
1134
+ end ,
1135
+ })
1136
+
1137
+ minetest .register_chatcommand (" /mtschemprob" , {
1138
+ params = " start/finish/get" ,
1139
+ description = " Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry" ,
1140
+ privs = {worldedit = true },
1141
+ func = function (name , param )
1142
+ if param == " start" then -- start probability setting
1143
+ worldedit .set_pos [name ] = " prob"
1144
+ worldedit .prob_list [name ] = {}
1145
+ worldedit .player_notify (name , " select Minetest schematic probability values by punching nodes" )
1146
+ elseif param == " finish" then -- finish probability setting
1147
+ worldedit .set_pos [name ] = nil
1148
+ worldedit .player_notify (name , " finished Minetest schematic probability selection" )
1149
+ elseif param == " get" then -- get all nodes that had probabilities set on them
1150
+ local text = " "
1151
+ local problist = worldedit .prob_list [name ]
1152
+ if problist == nil then
1153
+ return
1154
+ end
1155
+ for k ,v in pairs (problist ) do
1156
+ local prob = math.floor (((v [" prob" ] / 256 ) * 100 ) * 100 + 0.5 ) / 100
1157
+ text = text .. minetest .pos_to_string (v [" pos" ]) .. " : " .. prob .. " % | "
1158
+ end
1159
+ worldedit .player_notify (name , " Currently set node probabilities:" )
1160
+ worldedit .player_notify (name , text )
1161
+ else
1162
+ worldedit .player_notify (name , " unknown subcommand: " .. param )
1163
+ end
1164
+ end ,
1165
+ })
1166
+
1167
+ minetest .register_on_player_receive_fields (
1168
+ function (player , formname , fields )
1169
+ if (formname == " prob_val_enter" ) and (fields .text ~= " " ) then
1170
+ local name = player :get_player_name ()
1171
+ local prob_entry = {pos = worldedit .prob_pos [name ], prob = tonumber (fields .text )}
1172
+ local index = table .getn (worldedit .prob_list [name ]) + 1
1173
+ worldedit .prob_list [name ][index ] = prob_entry
1174
+ end
1175
+ end
1176
+ )
1177
+ end
0 commit comments