Add variant changer tool (WIP)
This commit is contained in:
parent
f4030fe5dd
commit
d99372584b
@ -2,6 +2,8 @@ local S = minetest.get_translator("lzr_tools")
|
||||
|
||||
local instadig = { times = { [1] = 0, [2] = 0, [3] = 0}, uses=0, maxlevel=255}
|
||||
|
||||
lzr_tools = {}
|
||||
|
||||
-- Cheat tools and weapons
|
||||
|
||||
|
||||
@ -163,3 +165,176 @@ if minetest.settings:get_bool("lzr_debug", false) then
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
local variant_cycles = {
|
||||
next_nodes = {},
|
||||
prev_nodes = {},
|
||||
}
|
||||
lzr_tools.register_variant_cycle = function(cycle)
|
||||
for c=1, #cycle do
|
||||
local cn = c + 1
|
||||
if cn > #cycle then
|
||||
cn = 1
|
||||
end
|
||||
local cp = c - 1
|
||||
if cp < 1 then
|
||||
cp = #cycle
|
||||
end
|
||||
local node_self = cycle[c]
|
||||
local node_next = cycle[cn]
|
||||
local node_prev = cycle[cp]
|
||||
|
||||
if variant_cycles.next_nodes[node_self] or variant_cycles.prev_nodes[node_self] then
|
||||
minetest.log("warning", "[lzr_tools] register_variant_cycle: Node '"..node_self.."' already was part of a variant cycle. Overwriting ...")
|
||||
end
|
||||
variant_cycles.next_nodes[node_self] = node_next
|
||||
variant_cycles.prev_nodes[node_self] = node_prev
|
||||
end
|
||||
end
|
||||
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:stone",
|
||||
"lzr_core:stone_cracked",
|
||||
"lzr_core:stone_block",
|
||||
"lzr_core:stone_block_mossy",
|
||||
"lzr_core:stone_brick_circular",
|
||||
"lzr_core:stone_brick_circular_mossy",
|
||||
"lzr_core:stone_brick",
|
||||
"lzr_core:stone_brick_mossy",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:ocean_stone",
|
||||
"lzr_decor:ocean_stone_cracked",
|
||||
"lzr_decor:ocean_stone_block",
|
||||
"lzr_decor:ocean_carved",
|
||||
"lzr_decor:ocean_cobble",
|
||||
"lzr_decor:ocean_bricks",
|
||||
"lzr_decor:ocean_circular",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:island_stone",
|
||||
"lzr_core:island_stone_cracked",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:cave_stone",
|
||||
"lzr_core:cave_stone_cracked",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:sand",
|
||||
"lzr_core:seabed",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:dirt",
|
||||
"lzr_core:dirt_with_grass",
|
||||
"lzr_core:dirt_with_jungle_litter",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:tree",
|
||||
"lzr_core:palm_tree",
|
||||
"lzr_core:coconut_tree",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:wood",
|
||||
"lzr_core:wood_mossy",
|
||||
"lzr_core:palm_wood",
|
||||
"lzr_core:coconut_wood",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:blanket_table",
|
||||
"lzr_decor:working_table",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_core:sandstone",
|
||||
"lzr_core:sandstone_block",
|
||||
"lzr_core:sandstone_brick",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:cauldron",
|
||||
"lzr_decor:cauldron_water",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:forge",
|
||||
"lzr_decor:forge_lit",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:cabinet",
|
||||
"lzr_decor:cabinet_half",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:potted_dandelion_white",
|
||||
"lzr_decor:potted_dandelion_yellow",
|
||||
"lzr_decor:potted_tulip",
|
||||
"lzr_decor:potted_rose",
|
||||
"lzr_decor:potted_geranium",
|
||||
"lzr_decor:potted_viola",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:empty_shelf",
|
||||
"lzr_decor:bookshelf",
|
||||
"lzr_decor:vessels_shelf",
|
||||
"lzr_decor:multishelf",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_decor:thatch",
|
||||
"lzr_decor:thatch_wet",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_laser:crate",
|
||||
"lzr_laser:crate_mossy",
|
||||
})
|
||||
lzr_tools.register_variant_cycle({
|
||||
"lzr_plants:island_grass",
|
||||
"lzr_plants:crab_grass",
|
||||
})
|
||||
|
||||
|
||||
minetest.register_tool("lzr_tools:variant_changer", {
|
||||
description = S("Block Variant Changer"),
|
||||
_tt_help = S("Changes a block to different variant"),
|
||||
inventory_image = "lzr_tools_variant_changer.png",
|
||||
groups = { editor_tool = 1 },
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
if lzr_gamestate.get_state() ~= lzr_gamestate.EDITOR then
|
||||
minetest.chat_send_player(user:get_player_name(), S("This tool only works in the level editor."))
|
||||
return itemstack
|
||||
end
|
||||
local pos = pointed_thing.under
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, user:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
local next_node = variant_cycles.next_nodes[node.name]
|
||||
if next_node then
|
||||
node.name = next_node
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
if lzr_gamestate.get_state() ~= lzr_gamestate.EDITOR then
|
||||
minetest.chat_send_player(user:get_player_name(), S("This tool only works in the level editor."))
|
||||
return itemstack
|
||||
end
|
||||
local pos = pointed_thing.under
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, user:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
local prev_node = variant_cycles.prev_nodes[node.name]
|
||||
if prev_node then
|
||||
node.name = prev_node
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
BIN
mods/lzr_tools/textures/lzr_tools_variant_changer.png
Normal file
BIN
mods/lzr_tools/textures/lzr_tools_variant_changer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 462 B |
Loading…
x
Reference in New Issue
Block a user