version 0.21
15
mods/3d_armor/3d_armor/README.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[mod] Visible Player Armor [3d_armor]
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
depends: default, inventory_plus, unified_skins
|
||||||
|
|
||||||
|
Adds craftable armor that is visible to other players. Each armor item worn contibutes to
|
||||||
|
a player's armor group level making them less vulnerable to weapons.
|
||||||
|
|
||||||
|
Armor takes damage when a player is hurt but also offers a percentage chance of healing.
|
||||||
|
|
||||||
|
default settings: [minetest.conf]
|
||||||
|
|
||||||
|
# Set number of seconds between armor updates.
|
||||||
|
3d_armor_update_time = 1
|
||||||
|
|
180
mods/3d_armor/3d_armor/armor.lua
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
local time = 0
|
||||||
|
local update_time = tonumber(minetest.setting_get("3d_armor_update_time"))
|
||||||
|
if not update_time then
|
||||||
|
update_time = 1
|
||||||
|
minetest.setting_set("3d_armor_update_time", tostring(update_time))
|
||||||
|
end
|
||||||
|
|
||||||
|
armor = {
|
||||||
|
player_hp = {},
|
||||||
|
elements = {"head", "torso", "legs", "feet"},
|
||||||
|
--[[formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
|
||||||
|
.."list[current_player;main;0,4.5;8,4;]"
|
||||||
|
.."list[detached:player_name_armor;armor_head;3,0;1,1;]"
|
||||||
|
.."list[detached:player_name_armor;armor_torso;3,1;1,1;]"
|
||||||
|
.."list[detached:player_name_armor;armor_legs;3,2;1,1;]"
|
||||||
|
.."list[detached:player_name_armor;armor_feet;3,3;1,1;]",]]
|
||||||
|
}
|
||||||
|
|
||||||
|
armor.def = {
|
||||||
|
state = 0,
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
armor.set_player_armor = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local armor_texture = uniskins.default_texture
|
||||||
|
local armor_level = 0
|
||||||
|
local state = 0
|
||||||
|
local items = 0
|
||||||
|
local textures = {}
|
||||||
|
for _,v in ipairs(self.elements) do
|
||||||
|
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||||
|
local level = stack:get_definition().groups["armor_"..v]
|
||||||
|
if level then
|
||||||
|
local item = stack:get_name()
|
||||||
|
table.insert(textures, item:gsub("%:", "_")..".png")
|
||||||
|
armor_level = armor_level + level
|
||||||
|
state = state + stack:get_wear()
|
||||||
|
items = items+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if table.getn(textures) > 0 then
|
||||||
|
armor_texture = table.concat(textures, "^")
|
||||||
|
end
|
||||||
|
local armor_groups = {fleshy=100}
|
||||||
|
if armor_level > 0 then
|
||||||
|
armor_groups.level = math.floor(armor_level / 20)
|
||||||
|
armor_groups.fleshy = 100 - armor_level
|
||||||
|
end
|
||||||
|
player:set_armor_groups(armor_groups)
|
||||||
|
uniskins.armor[name] = armor_texture
|
||||||
|
uniskins:update_player_visuals(player)
|
||||||
|
armor.def[name].state = state
|
||||||
|
armor.def[name].count = items
|
||||||
|
end
|
||||||
|
|
||||||
|
armor.update_armor = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local hp = player:get_hp() or 0
|
||||||
|
if hp == 0 or hp == self.player_hp[name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.player_hp[name] > hp then
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||||
|
if not armor_inv then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local heal_max = 0
|
||||||
|
local state = 0
|
||||||
|
local items = 0
|
||||||
|
for _,v in ipairs(self.elements) do
|
||||||
|
local stack = armor_inv:get_stack("armor_"..v, 1)
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
local use = stack:get_definition().groups["armor_use"] or 0
|
||||||
|
local heal = stack:get_definition().groups["armor_heal"] or 0
|
||||||
|
local item = stack:get_name()
|
||||||
|
stack:add_wear(use)
|
||||||
|
armor_inv:set_stack("armor_"..v, 1, stack)
|
||||||
|
player_inv:set_stack("armor_"..v, 1, stack)
|
||||||
|
state = state + stack:get_wear()
|
||||||
|
items = items+1
|
||||||
|
if stack:get_count() == 0 then
|
||||||
|
local desc = minetest.registered_items[item].description
|
||||||
|
if desc then
|
||||||
|
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||||
|
end
|
||||||
|
self:set_player_armor(player)
|
||||||
|
end
|
||||||
|
heal_max = heal_max + heal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
armor.def[name].state = state
|
||||||
|
armor.def[name].count = items
|
||||||
|
if heal_max > math.random(100) then
|
||||||
|
player:set_hp(self.player_hp[name])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.player_hp[name] = hp
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Register Callbacks
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if fields.armor then
|
||||||
|
local formspec = armor.formspec:gsub("player_name", name)
|
||||||
|
inventory_plus.set_inventory_formspec(player, formspec)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for field, _ in pairs(fields) do
|
||||||
|
if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
|
||||||
|
minetest.after(0, function(player)
|
||||||
|
uniskins.skin[name] = skins.skins[name]..".png"
|
||||||
|
uniskins:update_player_visuals(player)
|
||||||
|
end, player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
--inventory_plus.register_button(player,"armor", "Armor")
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local armor_inv = minetest.create_detached_inventory(name.."_armor",{
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
player:get_inventory():set_stack(listname, index, stack)
|
||||||
|
armor:set_player_armor(player)
|
||||||
|
end,
|
||||||
|
on_take = function(inv, listname, index, stack, player)
|
||||||
|
player:get_inventory():set_stack(listname, index, nil)
|
||||||
|
armor:set_player_armor(player)
|
||||||
|
end,
|
||||||
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
|
if inv:is_empty(listname) then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
for _,v in ipairs(armor.elements) do
|
||||||
|
local list = "armor_"..v
|
||||||
|
player_inv:set_size(list, 1)
|
||||||
|
armor_inv:set_size(list, 1)
|
||||||
|
armor_inv:set_stack(list, 1, player_inv:get_stack(list, 1))
|
||||||
|
end
|
||||||
|
armor.player_hp[name] = 0
|
||||||
|
armor.def[name] = {
|
||||||
|
state = 0,
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
|
minetest.after(0, function(player)
|
||||||
|
armor:set_player_armor(player)
|
||||||
|
end, player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
time = time + dtime
|
||||||
|
if time > update_time then
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
armor:update_armor(player)
|
||||||
|
end
|
||||||
|
time = 0
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
86
mods/3d_armor/3d_armor/armor_api.lua
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
|
||||||
|
armor_api = {
|
||||||
|
player_hp = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
armor_api.get_armor_textures = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local textures = {}
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||||
|
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||||
|
if stack:get_definition().groups["armor_"..v] then
|
||||||
|
local item = stack:get_name()
|
||||||
|
textures[v] = item:gsub("%:", "_")..".png"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return textures
|
||||||
|
end
|
||||||
|
|
||||||
|
armor_api.set_player_armor = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local armor_level = 0
|
||||||
|
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||||
|
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||||
|
local armor = stack:get_definition().groups["armor_"..v] or 0
|
||||||
|
armor_level = armor_level + armor
|
||||||
|
end
|
||||||
|
local armor_groups = {fleshy=100}
|
||||||
|
if armor_level > 0 then
|
||||||
|
armor_groups.level = math.floor(armor_level / 20)
|
||||||
|
armor_groups.fleshy = 100 - armor_level
|
||||||
|
end
|
||||||
|
player:set_armor_groups(armor_groups)
|
||||||
|
uniskins:update_player_visuals(player)
|
||||||
|
end
|
||||||
|
|
||||||
|
armor_api.update_armor = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local hp = player:get_hp()
|
||||||
|
if hp == nil or hp == 0 or hp == self.player_hp[name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.player_hp[name] > hp then
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_outfit"})
|
||||||
|
if armor_inv == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local heal_max = 0
|
||||||
|
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||||
|
local stack = armor_inv:get_stack("armor_"..v, 1)
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
local use = stack:get_definition().groups["armor_use"] or 0
|
||||||
|
local heal = stack:get_definition().groups["armor_heal"] or 0
|
||||||
|
local item = stack:get_name()
|
||||||
|
stack:add_wear(use)
|
||||||
|
armor_inv:set_stack("armor_"..v, 1, stack)
|
||||||
|
player_inv:set_stack("armor_"..v, 1, stack)
|
||||||
|
if stack:get_count() == 0 then
|
||||||
|
local desc = minetest.registered_items[item].description
|
||||||
|
if desc then
|
||||||
|
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||||
|
end
|
||||||
|
self:set_player_armor(player)
|
||||||
|
end
|
||||||
|
heal_max = heal_max + heal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if heal_max > math.random(100) then
|
||||||
|
player:set_hp(self.player_hp[name])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.player_hp[name] = hp
|
||||||
|
end
|
||||||
|
|
61
mods/3d_armor/3d_armor/crafting_guide.txt
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
3d_armor -- Crafting Guide
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Helmets:
|
||||||
|
|
||||||
|
+---+---+---+
|
||||||
|
| X | X | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
| | | |
|
||||||
|
+---+---+---+
|
||||||
|
|
||||||
|
[3d_armor:helmet_wood] X = [default:wood]
|
||||||
|
[3d_armor:helmet_steel] X = [default:steel_ingot]
|
||||||
|
[3d_armor:helmet_bronze] X = [default:bronze_ingot]
|
||||||
|
[3d_armor:helmet_diamond] X = [default:diamond]
|
||||||
|
|
||||||
|
Chestplates:
|
||||||
|
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | X | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | X | X |
|
||||||
|
+---+---+---+
|
||||||
|
|
||||||
|
[3d_armor:chestplate_wood] X = [default:wood]
|
||||||
|
[3d_armor:chestplate_steel] X = [default:steel_ingot]
|
||||||
|
[3d_armor:chestplate_bronze] X = [default:bronze_ingot]
|
||||||
|
[3d_armor:chestplate_diamond] X = [default:diamond]
|
||||||
|
|
||||||
|
Leggings:
|
||||||
|
|
||||||
|
+---+---+---+
|
||||||
|
| X | X | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
|
||||||
|
[3d_armor:leggings_wood] X = [default:wood]
|
||||||
|
[3d_armor:leggings_steel] X = [default:steel_ingot]
|
||||||
|
[3d_armor:leggings_bronze] X = [default:bronze_ingot]
|
||||||
|
[3d_armor:leggings_diamond] X = [default:diamond]
|
||||||
|
|
||||||
|
Boots:
|
||||||
|
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
| X | | X |
|
||||||
|
+---+---+---+
|
||||||
|
|
||||||
|
[3d_armor:boots_wood] X = [default:wood]
|
||||||
|
[3d_armor:boots_steel] X = [default:steel_ingot]
|
||||||
|
[3d_armor:boots_bronze] X = [default:bronze_ingot
|
||||||
|
[3d_armor:boots_diamond] X = [default:diamond]
|
||||||
|
|
2
mods/3d_armor/3d_armor/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
default
|
||||||
|
unified_skins
|
194
mods/3d_armor/3d_armor/init.lua
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor.lua")
|
||||||
|
|
||||||
|
-- Regisiter Head Armor
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:helmet_leather", {
|
||||||
|
description = "Leather Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_helmet_leather.png",
|
||||||
|
groups = {armor_head=5, armor_heal=0, armor_use=100},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:helmet_steel", {
|
||||||
|
description = "Steel Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_helmet_steel.png",
|
||||||
|
groups = {armor_head=10, armor_heal=5, armor_use=250},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:helmet_gold", {
|
||||||
|
description = "Golden Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_helmet_gold.png",
|
||||||
|
groups = {armor_head=15, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:helmet_diamond",{
|
||||||
|
description = "Diamond Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_helmet_diamond.png",
|
||||||
|
groups = {armor_head=20, armor_heal=15, armor_use=750},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:helmet_chain", {
|
||||||
|
description = "Chain Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_helmet_chain.png",
|
||||||
|
groups = {armor_head=15, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Regisiter Torso Armor
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:chestplate_leather", {
|
||||||
|
description = "Leather Chestplate",
|
||||||
|
inventory_image = "3d_armor_inv_chestplate_leather.png",
|
||||||
|
groups = {armor_torso=15, armor_heal=0, armor_use=100},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:chestplate_steel", {
|
||||||
|
description = "Steel Chestplate",
|
||||||
|
inventory_image = "3d_armor_inv_chestplate_steel.png",
|
||||||
|
groups = {armor_torso=20, armor_heal=5, armor_use=250},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:chestplate_gold", {
|
||||||
|
description = "Golden Chestplate",
|
||||||
|
inventory_image = "3d_armor_inv_chestplate_gold.png",
|
||||||
|
groups = {armor_torso=25, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:chestplate_diamond",{
|
||||||
|
description = "Diamond Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_chestplate_diamond.png",
|
||||||
|
groups = {armor_torso=30, armor_heal=15, armor_use=750},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:chestplate_chain", {
|
||||||
|
description = "Chain Chestplate",
|
||||||
|
inventory_image = "3d_armor_inv_chestplate_chain.png",
|
||||||
|
groups = {armor_torso=25, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Regisiter Leg Armor
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:leggings_leather", {
|
||||||
|
description = "Leather Leggings",
|
||||||
|
inventory_image = "3d_armor_inv_leggings_leather.png",
|
||||||
|
groups = {armor_legs=10, armor_heal=0, armor_use=100},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:leggings_steel", {
|
||||||
|
description = "Steel Leggings",
|
||||||
|
inventory_image = "3d_armor_inv_leggings_steel.png",
|
||||||
|
groups = {armor_legs=15, armor_heal=5, armor_use=250},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:leggings_gold", {
|
||||||
|
description = "Golden Leggings",
|
||||||
|
inventory_image = "3d_armor_inv_leggings_gold.png",
|
||||||
|
groups = {armor_legs=20, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:leggings_diamond",{
|
||||||
|
description = "Diamond Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_leggings_diamond.png",
|
||||||
|
groups = {armor_legs=25, armor_heal=15, armor_use=750},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:leggings_chain", {
|
||||||
|
description = "Chain Leggings",
|
||||||
|
inventory_image = "3d_armor_inv_leggings_chain.png",
|
||||||
|
groups = {armor_legs=20, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
-- Regisiter Boots
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:boots_leather", {
|
||||||
|
description = "Leather Boots",
|
||||||
|
inventory_image = "3d_armor_inv_boots_leather.png",
|
||||||
|
groups = {armor_feet=5, armor_heal=0, armor_use=100},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:boots_steel", {
|
||||||
|
description = "Steel Boots",
|
||||||
|
inventory_image = "3d_armor_inv_boots_steel.png",
|
||||||
|
groups = {armor_feet=10, armor_heal=5, armor_use=250},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:boots_gold", {
|
||||||
|
description = "Golden Boots",
|
||||||
|
inventory_image = "3d_armor_inv_boots_gold.png",
|
||||||
|
groups = {armor_feet=15, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:boots_diamond",{
|
||||||
|
description = "Diamond Helmet",
|
||||||
|
inventory_image = "3d_armor_inv_boots_diamond.png",
|
||||||
|
groups = {armor_feet=20, armor_heal=15, armor_use=750},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("3d_armor:boots_chain", {
|
||||||
|
description = "Chain Boots",
|
||||||
|
inventory_image = "3d_armor_inv_boots_chain.png",
|
||||||
|
groups = {armor_feet=15, armor_heal=10, armor_use=500},
|
||||||
|
wear = 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Register Craft Recipies
|
||||||
|
|
||||||
|
local craft_ingreds = {
|
||||||
|
leather = "default:wood",
|
||||||
|
steel = "default:steel_ingot",
|
||||||
|
gold = "default:gold_ingot",
|
||||||
|
diamond = "default:diamond",
|
||||||
|
chain = "fire:fire",
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v in pairs(craft_ingreds) do
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "3d_armor:helmet_"..k,
|
||||||
|
recipe = {
|
||||||
|
{v, v, v},
|
||||||
|
{v, "", v},
|
||||||
|
{"", "", ""},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "3d_armor:chestplate_"..k,
|
||||||
|
recipe = {
|
||||||
|
{v, "", v},
|
||||||
|
{v, v, v},
|
||||||
|
{v, v, v},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "3d_armor:leggings_"..k,
|
||||||
|
recipe = {
|
||||||
|
{v, v, v},
|
||||||
|
{v, "", v},
|
||||||
|
{v, "", v},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "3d_armor:boots_"..k,
|
||||||
|
recipe = {
|
||||||
|
{v, "", v},
|
||||||
|
{v, "", v},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
BIN
mods/3d_armor/3d_armor/textures/3d_armor_boots_chain.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_boots_diamond.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_boots_gold.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_boots_leather.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_boots_steel.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_chestplate_chain.png
Normal file
After Width: | Height: | Size: 643 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_chestplate_diamond.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_chestplate_gold.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_chestplate_leather.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_chestplate_steel.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_helmet_chain.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_helmet_diamond.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_helmet_gold.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_helmet_leather.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_helmet_steel.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_boots_chain.png
Normal file
After Width: | Height: | Size: 275 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_boots_diamond.png
Normal file
After Width: | Height: | Size: 248 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_boots_gold.png
Normal file
After Width: | Height: | Size: 248 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_boots_leather.png
Normal file
After Width: | Height: | Size: 433 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_boots_steel.png
Normal file
After Width: | Height: | Size: 241 B |
After Width: | Height: | Size: 318 B |
After Width: | Height: | Size: 277 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_chestplate_gold.png
Normal file
After Width: | Height: | Size: 277 B |
After Width: | Height: | Size: 472 B |
After Width: | Height: | Size: 269 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_helmet_chain.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_helmet_diamond.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_helmet_gold.png
Normal file
After Width: | Height: | Size: 229 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_helmet_leather.png
Normal file
After Width: | Height: | Size: 341 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_helmet_steel.png
Normal file
After Width: | Height: | Size: 216 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_leggings_chain.png
Normal file
After Width: | Height: | Size: 236 B |
After Width: | Height: | Size: 197 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_leggings_gold.png
Normal file
After Width: | Height: | Size: 197 B |
After Width: | Height: | Size: 372 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_inv_leggings_steel.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_leggings_chain.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_leggings_diamond.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_leggings_gold.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_leggings_leather.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
mods/3d_armor/3d_armor/textures/3d_armor_leggings_steel.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
7
mods/3d_armor/LICENSE.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
3D Armor - Visible Player Armor
|
||||||
|
===============================
|
||||||
|
|
||||||
|
Source Code: Copyright (C) 2013 Stuart Jones - LGPL
|
||||||
|
|
||||||
|
Special credit to Jordach and MirceaKitsune for providing the default 3d character model.
|
||||||
|
|
41
mods/3d_armor/README.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
Modpack - 3d Armor
|
||||||
|
==================
|
||||||
|
|
||||||
|
[mod] Unified Skins [unified_skins]
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
depends: default
|
||||||
|
|
||||||
|
A 3d character model re-texturing api used as the framework for this modpack.
|
||||||
|
|
||||||
|
Compatible with player skins mod [skins] by Zeg9 and Player Textures [player_textures] by sdzen.
|
||||||
|
|
||||||
|
Note: Currently only supports 64x32px player skins.
|
||||||
|
|
||||||
|
[mod] Visible Wielded Items [wieldview]
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
depends: unified_skins
|
||||||
|
|
||||||
|
Makes hand wielded items visible to other players.
|
||||||
|
|
||||||
|
Note: Currently only supports 16x16px texture packs, sorry!
|
||||||
|
|
||||||
|
[mod] Visible Player Armor [3d_armor]
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
depends: unified_skins, inventory_plus
|
||||||
|
|
||||||
|
Adds craftable armor that is visible to other players. Each armor item worn contributes to
|
||||||
|
a player's armor group level making them less vulnerable to weapons.
|
||||||
|
|
||||||
|
Armor takes damage when a player is hurt, however, many armor items offer a 'stackable'
|
||||||
|
percentage chance of restoring the lost health points.
|
||||||
|
|
||||||
|
[mod] Shields [shields]
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
depends: 3d_armor
|
||||||
|
|
||||||
|
Originally a part of 3d_armor, shields have been re-included as an optional extra.
|
||||||
|
If you do not want shields then simply remove the shields folder from the modpack.
|
0
mods/3d_armor/modpack.txt
Normal file
7
mods/3d_armor/unified_skins/README.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
A 3d character model re-texturing api used as the framework for this modpack.
|
||||||
|
|
||||||
|
depends: default
|
||||||
|
|
||||||
|
Compatible with player skins mod [skins] by Zeg9 and Player Textures [player_textures] by sdzen.
|
||||||
|
|
||||||
|
Note: Currently only 64x32px player skins.
|
1
mods/3d_armor/unified_skins/depends.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
default
|
47
mods/3d_armor/unified_skins/init.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
|
||||||
|
uniskins = {
|
||||||
|
skin = {},
|
||||||
|
armor = {},
|
||||||
|
wielditem = {},
|
||||||
|
default_skin = "character.png",
|
||||||
|
default_texture = "uniskins_trans.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
uniskins.update_player_visuals = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
player:set_properties({
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "uniskins_character.x",
|
||||||
|
textures = {
|
||||||
|
self.skin[name],
|
||||||
|
self.armor[name],
|
||||||
|
self.wielditem[name]
|
||||||
|
},
|
||||||
|
visual_size = {x=1, y=1},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
uniskins.skin[name] = uniskins.default_skin
|
||||||
|
uniskins.armor[name] = uniskins.default_texture
|
||||||
|
uniskins.wielditem[name] = uniskins.default_texture
|
||||||
|
if minetest.get_modpath("player_textures") then
|
||||||
|
local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
|
||||||
|
local f = io.open(filename..".png")
|
||||||
|
if f then
|
||||||
|
f:close()
|
||||||
|
uniskins.skin[name] = "player_"..name..".png"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if minetest.get_modpath("skins") then
|
||||||
|
local skin = skins.skins[name]
|
||||||
|
if skin and skins.get_type(skin) == skins.type.MODEL then
|
||||||
|
uniskins.skin[name] = skin..".png"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
BIN
mods/3d_armor/unified_skins/models/uniskins_character.blend
Normal file
9156
mods/3d_armor/unified_skins/models/uniskins_character.x
Normal file
BIN
mods/3d_armor/unified_skins/textures/uniskins_trans.png
Normal file
After Width: | Height: | Size: 146 B |
17
mods/3d_armor/wieldview/README.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[mod] visible wielded items [wieldview]
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
depends: default, unified_skins
|
||||||
|
|
||||||
|
Makes hand wielded items visible to other players. Compatible with player skins mod [skins].
|
||||||
|
|
||||||
|
Note: Currently only supports 16x16px texture packs, sorry!
|
||||||
|
|
||||||
|
default settings: [minetest.conf]
|
||||||
|
|
||||||
|
# Set number of seconds between visible wielded item updates.
|
||||||
|
wieldview_update_time = 2
|
||||||
|
|
||||||
|
# Show nodes as tiles, disabled by default
|
||||||
|
wieldview_node_tiles = false
|
||||||
|
|
2
mods/3d_armor/wieldview/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
default
|
||||||
|
unified_skins
|
73
mods/3d_armor/wieldview/init.lua
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
local time = 0
|
||||||
|
local update_time = tonumber(minetest.setting_get("wieldview_update_time"))
|
||||||
|
if not update_time then
|
||||||
|
update_time = 2
|
||||||
|
minetest.setting_set("wieldview_update_time", tostring(update_time))
|
||||||
|
end
|
||||||
|
local node_tiles = minetest.setting_getbool("wieldview_node_tiles")
|
||||||
|
if not node_tiles then
|
||||||
|
node_tiles = false
|
||||||
|
minetest.setting_set("wieldview_node_tiles", "false")
|
||||||
|
end
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
|
||||||
|
|
||||||
|
wieldview = {
|
||||||
|
wielded_item = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
wieldview.get_item_texture = function(self, item)
|
||||||
|
local texture = uniskins.default_texture
|
||||||
|
if item ~= "" then
|
||||||
|
if minetest.registered_items[item] then
|
||||||
|
if minetest.registered_items[item].inventory_image ~= "" then
|
||||||
|
texture = minetest.registered_items[item].inventory_image
|
||||||
|
elseif node_tiles == true and minetest.registered_items[item].tiles then
|
||||||
|
texture = minetest.registered_items[item].tiles[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if wieldview_transform[item] then
|
||||||
|
texture = texture.."^[transform"..wieldview_transform[item]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return texture
|
||||||
|
end
|
||||||
|
|
||||||
|
wieldview.update_wielded_item = function(self, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local stack = player:get_wielded_item()
|
||||||
|
local item = stack:get_name()
|
||||||
|
if not item then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.wielded_item[name] then
|
||||||
|
if self.wielded_item[name] == item then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
uniskins.wielditem[name] = self:get_item_texture(item)
|
||||||
|
uniskins:update_player_visuals(player)
|
||||||
|
end
|
||||||
|
self.wielded_item[name] = item
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
wieldview.wielded_item[name] = ""
|
||||||
|
minetest.after(0, function(player)
|
||||||
|
wieldview:update_wielded_item(player)
|
||||||
|
end, player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
time = time + dtime
|
||||||
|
if time > update_time then
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
wieldview:update_wielded_item(player)
|
||||||
|
end
|
||||||
|
time = 0
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
24
mods/3d_armor/wieldview/transform.lua
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
-- Wielded Item Transformations - http://dev.minetest.net/texture
|
||||||
|
|
||||||
|
wieldview_transform = {
|
||||||
|
["default:torch"]="R270",
|
||||||
|
["default:sapling"]="R270",
|
||||||
|
["flowers:dandelion_white"]="R270",
|
||||||
|
["flowers:dandelion_yellow"]="R270",
|
||||||
|
["flowers:geranium"]="R270",
|
||||||
|
["flowers:rose"]="R270",
|
||||||
|
["flowers:tulip"]="R270",
|
||||||
|
["flowers:viola"]="R270",
|
||||||
|
["bucket:bucket_empty"]="R270",
|
||||||
|
["bucket:bucket_water"]="R270",
|
||||||
|
["bucket:bucket_lava"]="R270",
|
||||||
|
["screwdriver:screwdriver"]="R270",
|
||||||
|
["screwdriver:screwdriver1"]="R270",
|
||||||
|
["screwdriver:screwdriver2"]="R270",
|
||||||
|
["screwdriver:screwdriver3"]="R270",
|
||||||
|
["screwdriver:screwdriver4"]="R270",
|
||||||
|
["vessels:glass_bottle"]="R270",
|
||||||
|
["vessels:drinking_glass"]="R270",
|
||||||
|
["vessels:steel_bottle"]="R270",
|
||||||
|
}
|
||||||
|
|
452
mods/DOM/domb/domb.lua
Normal file
|
@ -0,0 +1,452 @@
|
||||||
|
--Para ser usado no gerador aleatório.
|
||||||
|
domb.aleatorio = nil
|
||||||
|
|
||||||
|
--Inicialização da variável aleatoria para que seja usada quando necessário.
|
||||||
|
minetest.after(0.01, function()
|
||||||
|
domb.aleatorio=PseudoRandom(200 + (minetest.env:get_timeofday()*100000))
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Identifica vizinhança de um ponto, os pontos retornados tem a parte superior como ponto 1.
|
||||||
|
-- Totaliza atualmente água, lava e ar. Contabiliza totais e separando fontes de fluindo.
|
||||||
|
|
||||||
|
function DOM_vizinhos(ponto)
|
||||||
|
local p = {}
|
||||||
|
local vx=0
|
||||||
|
local vy=0
|
||||||
|
local vz=0
|
||||||
|
local tipo = ''
|
||||||
|
local pontos = 0
|
||||||
|
-- p.total = 0
|
||||||
|
p.total_ar = 0
|
||||||
|
p.total_lava = 0
|
||||||
|
p.total_lava_fonte = 0
|
||||||
|
p.total_agua = 0
|
||||||
|
p.total_agua_fonte = 0
|
||||||
|
p.n = {'','','','','',''}
|
||||||
|
|
||||||
|
--Começa pelo y (altura) de baixo para cima, sendo assim os 3 últimos testes serão os
|
||||||
|
for vy=-1,1 do
|
||||||
|
for vx=-1, 1 do
|
||||||
|
for vz=-1,1 do
|
||||||
|
p.n[pontos] = ''
|
||||||
|
tipo = minetest.env:get_node({x=(ponto.x + vx), y=(ponto.y + vy), z=(ponto.z + vz)}).name
|
||||||
|
--print("Ponto pego: " .. tipo)
|
||||||
|
-- Busca pontos onde dois eixos estejam zerados e um outro tenha valor.
|
||||||
|
if vx==0 and vy==0 and vz==0 then
|
||||||
|
-- Ignora caso seja exatamente o ponto testado.
|
||||||
|
elseif (vx==0 and vy==0 and vz~= 0) or (vx==0 and vz==0 and vy~=0) or (vy==0 and vz==0 and vx~=0) then
|
||||||
|
--print("Ponto: " .. tostring(vx) .. " " .. tostring(vy) .. " " .. tostring(vz) .. " (Pontos: " .. tostring(pontos) .. ")")
|
||||||
|
--print("Tipo: " .. tipo)
|
||||||
|
if tipo == "default:air" or tipo == "air" then
|
||||||
|
p.total_ar = p.total_ar + 1
|
||||||
|
--print("Ar contado, total de " .. tostring(p.total_ar))
|
||||||
|
elseif tipo == "default:water_source" or tipo == "default:water_flowing" or tipo == "default:water" then
|
||||||
|
p.total_agua = p.total_agua + 1
|
||||||
|
--print("Agua contada, total de " .. tostring(p.total_agua) .. ", tipo:" .. tipo)
|
||||||
|
if tipo == "default:water_source" then
|
||||||
|
p.total_agua_fonte = p.total_agua_fonte + 1
|
||||||
|
end
|
||||||
|
elseif tipo == "default:lava_source" or tipo == "default:lava_flowing" then
|
||||||
|
p.total_lava = p.total_lava + 1
|
||||||
|
if tipo == "default:lava_source" then
|
||||||
|
p.total_lava_fonte = p.total_lava_fonte + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
p.n[pontos] = tipo
|
||||||
|
pontos = pontos + 1
|
||||||
|
--if(vx==0 and vz==0 and vy==-1) then
|
||||||
|
--print("Ponto n para x=0, y=-1 e z=0 é o : " .. tostring(pontos))
|
||||||
|
--end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
p.total_lava_corrente = p.total_lava - p.total_lava_fonte
|
||||||
|
p.total_agua_corrente = p.total_agua - p.total_agua_fonte
|
||||||
|
|
||||||
|
-- print("Retornando total ar de :" .. tostring(p.total_ar))
|
||||||
|
return(p)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Rotina que pega o texto e remove eventuais símbolos não desejados.
|
||||||
|
]]--
|
||||||
|
|
||||||
|
function DOM_remove_simbolos(texto)
|
||||||
|
local t = ""
|
||||||
|
|
||||||
|
if texto == "" or texto == nil then
|
||||||
|
return("")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remoção de símbolos proibidos.
|
||||||
|
t=string.gsub(texto, "(%[)", "")
|
||||||
|
t=string.gsub(t, "(%])", "")
|
||||||
|
t=string.gsub(t, "(%()", "")
|
||||||
|
t=string.gsub(t, "(%))", "")
|
||||||
|
t=string.gsub(t, "(#)", "")
|
||||||
|
t=string.gsub(t, "(@)", "")
|
||||||
|
t=string.gsub(t, "(?)", "")
|
||||||
|
t=string.gsub(t, "(!)", "")
|
||||||
|
t=string.gsub(t, "($)", "")
|
||||||
|
t=string.gsub(t, "(%%)", "")
|
||||||
|
t=string.gsub(t, "(&)", "")
|
||||||
|
t=string.gsub(t, "(*)", "")
|
||||||
|
t=string.gsub(t, "(=)", "")
|
||||||
|
|
||||||
|
return(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Rotina que pega o texto e remove eventuais espaços no inicio, no final e espacos duplos no meio da string.
|
||||||
|
]]--
|
||||||
|
|
||||||
|
function DOM_remove_espacos(texto)
|
||||||
|
local t = ""
|
||||||
|
|
||||||
|
if texto == "" or texto == nil then
|
||||||
|
return("")
|
||||||
|
end
|
||||||
|
t = texto
|
||||||
|
|
||||||
|
--Remove todos os espaços duplos que encontrar.
|
||||||
|
while string.find(t," ") do
|
||||||
|
t=string.gsub(texto, "( )", " ")
|
||||||
|
end
|
||||||
|
|
||||||
|
--Remove espaços no final e no início do texto.
|
||||||
|
t=string.trim(t)
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Rotina usada para inspecionar elementos retornando um relatório na linha de comando.
|
||||||
|
Aceita quantidade variável de parâmetros sendo:
|
||||||
|
1) Arquivo
|
||||||
|
2) Linha
|
||||||
|
3) Teste
|
||||||
|
4) Parâmetros
|
||||||
|
|
||||||
|
]]--
|
||||||
|
function DOM_inspeciona_condicional(...)
|
||||||
|
if(arg[3] ~= true) then return end
|
||||||
|
|
||||||
|
local a=0
|
||||||
|
local linha= {tostring(debug.getinfo(2, 'l').currentline)}
|
||||||
|
local arquivo = debug.getinfo(2, 'S').short_src or debug.getinfo(2,'S').source
|
||||||
|
if string.len(arquivo) > 25 then
|
||||||
|
arquivo = "..." arquivo:sub(string.len(arquivo)- 22)
|
||||||
|
end
|
||||||
|
|
||||||
|
if arg[2] ~= nil then
|
||||||
|
linha = arg[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
if arg[1] ~= nil then
|
||||||
|
arquivo = arg[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("====================================== [DOM Inspeciona] =======")
|
||||||
|
print(arquivo .. " [" .. linha .. "]")
|
||||||
|
print(tostring(arg[4]))
|
||||||
|
print("---------------------------------------------------------------")
|
||||||
|
for a=5,#arg,1 do
|
||||||
|
print(string.format("%s", dump(arg[a])))
|
||||||
|
end
|
||||||
|
print("");
|
||||||
|
print("-------------------------------------- [DOM Inspeciona] ---Fim-")
|
||||||
|
print(arquivo .. " [" .. linha .. "]")
|
||||||
|
print("===============================================================")
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Chama a rotina de inpecao sem a necessidade de passar a condicao.
|
||||||
|
]]--
|
||||||
|
|
||||||
|
function DOM_inspeciona(...)
|
||||||
|
local linha = debug.getinfo(2, 'l').currentline
|
||||||
|
local arquivo = debug.getinfo(2, 'S').short_src or debug.getinfo(2,'S').source
|
||||||
|
if string.len(arquivo) > 25 then
|
||||||
|
arquivo = "..." .. arquivo:sub(arquivo:len(arquivo)- 22)
|
||||||
|
end
|
||||||
|
|
||||||
|
DOM_inspeciona_condicional(arquivo,linha,true,...)
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Inspeção simplificada que não necessita de valores adicionais, apenas o titulo. Mostra a linha
|
||||||
|
--]]
|
||||||
|
function DOM_inspeciona_r(titulo)
|
||||||
|
if titulo == nil then
|
||||||
|
titulo = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local linha = debug.getinfo(2, 'l').currentline
|
||||||
|
local arquivo = debug.getinfo(2, 'S').short_src or debug.getinfo(2,'S').source
|
||||||
|
if string.len(arquivo) > 25 then
|
||||||
|
arquivo = "..." arquivo:sub(string.len(arquivo)- 22)
|
||||||
|
end
|
||||||
|
|
||||||
|
print(arquivo .. " [" .. linha .. "] " .. titulo)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Realiza a união do string.format com o print simulando o printf do C++.
|
||||||
|
--]]
|
||||||
|
function DOM_print(...)
|
||||||
|
print(string.format(...))
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Permite envio de mensagens para o log no minitest ao invés do terminal, segue a formatação do string.format
|
||||||
|
--]]
|
||||||
|
function DOM_log(...)
|
||||||
|
-- action, error, info
|
||||||
|
minetest.log("action", "[DOM]"..string.format(...))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Centraliza os valores na matriz 5x5 de acordo com a largura e altura recebidas gerando automaticamente uma margem ao redor da fórmula.
|
||||||
|
--]]
|
||||||
|
function DOM_centraliza_matriz_5x5(matriz, largura, altura)
|
||||||
|
--Centraliza se largura ou altura forem menores que 5.
|
||||||
|
--Largura ou Altura/Critério: 5/Ignora, 4/Ignora, 3/1 de margem, 2/1 de margem, 1/2 de margem
|
||||||
|
local i = 0
|
||||||
|
a=matriz[1][3]
|
||||||
|
if a~=nil then
|
||||||
|
if string.find(a,"gravel") then
|
||||||
|
i = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--DOM_inspeciona("Rotina centraliza matriz: ",matriz)
|
||||||
|
|
||||||
|
local margem_superior = math.floor((5-altura)/2)
|
||||||
|
local margem_lateral = math.floor((5-largura)/2)
|
||||||
|
local d_a = margem_lateral
|
||||||
|
local d_b = margem_superior
|
||||||
|
|
||||||
|
if margem_superior > 0 or margem_lateral > 0 then
|
||||||
|
for a=5,margem_lateral+1,-1 do --Colunas
|
||||||
|
for b=5,margem_superior+1,-1 do --Linhas
|
||||||
|
-- Transfere valor da posição original para a deslocada tornando o valor da posição original como nulo.
|
||||||
|
matriz[a][b] = matriz[a-d_a][b-d_b]
|
||||||
|
matriz[a-d_a][b-d_b] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--DOM_inspeciona("Matriz convertida:",matriz)
|
||||||
|
|
||||||
|
---DOM_inspeciona("Saida da rotina centraliza matriz: ",matriz)
|
||||||
|
return matriz
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Cria matriz 5x5 a patir de uma linha de itens separados por virgulas
|
||||||
|
- Ignora itens a partir do sexto...
|
||||||
|
--]]
|
||||||
|
function DOM_cria_matriz_5x5(itens)
|
||||||
|
local m_5x5={{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil}},{{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil}},{{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil}},{{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil}},{{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil},{nil,nil,nil,nil,nil}}
|
||||||
|
local i = {}
|
||||||
|
local a = 0
|
||||||
|
local largura = 0
|
||||||
|
|
||||||
|
if itens ~= "" and itens ~= nil then
|
||||||
|
if itens.find(itens,",") then
|
||||||
|
else
|
||||||
|
table.insert(i,itens)
|
||||||
|
a = a + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
while string.find(itens,",") do
|
||||||
|
lido = string.sub(itens,1,itens.find(","))
|
||||||
|
itens = string.sub(itens,itens.find(",")+1)
|
||||||
|
table.insert(i,lido)
|
||||||
|
a = a + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
largura = a
|
||||||
|
while a < 5 do
|
||||||
|
table.insert(i,nil)
|
||||||
|
a = a + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for a=1,5,1 do --Colunas
|
||||||
|
-- Transfere valores para a linha 3.
|
||||||
|
m_5x5[3][a] = i[a]
|
||||||
|
end
|
||||||
|
|
||||||
|
m_5x5 = DOM_centraliza_matriz_5x5(m_5x5,largura,5)
|
||||||
|
|
||||||
|
return m_5x5
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Converte valor posicional xyz para valor em texto separados por virgulas e sem espaços:
|
||||||
|
<classe> -> "x,y,z"
|
||||||
|
]]--
|
||||||
|
function DOM_de_xyz_para_texto(valor)
|
||||||
|
if valor==nil then
|
||||||
|
return "0,0,0"
|
||||||
|
end
|
||||||
|
|
||||||
|
local r = ""
|
||||||
|
r = tostring(valor.x)..",".. tostring(valor.y) ..",".. tostring(valor.z)
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Converte valor posicional de texto para a classe xyz:
|
||||||
|
"x,y,z" -> <classe>
|
||||||
|
|
||||||
|
|
||||||
|
Convert values x,y,z in text to the class xyz:
|
||||||
|
"x,y,z" -> <classe>
|
||||||
|
]]--
|
||||||
|
function DOM_de_texto_para_xyz(valor)
|
||||||
|
if valor==nil or recebido == "" then
|
||||||
|
return {x=0,y=0,z=0}
|
||||||
|
end
|
||||||
|
|
||||||
|
--print("Recebido:".. dump(valor))
|
||||||
|
local r={x=0,y=0,z=0}
|
||||||
|
local d=valor
|
||||||
|
r.x=tonumber(d:sub(1,string.find(d,",")-1))
|
||||||
|
|
||||||
|
d=d:sub(string.find(d,",")+1)
|
||||||
|
r.y= tonumber(d:sub(1,string.find(d,",")-1))
|
||||||
|
|
||||||
|
d=d:sub(string.find(d,",")+1)
|
||||||
|
r.z= tonumber(d)
|
||||||
|
--print("Retorno:".. dump(r))
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Mensagem básica de carga
|
||||||
|
Recebe:
|
||||||
|
nome do modulo, caminho do modulo
|
||||||
|
|
||||||
|
Basic load message
|
||||||
|
Params:
|
||||||
|
module name, path of the module
|
||||||
|
]]--
|
||||||
|
function DOM_mb(m,c)
|
||||||
|
-- minetest.log("action", "[DOM]"..m.." loaded from "..minetest.get_modpath(minetest.get_current_modname()))
|
||||||
|
minetest.log("action", "[DOM]"..m.." is ready.")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Registra comando para chamar rotinas de apoio pelo chat com o comando /dom_util <comando> <parametros...>
|
||||||
|
Comandos:
|
||||||
|
apaga x y z Apaga node no lugar especificado.
|
||||||
|
|
||||||
|
if comando == "comando" then -- Comando?
|
||||||
|
minetest.chat_send_player(name, "[DOM]dom_util: ".."Comando?")
|
||||||
|
elseif comando == "comando2" then -- Comando?
|
||||||
|
minetest.chat_send_player(name, "[DOM]dom_util: ".."Comando2?")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--]]
|
||||||
|
function DOM_registra_comandos_de_uso_geral()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Quebra texto em lista utilizando espaços como delimitadores.
|
||||||
|
--]]
|
||||||
|
function DOM_quebra_texto_em_lista (texto)
|
||||||
|
local lista = {}
|
||||||
|
|
||||||
|
lista = DOM_quebra_texto_em_lista_por_delimitador (texto, " ")
|
||||||
|
|
||||||
|
return lista
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Quebra texto em lista utilizando delimitador pedido.
|
||||||
|
--]]
|
||||||
|
function DOM_quebra_texto_em_lista_por_delimitador (texto, delimitador)
|
||||||
|
local lista = {}
|
||||||
|
lista.tamanho = 0
|
||||||
|
local t = ""
|
||||||
|
local fatia = ""
|
||||||
|
|
||||||
|
if texto==nil or texto =="" then return nil end -- Caso texto recebido não seja válido retorna nulo
|
||||||
|
if delimitador==nil or delimitador =="" then return nil end -- Caso delimitador recebido não seja válido retorna nulo
|
||||||
|
|
||||||
|
--print("Texto: \'"..dump(texto).."\'")
|
||||||
|
t = texto
|
||||||
|
if not t:find(delimitador) then -- Cria lista com um item caso não seja encontrado nenhum delimitador.
|
||||||
|
table.insert(lista, t)
|
||||||
|
lista.tamanho = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
while t:find(delimitador) do -- Enquanto o delimitador puder ser encontrado no texto, fica no laço.
|
||||||
|
fatia = t:sub(1,t:find(delimitador)-1)
|
||||||
|
table.insert(lista,fatia)
|
||||||
|
lista.tamanho= lista.tamanho + 1
|
||||||
|
|
||||||
|
t = t:sub(t:find(delimitador)+1)
|
||||||
|
|
||||||
|
if not t:find(delimitador) then -- Adiciona o item que sobra ao final após o último delimitador ser removido.
|
||||||
|
table.insert(lista,t)
|
||||||
|
lista.tamanho= lista.tamanho + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--print("saída: "..dump(table.tamanho).." => "..dump(table))
|
||||||
|
return lista
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copia ponto evitando que seja passada matriz por referência
|
||||||
|
--]]
|
||||||
|
function DOM_copia_ponto(origem,destino)
|
||||||
|
--DOM_inspeciona("Copia ponto:",origem,destino)
|
||||||
|
if destino == nil then
|
||||||
|
destino = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
destino.x = tonumber(origem.x)
|
||||||
|
destino.y = tonumber(origem.y)
|
||||||
|
destino.z = tonumber(origem.z)
|
||||||
|
|
||||||
|
return destino
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Pega valores meta de um item, provavelmente se aplica a nodos.
|
||||||
|
function DOM_get_item_meta (item)
|
||||||
|
local r = {}
|
||||||
|
local v = item["metadata"]
|
||||||
|
|
||||||
|
if v==nil then
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
if string.find(v,"return {") then
|
||||||
|
r = minetest.deserialize(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Associa valores meta a um item, provavelmente se aplica a nodos.
|
||||||
|
function DOM_set_item_meta(i, v)
|
||||||
|
local t = minetest.serialize(v)
|
||||||
|
|
||||||
|
i["metadata"]=t
|
||||||
|
end
|
6
mods/DOM/domb/init.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
domb = {}
|
||||||
|
|
||||||
|
--DOM base system library
|
||||||
|
dofile(minetest.get_modpath("domb").."/domb.lua")
|
||||||
|
|
||||||
|
DOM_registra_comandos_de_uso_geral()
|
0
mods/DOM/modpack.txt
Normal file
2
mods/DOM/watch/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
default
|
||||||
|
domb
|
15
mods/DOM/watch/init.lua
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--[[
|
||||||
|
DOM, renew of the watch mod
|
||||||
|
|
||||||
|
Original from Echo, here: http://forum.minetest.net/viewtopic.php?id=3795
|
||||||
|
]]--
|
||||||
|
|
||||||
|
|
||||||
|
--Rotinas usadas pelo mod
|
||||||
|
dofile(minetest.get_modpath("watch").."/rotinas.lua")
|
||||||
|
|
||||||
|
--Declarações dos objetos
|
||||||
|
dofile(minetest.get_modpath("watch").."/itens.lua")
|
||||||
|
|
||||||
|
-- Apenas para indicar que este módulo foi completamente carregado.
|
||||||
|
DOM_mb(minetest.get_current_modname(),minetest.get_modpath(minetest.get_current_modname()))
|
20
mods/DOM/watch/itens.lua
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
-- Watch recipe
|
||||||
|
minetest.register_craft({
|
||||||
|
description = "Watch",
|
||||||
|
output = 'watch:watch',
|
||||||
|
groups = {not_in_creative_inventory=1},
|
||||||
|
recipe = {
|
||||||
|
{'', 'default:gold_ingot', ''},
|
||||||
|
{'default:gold_ingot', 'default:redstone_dust', 'default:gold_ingot'},
|
||||||
|
{'', 'default:gold_ingot', ''}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
--Watch tool
|
||||||
|
watch.registra_item("watch:watch",watch.images_a[3],true)
|
||||||
|
|
||||||
|
--Faces
|
||||||
|
for a=0,11,1 do
|
||||||
|
watch.registra_item("watch:watch_a"..tostring(a),watch.images_a[a+1],false)
|
||||||
|
end
|
139
mods/DOM/watch/rotinas.lua
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
--[[
|
||||||
|
DOM, renew of the watch mod
|
||||||
|
|
||||||
|
Original from Echo, here: http://forum.minetest.net/viewtopic.php?id=3795
|
||||||
|
]]--
|
||||||
|
|
||||||
|
watch = {}
|
||||||
|
watch.ultimo_tempo = -1
|
||||||
|
|
||||||
|
-- Image of all 12 possible faces, only cover hours, a day is to short to lost time with game minutes... :-P
|
||||||
|
watch.images_a = {
|
||||||
|
"watch_a0.png",
|
||||||
|
"watch_a1.png",
|
||||||
|
"watch_a2.png",
|
||||||
|
"watch_a3.png",
|
||||||
|
"watch_a4.png",
|
||||||
|
"watch_a5.png",
|
||||||
|
"watch_a6.png",
|
||||||
|
"watch_a7.png",
|
||||||
|
"watch_a8.png",
|
||||||
|
"watch_a9.png",
|
||||||
|
"watch_a10.png",
|
||||||
|
"watch_a11.png",
|
||||||
|
}
|
||||||
|
watch.images_d={
|
||||||
|
"watch_d0.png",
|
||||||
|
"watch_d1.png",
|
||||||
|
"watch_d2.png",
|
||||||
|
"watch_d3.png",
|
||||||
|
"watch_d4.png",
|
||||||
|
"watch_d5.png",
|
||||||
|
"watch_d6.png",
|
||||||
|
"watch_d7.png",
|
||||||
|
"watch_d8.png",
|
||||||
|
"watch_d9.png",
|
||||||
|
"watch_d10.png",
|
||||||
|
"watch_d11.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
--Catch the sever time and convert to hour, 12000 = 12h = 0.5, 6000 = 6h = 0.25
|
||||||
|
function watch.pega_hora(tipo)
|
||||||
|
local tempo_r = "12:00"
|
||||||
|
local t = minetest.env:get_timeofday()
|
||||||
|
local tempo = t*24 -- Get the time
|
||||||
|
local tempo_h = math.floor(tempo) -- Get 24h only, losting minutes
|
||||||
|
local tempo_m =math.floor((tempo - tempo_h)*60) --Get only minutes
|
||||||
|
|
||||||
|
--Hour
|
||||||
|
tempo_h_12=tempo_h
|
||||||
|
if tempo_h > 12 then -- Converte time to time in 12h format
|
||||||
|
tempo_h_12 = tempo_h - 12
|
||||||
|
end
|
||||||
|
|
||||||
|
if tipo==2 then -- hh
|
||||||
|
return(tostring(tempo_h_12))
|
||||||
|
end
|
||||||
|
|
||||||
|
tempo_r = tostring(tempo_h) .. ":"
|
||||||
|
|
||||||
|
--Minutes
|
||||||
|
if tempo_m < 10 then -- Add a zero at left if need.
|
||||||
|
tempo_r = tempo_r .. "0"
|
||||||
|
end
|
||||||
|
tempo_r = tempo_r .. tostring(tempo_m)
|
||||||
|
|
||||||
|
return(tempo_r) --HH:MM
|
||||||
|
end
|
||||||
|
|
||||||
|
--When someone try use the watch.
|
||||||
|
function watch.usa (itemstack, user, pointed_thing)
|
||||||
|
item=itemstack:to_table()
|
||||||
|
local meta=DOM_get_item_meta(item)
|
||||||
|
local w_type="a"
|
||||||
|
|
||||||
|
if meta~=nil then
|
||||||
|
w_type = meta["w_type"]
|
||||||
|
end
|
||||||
|
|
||||||
|
--DOM_inspeciona_r("Valores no meta:"..dump(meta))
|
||||||
|
--print("Relógio em modo: "..w_type)
|
||||||
|
meta["time"] = watch.pega_hora(1)
|
||||||
|
meta["w_type"] = w_type
|
||||||
|
DOM_set_item_meta(item, meta)
|
||||||
|
meta=DOM_get_item_meta(item)
|
||||||
|
--DOM_inspeciona_r("Valores no meta:"..dump(meta))
|
||||||
|
minetest.chat_send_player(user:get_player_name(), "[Watch] Time now is:" .. meta["time"])
|
||||||
|
|
||||||
|
itemstack:replace(item)
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Register itens
|
||||||
|
function watch.registra_item(nome,imagem,aparece_nas_receitas)
|
||||||
|
local g = 1
|
||||||
|
if aparece_nas_receitas then
|
||||||
|
g = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
--DOM_inspeciona_r("Registrando item "..nome..","..imagem)
|
||||||
|
minetest.register_tool(nome, {
|
||||||
|
description = "Watch",
|
||||||
|
inventory_image = imagem,
|
||||||
|
groups = {not_in_creative_inventory=g},
|
||||||
|
metadata = {w_type="d"},
|
||||||
|
wield_image = "",
|
||||||
|
stack_max = 1,
|
||||||
|
on_use = watch.usa,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
local t="a" -- d to digital, a to analogic
|
||||||
|
|
||||||
|
now = watch.pega_hora(2)
|
||||||
|
--DOM_inspeciona_r("Hora:"..now)
|
||||||
|
if now == "12" then now = "0" end
|
||||||
|
|
||||||
|
if watch.ultimo_tempo == now then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
watch.ultimo_tempo = now
|
||||||
|
|
||||||
|
|
||||||
|
local players = minetest.get_connected_players()
|
||||||
|
for i,player in ipairs(players) do
|
||||||
|
|
||||||
|
if string.sub(player:get_wielded_item():get_name(), 0, 11) == "watch:watch" then
|
||||||
|
player:set_wielded_item("watch:watch_"..t..now)
|
||||||
|
end
|
||||||
|
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
|
if i<9 and string.sub(stack:get_name(), 0, 11) == "watch:watch" then
|
||||||
|
player:get_inventory():remove_item("main", stack:get_name())
|
||||||
|
player:get_inventory():add_item("main", "watch:watch_"..t..now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
BIN
mods/DOM/watch/textures/watch_a0.png
Normal file
After Width: | Height: | Size: 485 B |
BIN
mods/DOM/watch/textures/watch_a1.png
Normal file
After Width: | Height: | Size: 490 B |
BIN
mods/DOM/watch/textures/watch_a10.png
Normal file
After Width: | Height: | Size: 496 B |
BIN
mods/DOM/watch/textures/watch_a11.png
Normal file
After Width: | Height: | Size: 490 B |
BIN
mods/DOM/watch/textures/watch_a2.png
Normal file
After Width: | Height: | Size: 497 B |
BIN
mods/DOM/watch/textures/watch_a3.png
Normal file
After Width: | Height: | Size: 491 B |
BIN
mods/DOM/watch/textures/watch_a4.png
Normal file
After Width: | Height: | Size: 493 B |
BIN
mods/DOM/watch/textures/watch_a5.png
Normal file
After Width: | Height: | Size: 490 B |
BIN
mods/DOM/watch/textures/watch_a6.png
Normal file
After Width: | Height: | Size: 484 B |
BIN
mods/DOM/watch/textures/watch_a7.png
Normal file
After Width: | Height: | Size: 491 B |
BIN
mods/DOM/watch/textures/watch_a8.png
Normal file
After Width: | Height: | Size: 495 B |
BIN
mods/DOM/watch/textures/watch_a9.png
Normal file
After Width: | Height: | Size: 490 B |
376
mods/WorldEdit/Chat Commands.md
Normal file
|
@ -0,0 +1,376 @@
|
||||||
|
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` |
|
||||||
|
| `//hspr` | `//hollowsphere` |
|
||||||
|
| `//spr` | `//sphere` |
|
||||||
|
| `//hdo` | `//hollowdome` |
|
||||||
|
| `//do` | `//dome` |
|
||||||
|
| `//hcyl` | `//hollowcylinder` |
|
||||||
|
|
||||||
|
### `//about`
|
||||||
|
|
||||||
|
Get information about the mod.
|
||||||
|
|
||||||
|
//about
|
||||||
|
|
||||||
|
### `//inspect on/off/1/0/true/false/yes/no/enable/disable/<blank>`
|
||||||
|
|
||||||
|
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
|
||||||
|
//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 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 Blue Lightstone
|
||||||
|
//set dirt with grass
|
||||||
|
|
||||||
|
### `//mix <node1> ...`
|
||||||
|
|
||||||
|
Fill the current WorldEdit region with a random mix of `<node1>`, `...`.
|
||||||
|
|
||||||
|
//mix air
|
||||||
|
//mix cactus stone glass sandstone
|
||||||
|
//mix Bronze
|
||||||
|
//mix default:cobble air
|
||||||
|
|
||||||
|
### `//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
|
||||||
|
|
||||||
|
### `//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
|
||||||
|
|
||||||
|
### `//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
|
661
mods/WorldEdit/LICENSE.txt
Normal file
|
@ -0,0 +1,661 @@
|
||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
156
mods/WorldEdit/README.md
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
WorldEdit v1.0 for Minetest 0.4.8+
|
||||||
|
==================================
|
||||||
|
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).
|
||||||
|
|
||||||
|
![Screenshot](http://i.imgur.com/lwhodrv.png)
|
||||||
|
|
||||||
|
Installing
|
||||||
|
----------
|
||||||
|
|
||||||
|
If you are using Windows, consider installing this mod using [MODSTER](https://forum.minetest.net/viewtopic.php?id=6497), a super simple mod installer that will take care of everything for you. If you are using MODSTER, skip directly to step 6 in the instructions below.
|
||||||
|
|
||||||
|
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 will probably want to download the ZIP version.
|
||||||
|
2. You should have a file named `SOMETHING.zip` or `SOMETHING.tar.gz`.
|
||||||
|
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 this 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 MP** 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](http://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 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`.
|
||||||
|
|
||||||
|
Certain functions/commands such as WorldEdit GUI's "Run Lua" function (equivalent to the `//lua` and `//luatransform` chat command) 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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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) and the [Chat Commands Reference](Chat Commands.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](Chat Commands.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 or supported.
|
||||||
|
|
||||||
|
WorldEdit works quite well with other mods, and does not have any known mod conflicts.
|
||||||
|
|
||||||
|
WorldEdit GUI works with [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) and [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204), but these are not required to use the mod.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath("worldedit").."/primitives.lua")
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
Axes
|
||||||
|
----
|
||||||
|
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 chat command, it is specified as one of the following values: `x`, `y`, `z`, or `?`.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Regions
|
||||||
|
-------
|
||||||
|
Most WorldEdit commands operate on regions. Regions are a set of two positions that define a 3D cuboid. They are local to each player and chat commands affect only the region for the player giving the commands.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
To remove the entities, simply punch them. This does not reset the positions themselves.
|
||||||
|
|
||||||
|
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 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:
|
||||||
|
|
||||||
|
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 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`.
|
||||||
|
|
||||||
|
Authors
|
||||||
|
-------
|
||||||
|
WorldEdit would not be possible without the contributions of many developers and designers. Below, they are listed alphabetically:
|
||||||
|
|
||||||
|
cheapie
|
||||||
|
cornernote
|
||||||
|
cyisfor
|
||||||
|
electricface
|
||||||
|
kaeza
|
||||||
|
khonkhortisan
|
||||||
|
sfan5
|
||||||
|
ShadowNinja
|
||||||
|
spillz
|
||||||
|
Uberi/Temperest
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
Copyright 2013 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).
|
||||||
|
|
||||||
|
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.
|
120
mods/WorldEdit/Tutorial.md
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
WorldEdit Tutorial
|
||||||
|
==================
|
||||||
|
This is a step-by-step tutorial outlining the basic usage of WorldEdit. For more information, see the [README](README.md).
|
||||||
|
|
||||||
|
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 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.
|
||||||
|
* 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 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`.
|
||||||
|
|
||||||
|
### 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".
|
||||||
|
|
||||||
|
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
|
||||||
|
----------------------
|
||||||
|
### Chat 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.
|
||||||
|
|
||||||
|
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](Chat Commands.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.
|
236
mods/WorldEdit/WorldEdit API.md
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
WorldEdit API
|
||||||
|
=============
|
||||||
|
The WorldEdit API is composed of multiple modules, each of which is independent and can be used without the other. Each module is contained within a single file.
|
||||||
|
|
||||||
|
If needed, individual modules such as visualization.lua can be removed without affecting the rest of the program. The only file that cannot be removed is init.lua, which is necessary for the mod to run.
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
Sets a region defined by positions `pos1` and `pos2` to `nodename`. To clear a region, use "air" as the value of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes set.
|
||||||
|
|
||||||
|
### count = worldedit.replace(pos1, pos2, searchnode, replacenode)
|
||||||
|
|
||||||
|
Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the number of nodes replaced.
|
||||||
|
|
||||||
|
### count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
|
||||||
|
|
||||||
|
Replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the number of nodes replaced.
|
||||||
|
|
||||||
|
### count = worldedit.copy(pos1, pos2, axis, amount)
|
||||||
|
|
||||||
|
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Returns the number of nodes moved.
|
||||||
|
|
||||||
|
### count = worldedit.stack(pos1, pos2, axis, count)
|
||||||
|
|
||||||
|
Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.
|
||||||
|
|
||||||
|
Returns the number of nodes stacked.
|
||||||
|
|
||||||
|
### count = worldedit.stack2(pos1, pos2, direction, amount)
|
||||||
|
|
||||||
|
Duplicates the region defined by positions `pos1` and `pos2` `amount` times with offset vector `direction`.
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").
|
||||||
|
|
||||||
|
Returns the number of nodes transposed, the new transposed position 1, and the new transposed position 2.
|
||||||
|
|
||||||
|
### count = worldedit.flip(pos1, pos2, axis)
|
||||||
|
|
||||||
|
Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").
|
||||||
|
|
||||||
|
Returns the number of nodes flipped.
|
||||||
|
|
||||||
|
### count, newpos2, newpos2 = worldedit.rotate(pos1, pos2, angle)
|
||||||
|
|
||||||
|
Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).
|
||||||
|
|
||||||
|
Returns the number of nodes rotated, the new position 1, and the new position 2.
|
||||||
|
|
||||||
|
### count = worldedit.orient(pos1, pos2, angle)
|
||||||
|
|
||||||
|
Rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis.
|
||||||
|
|
||||||
|
Returns the number of nodes oriented.
|
||||||
|
|
||||||
|
### count = worldedit.fixlight(pos1, pos2)
|
||||||
|
|
||||||
|
Fixes the lighting in a region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the number of nodes updated.
|
||||||
|
|
||||||
|
### count = worldedit.clearobjects(pos1, pos2)
|
||||||
|
|
||||||
|
Clears all objects in a region defined by the positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the number of objects cleared.
|
||||||
|
|
||||||
|
Primitives
|
||||||
|
----------
|
||||||
|
Contained in primitives.lua, this module allows the creation of several geometric primitives.
|
||||||
|
|
||||||
|
### count = worldedit.hollow_sphere(pos, radius, nodename)
|
||||||
|
|
||||||
|
Adds a hollow sphere centered at `pos` with radius `radius`, composed of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
### count = worldedit.sphere(pos, radius, nodename)
|
||||||
|
|
||||||
|
Adds a sphere centered at `pos` with radius `radius`, composed of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
### count = worldedit.hollow_dome(pos, radius, nodename)
|
||||||
|
|
||||||
|
Adds a hollow dome centered at `pos` with radius `radius`, composed of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
### count = worldedit.dome(pos, radius, nodename)
|
||||||
|
|
||||||
|
Adds a dome centered at `pos` with radius `radius`, composed of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)
|
||||||
|
|
||||||
|
Adds a hollow 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.cylinder(pos, axis, length, radius, nodename)
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
Visualization
|
||||||
|
-------------
|
||||||
|
Contained in visualization.lua, this module allows nodes to be visualized in different ways.
|
||||||
|
|
||||||
|
### volume = worldedit.volume(pos1, pos2)
|
||||||
|
|
||||||
|
Determines the volume of the region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the volume.
|
||||||
|
|
||||||
|
### count = worldedit.hide(pos1, pos2)
|
||||||
|
|
||||||
|
Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.
|
||||||
|
|
||||||
|
Returns the number of nodes hidden.
|
||||||
|
|
||||||
|
### count = worldedit.suppress(pos1, pos2, nodename)
|
||||||
|
|
||||||
|
Suppresses all instances of `nodename` 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)
|
||||||
|
|
||||||
|
Highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.
|
||||||
|
|
||||||
|
Returns the number of nodes found.
|
||||||
|
|
||||||
|
### count = worldedit.restore(pos1, pos2)
|
||||||
|
|
||||||
|
Restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
### version = worldedit.valueversion(value)
|
||||||
|
|
||||||
|
Determines the version of serialized data `value`.
|
||||||
|
|
||||||
|
Returns the version as a positive integer or 0 for unknown versions.
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
|
### pos1, pos2, count = worldedit.allocate(originpos, value)
|
||||||
|
|
||||||
|
Determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`.
|
||||||
|
|
||||||
|
Returns the two corner positions and the number of nodes.
|
||||||
|
|
||||||
|
### count = worldedit.deserialize(originpos, value)
|
||||||
|
|
||||||
|
Loads the nodes represented by string `value` at position `originpos`.
|
||||||
|
|
||||||
|
Returns the number of nodes deserialized.
|
||||||
|
|
||||||
|
Code
|
||||||
|
----
|
||||||
|
Contained in code.lua, this module allows arbitrary Lua code to be used with WorldEdit.
|
||||||
|
|
||||||
|
### error = worldedit.lua(code)
|
||||||
|
|
||||||
|
Executes `code` as a Lua chunk in the global namespace.
|
||||||
|
|
||||||
|
Returns an error if the code fails or nil otherwise.
|
||||||
|
|
||||||
|
### error = worldedit.luatransform(pos1, pos2, code)
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
Returns an error if the code fails or nil otherwise.
|
0
mods/WorldEdit/modpack.txt
Normal file
70
mods/WorldEdit/worldedit/code.lua
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
local minetest = minetest -- local copy of global
|
||||||
|
|
||||||
|
-- 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.
|
||||||
|
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
|
||||||
|
|
||||||
|
-- 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 func, err = loadstring(code)
|
||||||
|
if not func then -- Syntax error
|
||||||
|
return err
|
||||||
|
end
|
||||||
|
local good, err = pcall(operation)
|
||||||
|
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)
|
||||||
|
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 func = factory()
|
||||||
|
|
||||||
|
-- Keep area loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
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 good, err = pcall(func, pos)
|
||||||
|
if not good then -- Runtime error
|
||||||
|
return err
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
23
mods/WorldEdit/worldedit/compatibility.lua
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
local minetest = minetest --local copy of global
|
||||||
|
|
||||||
|
worldedit.allocate_old = worldedit.allocate
|
||||||
|
worldedit.deserialize_old = worldedit.deserialize
|
||||||
|
worldedit.metasave = function(pos1, pos2, filename)
|
||||||
|
local file, err = io.open(filename, "wb")
|
||||||
|
if err then return 0 end
|
||||||
|
local data, count = worldedit.serialize(pos1, pos2)
|
||||||
|
file:write(data)
|
||||||
|
file:close()
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
worldedit.metaload = function(originpos, filename)
|
||||||
|
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
|
||||||
|
worldedit.scale = function(pos1, pos2, factor)
|
||||||
|
return worldedit.stretch(pos1, pos2, factor, factor, factor)
|
||||||
|
end
|
25
mods/WorldEdit/worldedit/init.lua
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
worldedit.version = {major=1, minor=0}
|
||||||
|
worldedit.version_string = "1.0"
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
|
local loadmodule = function(path)
|
||||||
|
local file = io.open(path)
|
||||||
|
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")
|
||||||
|
|
||||||
|
print("[MOD] WorldEdit loaded!")
|
731
mods/WorldEdit/worldedit/manipulations.lua
Normal file
|
@ -0,0 +1,731 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
local minetest = minetest --local copy of global
|
||||||
|
|
||||||
|
-- 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.
|
||||||
|
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
|
||||||
|
|
||||||
|
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
|
||||||
|
worldedit.set = function(pos1, pos2, nodenames)
|
||||||
|
if type(nodenames) == "string" then
|
||||||
|
nodenames = {nodenames}
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--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_ids = {}
|
||||||
|
for i,v in ipairs(nodenames) do
|
||||||
|
node_ids[i] = minetest.get_content_id(nodenames[i])
|
||||||
|
end
|
||||||
|
if #node_ids == 1 then --only one type of node
|
||||||
|
local id = node_ids[1]
|
||||||
|
for i in area:iterp(pos1, pos2) do nodes[i] = id end --fill area with node
|
||||||
|
else --several types of nodes specified
|
||||||
|
local id_count, rand = #node_ids, math.random
|
||||||
|
for i in area:iterp(pos1, pos2) do nodes[i] = node_ids[rand(id_count)] end --fill randomly with all types of specified nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
|
||||||
|
worldedit.replace = function(pos1, pos2, searchnode, replacenode)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--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 nodes = manip:get_data()
|
||||||
|
local searchnode_id = minetest.get_content_id(searchnode)
|
||||||
|
local replacenode_id = minetest.get_content_id(replacenode)
|
||||||
|
local count = 0
|
||||||
|
for i in area:iterp(pos1, pos2) do --replace searchnode with replacenode
|
||||||
|
if nodes[i] == searchnode_id then
|
||||||
|
nodes[i] = replacenode_id
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
|
||||||
|
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--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 nodes = manip:get_data()
|
||||||
|
local searchnode_id = minetest.get_content_id(searchnode)
|
||||||
|
local replacenode_id = minetest.get_content_id(replacenode)
|
||||||
|
local count = 0
|
||||||
|
for i in area:iterp(pos1, pos2) do --replace anything that is not searchnode with replacenode
|
||||||
|
if nodes[i] ~= searchnode_id then
|
||||||
|
nodes[i] = replacenode_id
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
||||||
|
worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old version below
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
if amount == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
--prepare slice along axis
|
||||||
|
local extent = {
|
||||||
|
[axis] = 1,
|
||||||
|
[other1]=pos2[other1] - pos1[other1] + 1,
|
||||||
|
[other2]=pos2[other2] - pos1[other2] + 1,
|
||||||
|
}
|
||||||
|
local nodes = {}
|
||||||
|
local schematic = {size=extent, data=nodes}
|
||||||
|
|
||||||
|
local currentpos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||||
|
local stride = {x=1, y=extent.x, z=extent.x * extent.y}
|
||||||
|
local get_node = minetest.get_node
|
||||||
|
for index1 = 1, extent[axis] do --go through each slice
|
||||||
|
--copy slice into schematic
|
||||||
|
local newindex1 = (index1 + offset[axis]) * stride[axis] + 1 --offset contributed by axis plus 1 to make it 1-indexed
|
||||||
|
for index2 = 1, extent[other1] do
|
||||||
|
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
||||||
|
for index3 = 1, extent[other2] do
|
||||||
|
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||||
|
local node = get_node(pos)
|
||||||
|
node.param1 = 255 --node will always appear
|
||||||
|
nodes[i] = node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--copy schematic to target
|
||||||
|
currentpos[axis] = currentpos[axis] + amount
|
||||||
|
place_schematic(currentpos, schematic)
|
||||||
|
|
||||||
|
--wip: copy meta
|
||||||
|
|
||||||
|
currentpos[axis] = currentpos[axis] + 1
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
worldedit.copy2 = function(pos1, pos2, direction, volume)
|
||||||
|
-- the overlap shouldn't matter as long as we
|
||||||
|
-- 1) start at the furthest separated corner
|
||||||
|
-- 2) complete an edge before moving inward, either edge works
|
||||||
|
-- 3) complete a face before moving inward, similarly
|
||||||
|
--
|
||||||
|
-- to do this I
|
||||||
|
-- 1) find the furthest destination in the direction, of each axis
|
||||||
|
-- 2) call those the furthest separated corner
|
||||||
|
-- 3) make sure to iterate inward from there
|
||||||
|
-- 4) nested loop to make sure complete edge, complete face, then complete cube.
|
||||||
|
|
||||||
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
|
local somemeta = get_meta(pos1) -- hax lol
|
||||||
|
local to_table = somemeta.to_table
|
||||||
|
local from_table = somemeta.from_table
|
||||||
|
somemeta = nil
|
||||||
|
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local sx, sy, sz -- direction sign
|
||||||
|
local ix, iy, iz -- initial destination
|
||||||
|
local ex, ey, ez -- final destination
|
||||||
|
local originalx, originaly, originalz -- source
|
||||||
|
-- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
|
||||||
|
if direction.x > 0 then
|
||||||
|
originalx = pos2.x
|
||||||
|
ix = originalx + direction.x
|
||||||
|
ex = pos1.x + direction.x
|
||||||
|
sx = -1
|
||||||
|
elseif direction.x < 0 then
|
||||||
|
originalx = pos1.x
|
||||||
|
ix = originalx + direction.x
|
||||||
|
ex = pos2.x + direction.x
|
||||||
|
sx = 1
|
||||||
|
else
|
||||||
|
originalx = pos1.x
|
||||||
|
ix = originalx -- whatever
|
||||||
|
ex = pos2.x
|
||||||
|
sx = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if direction.y > 0 then
|
||||||
|
originaly = pos2.y
|
||||||
|
iy = originaly + direction.y
|
||||||
|
ey = pos1.y + direction.y
|
||||||
|
sy = -1
|
||||||
|
elseif direction.y < 0 then
|
||||||
|
originaly = pos1.y
|
||||||
|
iy = originaly + direction.y
|
||||||
|
ey = pos2.y + direction.y
|
||||||
|
sy = 1
|
||||||
|
else
|
||||||
|
originaly = pos1.y
|
||||||
|
iy = originaly -- whatever
|
||||||
|
ey = pos2.y
|
||||||
|
sy = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if direction.z > 0 then
|
||||||
|
originalz = pos2.z
|
||||||
|
iz = originalz + direction.z
|
||||||
|
ez = pos1.z + direction.z
|
||||||
|
sz = -1
|
||||||
|
elseif direction.z < 0 then
|
||||||
|
originalz = pos1.z
|
||||||
|
iz = originalz + direction.z
|
||||||
|
ez = pos2.z + direction.z
|
||||||
|
sz = 1
|
||||||
|
else
|
||||||
|
originalz = pos1.z
|
||||||
|
iz = originalz -- whatever
|
||||||
|
ez = pos2.z
|
||||||
|
sz = 1
|
||||||
|
end
|
||||||
|
-- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
|
||||||
|
|
||||||
|
local ox,oy,oz
|
||||||
|
|
||||||
|
ox = originalx
|
||||||
|
for x = ix, ex, sx do
|
||||||
|
oy = originaly
|
||||||
|
for y = iy, ey, sy do
|
||||||
|
oz = originalz
|
||||||
|
for z = iz, ez, sz do
|
||||||
|
-- reusing pos1/pos2 as source/dest here
|
||||||
|
pos1.x, pos1.y, pos1.z = ox, oy, oz
|
||||||
|
pos2.x, pos2.y, pos2.z = x, y, z
|
||||||
|
local node = get_node(pos1)
|
||||||
|
local meta = to_table(get_meta(pos1)) --get meta of current node
|
||||||
|
add_node(pos2,node)
|
||||||
|
from_table(get_meta(pos2),meta)
|
||||||
|
oz = oz + sz
|
||||||
|
end
|
||||||
|
oy = oy + sy
|
||||||
|
end
|
||||||
|
ox = ox + sx
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--duplicates the region defined by positions `pos1` and `pos2` `amount` times with offset vector `direction`, returning the number of nodes stacked
|
||||||
|
worldedit.stack2 = function(pos1, pos2, direction, amount, finished)
|
||||||
|
local i = 0
|
||||||
|
local translated = {x=0,y=0,z=0}
|
||||||
|
local function nextone()
|
||||||
|
if i <= amount then
|
||||||
|
i = i + 1
|
||||||
|
translated.x = translated.x + direction.x
|
||||||
|
translated.y = translated.y + direction.y
|
||||||
|
translated.z = translated.z + direction.z
|
||||||
|
worldedit.copy2(pos1, pos2, translated, volume)
|
||||||
|
minetest.after(0, nextone)
|
||||||
|
else
|
||||||
|
if finished then
|
||||||
|
finished()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nextone()
|
||||||
|
return worldedit.volume(pos1, pos2) * amount
|
||||||
|
end
|
||||||
|
|
||||||
|
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
||||||
|
worldedit.copy = function(pos1, pos2, axis, amount)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
|
if amount < 0 then
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
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) --obtain current node
|
||||||
|
local meta = get_meta(pos):to_table() --get meta of current node
|
||||||
|
local value = pos[axis] --store current position
|
||||||
|
pos[axis] = value + amount --move along axis
|
||||||
|
add_node(pos, node) --copy node to new position
|
||||||
|
get_meta(pos):from_table(meta) --set metadata of new node
|
||||||
|
pos[axis] = value --restore old position
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local pos = {x=pos2.x, y=0, z=0}
|
||||||
|
while pos.x >= pos1.x do
|
||||||
|
pos.y = pos2.y
|
||||||
|
while pos.y >= pos1.y do
|
||||||
|
pos.z = pos2.z
|
||||||
|
while pos.z >= pos1.z do
|
||||||
|
local node = get_node(pos) --obtain current node
|
||||||
|
local meta = get_meta(pos):to_table() --get meta of current node
|
||||||
|
local value = pos[axis] --store current position
|
||||||
|
pos[axis] = value + amount --move along axis
|
||||||
|
add_node(pos, node) --copy node to new position
|
||||||
|
get_meta(pos):from_table(meta) --set metadata of new node
|
||||||
|
pos[axis] = value --restore old position
|
||||||
|
pos.z = pos.z - 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes moved
|
||||||
|
worldedit.move = function(pos1, pos2, axis, amount)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
--wip: move slice by slice using schematic method in the move axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time and erase original after, using schematic method)
|
||||||
|
local get_node, get_meta, add_node, remove_node = minetest.get_node, minetest.get_meta, minetest.add_node, minetest.remove_node
|
||||||
|
if amount < 0 then
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
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) --obtain current node
|
||||||
|
local meta = get_meta(pos):to_table() --get metadata of current node
|
||||||
|
remove_node(pos)
|
||||||
|
local value = pos[axis] --store current position
|
||||||
|
pos[axis] = value + amount --move along axis
|
||||||
|
add_node(pos, node) --move node to new position
|
||||||
|
get_meta(pos):from_table(meta) --set metadata of new node
|
||||||
|
pos[axis] = value --restore old position
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local pos = {x=pos2.x, y=0, z=0}
|
||||||
|
while pos.x >= pos1.x do
|
||||||
|
pos.y = pos2.y
|
||||||
|
while pos.y >= pos1.y do
|
||||||
|
pos.z = pos2.z
|
||||||
|
while pos.z >= pos1.z do
|
||||||
|
local node = get_node(pos) --obtain current node
|
||||||
|
local meta = get_meta(pos):to_table() --get metadata of current node
|
||||||
|
remove_node(pos)
|
||||||
|
local value = pos[axis] --store current position
|
||||||
|
pos[axis] = value + amount --move along axis
|
||||||
|
add_node(pos, node) --move node to new position
|
||||||
|
get_meta(pos):from_table(meta) --set metadata of new node
|
||||||
|
pos[axis] = value --restore old position
|
||||||
|
pos.z = pos.z - 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
|
||||||
|
worldedit.stack = function(pos1, pos2, axis, count)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
local length = pos2[axis] - pos1[axis] + 1
|
||||||
|
if count < 0 then
|
||||||
|
count = -count
|
||||||
|
length = -length
|
||||||
|
end
|
||||||
|
local amount = 0
|
||||||
|
local copy = worldedit.copy
|
||||||
|
local i = 1
|
||||||
|
function nextone()
|
||||||
|
if i <= count then
|
||||||
|
i = i + 1
|
||||||
|
amount = amount + length
|
||||||
|
copy(pos1, pos2, axis, amount)
|
||||||
|
minetest.after(0, nextone)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nextone()
|
||||||
|
return worldedit.volume(pos1, pos2) * count
|
||||||
|
end
|
||||||
|
|
||||||
|
--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, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2
|
||||||
|
worldedit.stretch = function(pos1, pos2, stretchx, stretchy, stretchz) --wip: test this
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--prepare schematic of large node
|
||||||
|
local get_node, get_meta, place_schematic = minetest.get_node, minetest.get_meta, minetest.place_schematic
|
||||||
|
local placeholder_node = {name="", param1=255, param2=0}
|
||||||
|
local nodes = {}
|
||||||
|
for i = 1, stretchx * stretchy * stretchz do
|
||||||
|
nodes[i] = placeholder_node
|
||||||
|
end
|
||||||
|
local schematic = {size={x=stretchx, y=stretchy, z=stretchz}, data=nodes}
|
||||||
|
|
||||||
|
local sizex, sizey, sizez = stretchx - 1, stretchy - 1, stretchz - 1
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
local new_pos2 = {
|
||||||
|
x=pos1.x + (pos2.x - pos1.x) * stretchx + sizex,
|
||||||
|
y=pos1.y + (pos2.y - pos1.y) * stretchy + sizey,
|
||||||
|
z=pos1.z + (pos2.z - pos1.z) * stretchz + sizez,
|
||||||
|
}
|
||||||
|
manip:read_from_map(pos1, new_pos2)
|
||||||
|
|
||||||
|
local pos = {x=pos2.x, y=0, z=0}
|
||||||
|
local bigpos = {x=0, y=0, z=0}
|
||||||
|
while pos.x >= pos1.x do
|
||||||
|
pos.y = pos2.y
|
||||||
|
while pos.y >= pos1.y do
|
||||||
|
pos.z = pos2.z
|
||||||
|
while pos.z >= pos1.z do
|
||||||
|
local node = get_node(pos) --obtain current node
|
||||||
|
local meta = get_meta(pos):to_table() --get meta of current node
|
||||||
|
|
||||||
|
--calculate far corner of the big node
|
||||||
|
local posx = pos1.x + (pos.x - pos1.x) * stretchx
|
||||||
|
local posy = pos1.y + (pos.y - pos1.y) * stretchy
|
||||||
|
local posz = pos1.z + (pos.z - pos1.z) * stretchz
|
||||||
|
|
||||||
|
--create large node
|
||||||
|
placeholder_node.name = node.name
|
||||||
|
placeholder_node.param2 = node.param2
|
||||||
|
bigpos.x, bigpos.y, bigpos.z = posx, posy, posz
|
||||||
|
place_schematic(bigpos, schematic)
|
||||||
|
|
||||||
|
--fill in large node meta
|
||||||
|
if next(meta.fields) ~= nil or next(meta.inventory) ~= nil then --node has meta fields
|
||||||
|
for x = 0, sizex do
|
||||||
|
for y = 0, sizey do
|
||||||
|
for z = 0, sizez do
|
||||||
|
bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z
|
||||||
|
get_meta(bigpos):from_table(meta) --set metadata of new node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pos.z = pos.z - 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x - 1
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2) * stretchx * stretchy * stretchz, pos1, new_pos2
|
||||||
|
end
|
||||||
|
|
||||||
|
--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed position 2
|
||||||
|
worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
local compare
|
||||||
|
local extent1, extent2 = pos2[axis1] - pos1[axis1], pos2[axis2] - pos1[axis2]
|
||||||
|
|
||||||
|
if extent1 > extent2 then
|
||||||
|
compare = function(extent1, extent2)
|
||||||
|
return extent1 > extent2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
compare = function(extent1, extent2)
|
||||||
|
return extent1 < extent2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--calculate the new position 2 after transposition
|
||||||
|
local new_pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||||
|
new_pos2[axis1] = pos1[axis1] + extent2
|
||||||
|
new_pos2[axis2] = pos1[axis2] + extent1
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
local upperbound = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||||
|
if upperbound[axis1] < new_pos2[axis1] then upperbound[axis1] = new_pos2[axis1] end
|
||||||
|
if upperbound[axis2] < new_pos2[axis2] then upperbound[axis2] = new_pos2[axis2] end
|
||||||
|
manip:read_from_map(pos1, upperbound)
|
||||||
|
|
||||||
|
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
|
||||||
|
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 extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]
|
||||||
|
if compare(extent1, extent2) then --transpose only if below the diagonal
|
||||||
|
local node1 = get_node(pos)
|
||||||
|
local meta1 = get_meta(pos):to_table()
|
||||||
|
local value1, value2 = pos[axis1], pos[axis2] --save position values
|
||||||
|
pos[axis1], pos[axis2] = pos1[axis1] + extent2, pos1[axis2] + extent1 --swap axis extents
|
||||||
|
local node2 = get_node(pos)
|
||||||
|
local meta2 = get_meta(pos):to_table()
|
||||||
|
add_node(pos, node1)
|
||||||
|
get_meta(pos):from_table(meta1)
|
||||||
|
pos[axis1], pos[axis2] = value1, value2 --restore position values
|
||||||
|
add_node(pos, node2)
|
||||||
|
get_meta(pos):from_table(meta2)
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2), pos1, new_pos2
|
||||||
|
end
|
||||||
|
|
||||||
|
--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
|
||||||
|
worldedit.flip = function(pos1, pos2, axis)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
--wip: flip the region slice by slice along the flip axis using schematic method
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
local start = pos1[axis] + pos2[axis]
|
||||||
|
pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)
|
||||||
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_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 node1 = get_node(pos)
|
||||||
|
local meta1 = get_meta(pos):to_table()
|
||||||
|
local value = pos[axis]
|
||||||
|
pos[axis] = start - value
|
||||||
|
local node2 = get_node(pos)
|
||||||
|
local meta2 = get_meta(pos):to_table()
|
||||||
|
add_node(pos, node1)
|
||||||
|
get_meta(pos):from_table(meta1)
|
||||||
|
pos[axis] = value
|
||||||
|
add_node(pos, node2)
|
||||||
|
get_meta(pos):from_table(meta2)
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
|
||||||
|
worldedit.rotate = function(pos1, pos2, axis, angle)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
local axis1, axis2
|
||||||
|
if axis == "x" then
|
||||||
|
axis1, axis2 = "z", "y"
|
||||||
|
elseif axis == "y" then
|
||||||
|
axis1, axis2 = "x", "z"
|
||||||
|
else --axis == "z"
|
||||||
|
axis1, axis2 = "y", "x"
|
||||||
|
end
|
||||||
|
angle = angle % 360
|
||||||
|
|
||||||
|
local count
|
||||||
|
if angle == 90 then
|
||||||
|
worldedit.flip(pos1, pos2, axis1)
|
||||||
|
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
|
||||||
|
elseif angle == 180 then
|
||||||
|
worldedit.flip(pos1, pos2, axis1)
|
||||||
|
count = worldedit.flip(pos1, pos2, axis2)
|
||||||
|
elseif angle == 270 then
|
||||||
|
worldedit.flip(pos1, pos2, axis2)
|
||||||
|
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
|
||||||
|
end
|
||||||
|
return count, pos1, pos2
|
||||||
|
end
|
||||||
|
|
||||||
|
--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented
|
||||||
|
worldedit.orient = function(pos1, pos2, angle) --wip: support 6D facedir rotation along arbitrary axis
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
local registered_nodes = minetest.registered_nodes
|
||||||
|
|
||||||
|
local wallmounted = {
|
||||||
|
[90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},
|
||||||
|
[180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},
|
||||||
|
[270]={[0]=0, [1]=1, [2]=4, [3]=5, [4]=3, [5]=2}
|
||||||
|
}
|
||||||
|
local facedir = {
|
||||||
|
[90]={[0]=1, [1]=2, [2]=3, [3]=0},
|
||||||
|
[180]={[0]=2, [1]=3, [2]=0, [3]=1},
|
||||||
|
[270]={[0]=3, [1]=0, [2]=1, [3]=2}
|
||||||
|
}
|
||||||
|
|
||||||
|
angle = angle % 360
|
||||||
|
if angle == 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
local wallmounted_substitution = wallmounted[angle]
|
||||||
|
local facedir_substitution = facedir[angle]
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
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)
|
||||||
|
local def = registered_nodes[node.name]
|
||||||
|
if def then
|
||||||
|
if def.paramtype2 == "wallmounted" then
|
||||||
|
node.param2 = wallmounted_substitution[node.param2]
|
||||||
|
local meta = get_meta(pos):to_table()
|
||||||
|
add_node(pos, node)
|
||||||
|
get_meta(pos):from_table(meta)
|
||||||
|
count = count + 1
|
||||||
|
elseif def.paramtype2 == "facedir" then
|
||||||
|
node.param2 = facedir_substitution[node.param2]
|
||||||
|
local meta = get_meta(pos):to_table()
|
||||||
|
add_node(pos, node)
|
||||||
|
get_meta(pos):from_table(meta)
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
|
||||||
|
worldedit.fixlight = function(pos1, pos2)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, "air")
|
||||||
|
local dig_node = minetest.dig_node
|
||||||
|
for _, pos in ipairs(nodes) do
|
||||||
|
dig_node(pos)
|
||||||
|
end
|
||||||
|
return #nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
--clears all objects in a region defined by the positions `pos1` and `pos2`, returning the number of objects cleared
|
||||||
|
worldedit.clearobjects = function(pos1, pos2)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
local pos1x, pos1y, pos1z = pos1.x, pos1.y, pos1.z
|
||||||
|
local pos2x, pos2y, pos2z = pos2.x + 1, pos2.y + 1, pos2.z + 1
|
||||||
|
local center = {x=(pos1x + pos2x) / 2, y=(pos1y + pos2y) / 2, z=(pos1z + pos2z) / 2} --center of region
|
||||||
|
local radius = ((center.x - pos1x + 0.5) + (center.y - pos1y + 0.5) + (center.z - pos1z + 0.5)) ^ 0.5 --bounding sphere radius
|
||||||
|
local count = 0
|
||||||
|
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do --all objects in bounding sphere
|
||||||
|
local entity = obj:get_luaentity()
|
||||||
|
if not (entity and entity.name:find("^worldedit:")) then --avoid WorldEdit entities
|
||||||
|
local pos = obj:getpos()
|
||||||
|
if pos.x >= pos1x and pos.x <= pos2x
|
||||||
|
and pos.y >= pos1y and pos.y <= pos2y
|
||||||
|
and pos.z >= pos1z and pos.z <= pos2z then --inside region
|
||||||
|
obj:remove()
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
470
mods/WorldEdit/worldedit/primitives.lua
Normal file
|
@ -0,0 +1,470 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
local minetest = minetest --local copy of global
|
||||||
|
|
||||||
|
--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})
|
||||||
|
|
||||||
|
--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
|
||||||
|
|
||||||
|
--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)
|
||||||
|
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 min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||||
|
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 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]
|
||||||
|
local squared = index2 * index2 + index3 * index3
|
||||||
|
if squared >= min_radius and squared <= max_radius then --position is on surface of cylinder
|
||||||
|
for index1 = min_slice, max_slice do --add column along axis
|
||||||
|
local i = newindex3 + index1 * stride[axis]
|
||||||
|
nodes[i] = node_id
|
||||||
|
end
|
||||||
|
count = count + length
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
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)
|
||||||
|
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 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 --position is within cylinder
|
||||||
|
for index1 = min_slice, max_slice do --add column along axis
|
||||||
|
local i = newindex3 + index1 * stride[axis]
|
||||||
|
nodes[i] = node_id
|
||||||
|
end
|
||||||
|
count = count + length
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
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"
|
||||||
|
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}
|
||||||
|
|
||||||
|
--handle inverted pyramids
|
||||||
|
local startaxis, endaxis, 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)
|
||||||
|
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 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 index2 = -size, size do
|
||||||
|
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
||||||
|
for index3 = -size, size do
|
||||||
|
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||||
|
nodes[i] = node_id
|
||||||
|
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()
|
||||||
|
|
||||||
|
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)
|
||||||
|
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})
|
||||||
|
|
||||||
|
--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
|
||||||
|
|
||||||
|
--set up variables
|
||||||
|
local node_id = minetest.get_content_id(nodename)
|
||||||
|
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
|
||||||
|
|
||||||
|
--add first column
|
||||||
|
local count = height
|
||||||
|
local column = i
|
||||||
|
for y = 1, height do
|
||||||
|
nodes[column] = node_id
|
||||||
|
column = column + stride.y
|
||||||
|
end
|
||||||
|
|
||||||
|
--add spiral segments
|
||||||
|
local strideaxis, strideother = stride.x, stride.z
|
||||||
|
local sign = -1
|
||||||
|
local segment_length = 0
|
||||||
|
spacer = spacer + 1
|
||||||
|
for segment = 1, math.floor(length / spacer) * 2 do --go through each segment except the last
|
||||||
|
if segment % 2 == 1 then --change sign and length every other turn starting with the first
|
||||||
|
sign = -sign
|
||||||
|
segment_length = segment_length + spacer
|
||||||
|
end
|
||||||
|
for index = 1, segment_length do --fill segment
|
||||||
|
i = i + strideaxis * sign --move along the direction of the segment
|
||||||
|
local column = i
|
||||||
|
for y = 1, height do --add column
|
||||||
|
nodes[column] = node_id
|
||||||
|
column = column + stride.y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
count = count + segment_length * height
|
||||||
|
strideaxis, strideother = strideother, strideaxis --swap axes
|
||||||
|
end
|
||||||
|
|
||||||
|
--add shorter final segment
|
||||||
|
sign = -sign
|
||||||
|
for index = 1, segment_length do
|
||||||
|
i = i + strideaxis * sign
|
||||||
|
local column = i
|
||||||
|
for y = 1, height do --add column
|
||||||
|
nodes[column] = node_id
|
||||||
|
column = column + stride.y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
count = count + segment_length * height
|
||||||
|
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
|
return count
|
||||||
|
end
|
273
mods/WorldEdit/worldedit/serialization.lua
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
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 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
|
||||||
|
elseif value:find("^[^\"']+%{%d+%}") then
|
||||||
|
if value:find("%[\"meta\"%]") then --previous meta flat table format
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
return 1 --original flat table format
|
||||||
|
elseif value:find("%{") then --current nested table format
|
||||||
|
return 4
|
||||||
|
end
|
||||||
|
return 0 --unknown format
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
pos.z = pos1.z
|
||||||
|
while pos.z <= pos2.z do
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result[count] = {
|
||||||
|
x = pos.x - pos1.x,
|
||||||
|
y = pos.y - pos1.y,
|
||||||
|
z = pos.z - pos1.z,
|
||||||
|
name = node.name,
|
||||||
|
param1 = node.param1,
|
||||||
|
param2 = node.param2,
|
||||||
|
meta = meta,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
result = minetest.serialize(result) --convert entries to a string
|
||||||
|
return 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)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
|
||||||
|
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
|
||||||
|
return pos1, pos2, count
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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]
|
||||||
|
get_meta(entry):from_table(entry.meta)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
142
mods/WorldEdit/worldedit/visualization.lua
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
minetest.register_node("worldedit:placeholder", {
|
||||||
|
drawtype = "airlike",
|
||||||
|
paramtype = "light",
|
||||||
|
sunlight_propagates = true,
|
||||||
|
diggable = 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)
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
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
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(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
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
|
||||||
|
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 count = 0
|
||||||
|
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 == nodename 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
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
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)
|
||||||
|
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(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
|
||||||
|
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
|
||||||
|
end
|
||||||
|
return #nodes
|
||||||
|
end
|
1
mods/WorldEdit/worldedit_commands/depends.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
worldedit
|
1143
mods/WorldEdit/worldedit_commands/init.lua
Normal file
161
mods/WorldEdit/worldedit_commands/mark.lua
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
worldedit.marker1 = {}
|
||||||
|
worldedit.marker2 = {}
|
||||||
|
worldedit.marker_region = {}
|
||||||
|
|
||||||
|
--marks worldedit region position 1
|
||||||
|
worldedit.mark_pos1 = function(name)
|
||||||
|
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
|
||||||
|
--add marker
|
||||||
|
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
|
||||||
|
if worldedit.marker1[name] ~= nil then
|
||||||
|
worldedit.marker1[name]:get_luaentity().name = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
worldedit.mark_region(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
--marks worldedit region position 2
|
||||||
|
worldedit.mark_pos2 = function(name)
|
||||||
|
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
|
||||||
|
--add marker
|
||||||
|
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
|
||||||
|
if worldedit.marker2[name] ~= nil then
|
||||||
|
worldedit.marker2[name]:get_luaentity().name = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
worldedit.mark_region(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
worldedit.mark_region = function(name)
|
||||||
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
|
|
||||||
|
if worldedit.marker_region[name] ~= nil then --marker already exists
|
||||||
|
--wip: make the area stay loaded somehow
|
||||||
|
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
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
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 marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")
|
||||||
|
marker:set_properties({
|
||||||
|
visual_size={x=sizex * 2, y=sizey * 2},
|
||||||
|
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
|
||||||
|
})
|
||||||
|
marker:get_luaentity().name = name
|
||||||
|
table.insert(markers, marker)
|
||||||
|
end
|
||||||
|
|
||||||
|
--YZ plane markers
|
||||||
|
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
|
||||||
|
local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")
|
||||||
|
marker:set_properties({
|
||||||
|
visual_size={x=sizez * 2, y=sizey * 2},
|
||||||
|
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
|
||||||
|
})
|
||||||
|
marker:setyaw(math.pi / 2)
|
||||||
|
marker:get_luaentity().name = name
|
||||||
|
table.insert(markers, marker)
|
||||||
|
end
|
||||||
|
|
||||||
|
worldedit.marker_region[name] = markers
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_entity(":worldedit:pos1", {
|
||||||
|
initial_properties = {
|
||||||
|
visual = "cube",
|
||||||
|
visual_size = {x=1.1, y=1.1},
|
||||||
|
textures = {"worldedit_pos1.png", "worldedit_pos1.png",
|
||||||
|
"worldedit_pos1.png", "worldedit_pos1.png",
|
||||||
|
"worldedit_pos1.png", "worldedit_pos1.png"},
|
||||||
|
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||||
|
physical = false,
|
||||||
|
},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if worldedit.marker1[self.name] == nil then
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_punch = function(self, hitter)
|
||||||
|
self.object:remove()
|
||||||
|
worldedit.marker1[self.name] = nil
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity(":worldedit:pos2", {
|
||||||
|
initial_properties = {
|
||||||
|
visual = "cube",
|
||||||
|
visual_size = {x=1.1, y=1.1},
|
||||||
|
textures = {"worldedit_pos2.png", "worldedit_pos2.png",
|
||||||
|
"worldedit_pos2.png", "worldedit_pos2.png",
|
||||||
|
"worldedit_pos2.png", "worldedit_pos2.png"},
|
||||||
|
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||||
|
physical = false,
|
||||||
|
},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if worldedit.marker2[self.name] == nil then
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_punch = function(self, hitter)
|
||||||
|
self.object:remove()
|
||||||
|
worldedit.marker2[self.name] = nil
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity(":worldedit:region_cube", {
|
||||||
|
initial_properties = {
|
||||||
|
visual = "upright_sprite",
|
||||||
|
visual_size = {x=1.1, y=1.1},
|
||||||
|
textures = {"worldedit_cube.png"},
|
||||||
|
visual_size = {x=10, y=10},
|
||||||
|
physical = false,
|
||||||
|
},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if worldedit.marker_region[self.name] == nil then
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_punch = function(self, hitter)
|
||||||
|
for _, entity in ipairs(worldedit.marker_region[self.name]) do
|
||||||
|
entity:remove()
|
||||||
|
end
|
||||||
|
worldedit.marker_region[self.name] = nil
|
||||||
|
end,
|
||||||
|
})
|
65
mods/WorldEdit/worldedit_commands/safe.lua
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
local safe_region_callback = {}
|
||||||
|
local safe_region_param = {}
|
||||||
|
|
||||||
|
check_region = function(name, param)
|
||||||
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
|
||||||
|
if pos1 == nil or pos2 == nil then
|
||||||
|
worldedit.player_notify(name, "no region selected")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--`callback` is a callback to run when the user confirms
|
||||||
|
--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
|
||||||
|
safe_region = function(callback, nodes_needed)
|
||||||
|
--default node volume calculation
|
||||||
|
nodes_needed = nodes_needed or check_region
|
||||||
|
|
||||||
|
return function(name, param)
|
||||||
|
--check if the operation applies to a safe number of nodes
|
||||||
|
local count = nodes_needed(name, param)
|
||||||
|
if count == nil then return end --invalid command
|
||||||
|
if count < 10000 then
|
||||||
|
return callback(name, param)
|
||||||
|
end
|
||||||
|
|
||||||
|
--save callback to call later
|
||||||
|
safe_region_callback[name], safe_region_param[name] = callback, param
|
||||||
|
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/y", {
|
||||||
|
params = "",
|
||||||
|
description = "Confirm a pending operation",
|
||||||
|
func = function(name)
|
||||||
|
local callback, param = safe_region_callback[name], safe_region_param[name]
|
||||||
|
if not callback then
|
||||||
|
worldedit.player_notify(name, "no operation pending")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
--obtain positions
|
||||||
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
|
if pos1 == nil or pos2 == nil then
|
||||||
|
worldedit.player_notify(name, "no region selected")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
|
||||||
|
callback(name, param, pos1, pos2)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/n", {
|
||||||
|
params = "",
|
||||||
|
description = "Confirm a pending operation",
|
||||||
|
func = function(name)
|
||||||
|
if not safe_region_callback[name] then
|
||||||
|
worldedit.player_notify(name, "no operation pending")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
safe_region_callback[name], safe_region_param[name] = nil, nil
|
||||||
|
end,
|
||||||
|
})
|
BIN
mods/WorldEdit/worldedit_commands/textures/worldedit_cube.png
Normal file
After Width: | Height: | Size: 147 B |
BIN
mods/WorldEdit/worldedit_commands/textures/worldedit_pos1.png
Normal file
After Width: | Height: | Size: 142 B |
BIN
mods/WorldEdit/worldedit_commands/textures/worldedit_pos2.png
Normal file
After Width: | Height: | Size: 157 B |
103
mods/WorldEdit/worldedit_infinity/init.lua
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
worldedit = worldedit or {}
|
||||||
|
local minetest = minetest --local copy of global
|
||||||
|
|
||||||
|
local get_pointed = function(pos, nearest, distance)
|
||||||
|
if distance > 100 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--check for collision with node
|
||||||
|
local nodename = minetest.get_node(pos).name
|
||||||
|
if nodename ~= "air"
|
||||||
|
and nodename ~= "default:water_source"
|
||||||
|
and nodename ~= "default:water_flowing" then
|
||||||
|
if nodename ~= "ignore" then
|
||||||
|
return nearest
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local use = function(itemstack, user, pointed_thing)
|
||||||
|
if pointed_thing.type == "nothing" then --pointing at nothing
|
||||||
|
local placepos = worldedit.raytrace(user:getpos(), user:get_look_dir(), get_pointed)
|
||||||
|
if placepos then --extended reach
|
||||||
|
pointed_thing.type = "node"
|
||||||
|
pointed_thing.under = nil --wip
|
||||||
|
pointed_thing.above = nil --wip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return minetest.item_place_node(itemstack, user, pointed_thing)
|
||||||
|
end
|
||||||
|
--
|
||||||
|
|
||||||
|
worldedit.raytrace = function(pos, dir, callback)
|
||||||
|
local base = {x=math.floor(pos.x), y=math.floor(pos.y), z=math.floor(pos.z)}
|
||||||
|
local stepx, stepy, stepz = 0, 0, 0
|
||||||
|
local componentx, componenty, componentz = 0, 0, 0
|
||||||
|
local intersectx, intersecty, intersectz = 0, 0, 0
|
||||||
|
|
||||||
|
if dir.x == 0 then
|
||||||
|
intersectx = math.huge
|
||||||
|
elseif dir.x > 0 then
|
||||||
|
stepx = 1
|
||||||
|
componentx = 1 / dir.x
|
||||||
|
intersectx = ((base.x - pos.x) + 1) * componentx
|
||||||
|
else
|
||||||
|
stepx = -1
|
||||||
|
componentx = 1 / -dir.x
|
||||||
|
intersectx = (pos.x - base.x) * componentx
|
||||||
|
end
|
||||||
|
if dir.y == 0 then
|
||||||
|
intersecty = math.huge
|
||||||
|
elseif dir.y > 0 then
|
||||||
|
stepy = 1
|
||||||
|
componenty = 1 / dir.y
|
||||||
|
intersecty = ((base.y - pos.y) + 1) * componenty
|
||||||
|
else
|
||||||
|
stepy = -1
|
||||||
|
componenty = 1 / -dir.y
|
||||||
|
intersecty = (pos.y - base.y) * componenty
|
||||||
|
end
|
||||||
|
if dir.z == 0 then
|
||||||
|
intersectz = math.huge
|
||||||
|
elseif dir.z > 0 then
|
||||||
|
stepz = 1
|
||||||
|
componentz = 1 / dir.z
|
||||||
|
intersectz = ((base.z - pos.z) + 1) * componentz
|
||||||
|
else
|
||||||
|
stepz = -1
|
||||||
|
componentz = 1 / -dir.z
|
||||||
|
intersectz = (pos.z - base.z) * componentz
|
||||||
|
end
|
||||||
|
|
||||||
|
local distance = 0
|
||||||
|
local nearest = {x=base.x, y=base.y, z=base.z}
|
||||||
|
while true do
|
||||||
|
local values = {callback(base, nearest, distance)}
|
||||||
|
if #values > 0 then
|
||||||
|
return unpack(values)
|
||||||
|
end
|
||||||
|
|
||||||
|
nearest.x, nearest.y, nearest.z = base.x, base.y, base.z
|
||||||
|
if intersectx < intersecty then
|
||||||
|
if intersectx < intersectz then
|
||||||
|
base.x = base.x + stepx
|
||||||
|
distance = intersectx
|
||||||
|
intersectx = intersectx + componentx
|
||||||
|
else
|
||||||
|
base.z = base.z + stepz
|
||||||
|
distance = intersectz
|
||||||
|
intersectz = intersectz + componentz
|
||||||
|
end
|
||||||
|
elseif intersecty < intersectz then
|
||||||
|
base.y = base.y + stepy
|
||||||
|
distance = intersecty
|
||||||
|
intersecty = intersecty + componenty
|
||||||
|
else
|
||||||
|
base.z = base.z + stepz
|
||||||
|
distance = intersectz
|
||||||
|
intersectz = intersectz + componentz
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
1
mods/WorldEdit/worldedit_limited/depends.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
worldedit
|