1
0
Fork 0

Flower pot fixes

- More accurate selection and collision box
-  Remove check for `minetest.features.use_texture_alpha_string_modes`
- Use new vectors
- Add some basic type annotations to API functions
This commit is contained in:
AFCMS 2022-10-08 11:20:35 +02:00
parent 3aaf0f3e29
commit 5719637ee7
Signed by untrusted user: AFCMS
GPG Key ID: 8720389A25B652E3
1 changed files with 46 additions and 53 deletions

View File

@ -2,8 +2,18 @@ local S = minetest.get_translator(minetest.get_current_modname())
local has_doc = minetest.get_modpath("doc") local has_doc = minetest.get_modpath("doc")
mcl_flowerpots = {} mcl_flowerpots = {}
---@type table<string, string>
mcl_flowerpots.registered_pots = {} mcl_flowerpots.registered_pots = {}
---@type nodebox
local pot_box = {
type = "fixed",
fixed = {
{ -0.1875, -0.5, -0.1875, 0.1875, -0.125, 0.1875 },
},
}
minetest.register_node("mcl_flowerpots:flower_pot", { minetest.register_node("mcl_flowerpots:flower_pot", {
description = S("Flower Pot"), description = S("Flower Pot"),
_tt_help = S("Can hold a small flower or plant"), _tt_help = S("Can hold a small flower or plant"),
@ -14,23 +24,16 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
tiles = { tiles = {
"mcl_flowerpots_flowerpot.png", "mcl_flowerpots_flowerpot.png",
}, },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, use_texture_alpha = "clip",
visual_scale = 0.5, visual_scale = 0.5,
wield_image = "mcl_flowerpots_flowerpot_inventory.png", wield_image = "mcl_flowerpots_flowerpot_inventory.png",
wield_scale = {x=1.0, y=1.0, z=1.0},
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
selection_box = { selection_box = pot_box,
type = "fixed", collision_box = pot_box,
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
is_ground_content = false, is_ground_content = false,
inventory_image = "mcl_flowerpots_flowerpot_inventory.png", inventory_image = "mcl_flowerpots_flowerpot_inventory.png",
groups = {dig_immediate=3, deco_block=1, attached_node=1, dig_by_piston=1, flower_pot=1}, groups = { dig_immediate = 3, deco_block = 1, attached_node = 1, dig_by_piston = 1, flower_pot = 1 },
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = mcl_sounds.node_sound_stone_defaults(),
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
local name = clicker:get_player_name() local name = clicker:get_player_name()
@ -40,7 +43,7 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
end end
local item = clicker:get_wielded_item():get_name() local item = clicker:get_wielded_item():get_name()
if mcl_flowerpots.registered_pots[item] then if mcl_flowerpots.registered_pots[item] then
minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..mcl_flowerpots.registered_pots[item]}) minetest.swap_node(pos, { name = "mcl_flowerpots:flower_pot_" .. mcl_flowerpots.registered_pots[item] })
if not minetest.is_creative_enabled(clicker:get_player_name()) then if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item() itemstack:take_item()
end end
@ -51,37 +54,32 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
minetest.register_craft({ minetest.register_craft({
output = "mcl_flowerpots:flower_pot", output = "mcl_flowerpots:flower_pot",
recipe = { recipe = {
{"mcl_core:brick", "", "mcl_core:brick"}, { "mcl_core:brick", "", "mcl_core:brick" },
{"", "mcl_core:brick", ""}, { "", "mcl_core:brick", "" },
{"", "", ""}, { "", "", "" },
} },
}) })
---@param name string
---@param def {name: string, desc: string, image: string}
function mcl_flowerpots.register_potted_flower(name, def) function mcl_flowerpots.register_potted_flower(name, def)
mcl_flowerpots.registered_pots[name] = def.name mcl_flowerpots.registered_pots[name] = def.name
minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, { minetest.register_node(":mcl_flowerpots:flower_pot_" .. def.name, {
description = def.desc.." "..S("Flower Pot"), description = def.desc .. " " .. S("Flower Pot"),
_doc_items_create_entry = false, _doc_items_create_entry = false,
drawtype = "mesh", drawtype = "mesh",
mesh = "flowerpot.obj", mesh = "flowerpot.obj",
tiles = { tiles = {
"[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..def.image, "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0=" .. def.image,
}, },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, use_texture_alpha = "clip",
visual_scale = 0.5, visual_scale = 0.5,
wield_scale = {x=1.0, y=1.0, z=1.0},
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
selection_box = { selection_box = pot_box,
type = "fixed", collision_box = pot_box,
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
is_ground_content = false, is_ground_content = false,
groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, groups = { dig_immediate = 3, attached_node = 1, dig_by_piston = 1, not_in_creative_inventory = 1, flower_pot = 2 },
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = mcl_sounds.node_sound_stone_defaults(),
on_rightclick = function(pos, item, clicker) on_rightclick = function(pos, item, clicker)
local player_name = clicker:get_player_name() local player_name = clicker:get_player_name()
@ -89,46 +87,41 @@ function mcl_flowerpots.register_potted_flower(name, def)
minetest.record_protection_violation(pos, player_name) minetest.record_protection_violation(pos, player_name)
return return
end end
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name) minetest.add_item(vector.offset(pos, 0, 0.5, 0), name)
minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) minetest.set_node(pos, { name = "mcl_flowerpots:flower_pot" })
end, end,
drop = { drop = {
items = { items = {
{ items = { "mcl_flowerpots:flower_pot", name } } { items = { "mcl_flowerpots:flower_pot", name } },
} },
}, },
}) })
-- Add entry alias for the Help -- Add entry alias for the Help
if has_doc then if has_doc then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..name) doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_" .. name)
end end
end end
---@param name string
---@param def {name: string, desc: string, image: string}
function mcl_flowerpots.register_potted_cube(name, def) function mcl_flowerpots.register_potted_cube(name, def)
mcl_flowerpots.registered_pots[name] = def.name mcl_flowerpots.registered_pots[name] = def.name
minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, { minetest.register_node(":mcl_flowerpots:flower_pot_" .. def.name, {
description = def.desc.." "..S("Flower Pot"), description = def.desc .. " " .. S("Flower Pot"),
_doc_items_create_entry = false, _doc_items_create_entry = false,
drawtype = "mesh", drawtype = "mesh",
mesh = "flowerpot_with_long_cube.obj", mesh = "flowerpot_with_long_cube.obj",
tiles = { tiles = {
def.image, def.image,
}, },
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, use_texture_alpha = "clip",
visual_scale = 0.5, visual_scale = 0.5,
wield_scale = {x=1.0, y=1.0, z=1.0},
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
selection_box = { selection_box = pot_box,
type = "fixed", collision_box = pot_box,
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
is_ground_content = false, is_ground_content = false,
groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, groups = { dig_immediate = 3, attached_node = 1, dig_by_piston = 1, not_in_creative_inventory = 1, flower_pot = 2 },
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = mcl_sounds.node_sound_stone_defaults(),
on_rightclick = function(pos, item, clicker) on_rightclick = function(pos, item, clicker)
local player_name = "" local player_name = ""
@ -139,18 +132,18 @@ function mcl_flowerpots.register_potted_cube(name, def)
minetest.record_protection_violation(pos, player_name) minetest.record_protection_violation(pos, player_name)
return return
end end
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name) minetest.add_item(vector.offset(pos, 0, 0.5, 0), name)
minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) minetest.set_node(pos, { name = "mcl_flowerpots:flower_pot" })
end, end,
drop = { drop = {
items = { items = {
{ items = { "mcl_flowerpots:flower_pot", name } } { items = { "mcl_flowerpots:flower_pot", name } },
} },
}, },
}) })
-- Add entry alias for the Help -- Add entry alias for the Help
if has_doc then if has_doc then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..def.name) doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_" .. def.name)
end end
end end