Compare commits

...

10 Commits

Author SHA1 Message Date
Maurus
af4f256c55
Add Spanish translation (#20) 2024-06-30 14:07:31 +02:00
whosit
1bf935c33d
Change to make punch remove the plant first (#18)
This fixes item loss when the pot loses its node underneath and is converted to dropped items.
2024-03-09 19:26:57 +01:00
jolesh
2535483e85
Add Esperanto translation (#15) 2022-11-19 22:35:01 +01:00
fluxionary
7d2fecdb4a
Return "correct" drops when digging a flowerpot (#14)
This returns the result of digging the actual node in the world. the "downside" of that is that digging grass in a flowerpot might give you seeds or something now, but at least it's not a weird "not_in_creative_inventory" item.
2022-11-06 11:22:20 +01:00
fluxionary
1431a640b2
Fix error caused by returning invalid itemstack (#13) 2022-04-16 12:27:56 +02:00
Starbeamrainbowlabs
4dff9943d9
Fix texture alpha warnings since 5.5.0-dev (#12) 2021-10-16 14:36:01 +02:00
SmallJoker
3a933aa081
Make flowerpot registration possible from other mods 2021-07-19 19:31:18 +02:00
mazes-80
8802188e53 Add default bush sapling support 2020-09-10 14:07:13 +02:00
SmallJoker
e017fcbbe8 Replace doors_blank.png with blank.png 2020-09-10 14:02:53 +02:00
Louis Royer
f3d5285337
Make all depends optional except default (#8)
Registers flowerpots based on mods that are enabled and supported.
2020-02-15 11:59:39 +01:00
5 changed files with 123 additions and 60 deletions

27
.luacheckrc Normal file
View File

@ -0,0 +1,27 @@
quiet = 1
codes = true
exclude_files = {
".luarocks/*",
"worldeditadditions/utils/bit.lua"
}
ignore = {
"631", "61[124]",
"542",
"412",
"321/bit",
"21[123]"
}
-- Read-write globals (i.e. they can be defined)
globals = {
"flowerpot"
}
-- Read-only globals
read_globals = {
"minetest",
"default"
}
std = "max"

136
init.lua
View File

@ -12,54 +12,34 @@
flowerpot = {}
local f = string.format
-- Translation
local S = minetest.get_translator("flowerpot")
-- handle plant removal from flowerpot
local function flowerpot_on_punch(pos, node, puncher, pointed_thing)
if puncher and not minetest.check_player_privs(puncher, "protection_bypass") then
local name = puncher:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return false
end
end
local nodedef = minetest.registered_nodes[node.name]
local plant = nodedef.flowerpot_plantname
assert(plant, "unknown plant in flowerpot: " .. node.name)
minetest.sound_play(nodedef.sounds.dug, {pos = pos})
minetest.handle_node_drops(pos, {plant}, puncher)
minetest.swap_node(pos, {name = "flowerpot:empty"})
end
local flower_items_by_pot = {}
-- handle plant insertion into flowerpot
local function flowerpot_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
local name = clicker:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return false
end
if not minetest.is_player(clicker) then
return itemstack
end
local nodename = itemstack:get_name()
if not nodename then
return false
local player_name = clicker:get_player_name()
if minetest.is_protected(pos, player_name) then
return itemstack
end
if nodename:match("grass_1") then
nodename = nodename:gsub("grass_1", "grass_" .. math.random(5))
end
local item_name = itemstack:get_name()
local name = "flowerpot:" .. nodename:gsub(":", "_")
local def = minetest.registered_nodes[name]
local pot_name = "flowerpot:" .. item_name:gsub(":", "_")
local def = minetest.registered_nodes[pot_name]
if not def then
return itemstack
end
minetest.sound_play(def.sounds.place, {pos = pos})
minetest.swap_node(pos, {name = name})
minetest.swap_node(pos, {name = pot_name})
if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item()
end
@ -74,41 +54,69 @@ local function get_tile(def)
return tile
end
local old_get_node_drops = minetest.get_node_drops
function minetest.get_node_drops(node, toolname)
local node_name
if type(node) == "table" then
node_name = node.name
elseif type(node) == "string" then
node_name = node
end
if node_name then
local flower_item = flower_items_by_pot[node_name]
if flower_item then
local drops = old_get_node_drops(flower_item, toolname)
if drops then
table.insert(drops, "flowerpot:empty")
return drops
else
return { "flowerpot:empty" }
end
end
end
return old_get_node_drops(node, toolname)
end
function flowerpot.register_node(nodename)
assert(nodename, "no nodename passed")
local nodedef = minetest.registered_nodes[nodename]
if not nodedef then
minetest.log("error", S("@1 is not a known node, unable to register flowerpot", nodename))
return false
error(f("%s is not a known node, unable to register flowerpot", nodename))
end
local desc = nodedef.description
local name = nodedef.name:gsub(":", "_")
local tiles = {}
local tiles
if nodedef.drawtype == "plantlike" then
tiles = {
{name = "flowerpot.png"},
{name = get_tile(nodedef)},
{name = "doors_blank.png"},
{name = "blank.png"},
}
else
tiles = {
{name = "flowerpot.png"},
{name = "doors_blank.png"},
{name = "blank.png"},
{name = get_tile(nodedef)},
}
end
local dropname = nodename:gsub("grass_%d", "grass_1")
flower_items_by_pot["flowerpot:" .. name] = nodename
minetest.register_node("flowerpot:" .. name, {
minetest.register_node(":flowerpot:" .. name, {
description = S("Flowerpot with @1", desc),
drawtype = "mesh",
mesh = "flowerpot.obj",
tiles = tiles,
paramtype = "light",
sunlight_propagates = true,
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
collision_box = {
type = "fixed",
fixed = {-1/4, -1/2, -1/4, 1/4, -1/8, 1/4},
@ -120,20 +128,24 @@ function flowerpot.register_node(nodename)
sounds = default.node_sound_defaults(),
groups = {attached_node = 1, oddly_breakable_by_hand = 1, snappy = 3, not_in_creative_inventory = 1},
flowerpot_plantname = nodename,
on_dig = function(pos, node, digger)
minetest.set_node(pos, {name = "flowerpot:empty"})
local def = minetest.registered_nodes[node.name]
minetest.add_item(pos, dropname)
node_dig_prediction = "flowerpot:empty",
on_punch = function(pos, node, puncher, pointed_thing)
if not (puncher and puncher:is_player()) then
return
end
if minetest.is_protected(pos, puncher:get_player_name()) then
return
end
local toolname = puncher:get_wielded_item()
if node.name then
local flower_item = flower_items_by_pot[node.name]
if flower_item then
local drops = old_get_node_drops(flower_item, toolname)
minetest.handle_node_drops(pos, drops, puncher)
end
end
minetest.swap_node(pos, {name = "flowerpot:empty"})
end,
drop = {
max_items = 2,
items = {
{
items = {"flowerpot:empty", dropname},
rarity = 1,
},
}
},
})
end
@ -146,11 +158,12 @@ minetest.register_node("flowerpot:empty", {
wield_image = "flowerpot_item.png",
tiles = {
{name = "flowerpot.png"},
{name = "doors_blank.png"},
{name = "doors_blank.png"},
{name = "blank.png"},
{name = "blank.png"},
},
paramtype = "light",
sunlight_propagates = true,
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
collision_box = {
type = "fixed",
fixed = {-1/4, -1/2, -1/4, 1/4, -1/8, 1/4},
@ -173,12 +186,14 @@ minetest.register_craft({
}
})
-- default farming nodes
for _, node in pairs({
-- default nodes
"default:acacia_bush_sapling",
"default:acacia_bush_stem",
"default:acacia_sapling",
"default:aspen_sapling",
"default:blueberry_bush_sapling",
"default:pine_bush_sapling",
"default:bush_sapling",
"default:bush_stem",
"default:cactus",
@ -206,6 +221,7 @@ for _, node in pairs({
"default:fern_1",
"default:fern_2",
"default:fern_3",
-- farming nodes
"farming:cotton_1",
"farming:cotton_2",
"farming:cotton_3",
@ -222,6 +238,7 @@ for _, node in pairs({
"farming:wheat_6",
"farming:wheat_7",
"farming:wheat_8",
-- flowers nodes
"flowers:dandelion_white",
"flowers:dandelion_yellow",
"flowers:geranium",
@ -232,6 +249,7 @@ for _, node in pairs({
"flowers:viola",
"flowers:chrysanthemum_green",
"flowers:tulip_black",
-- moretrees nodes
"moretrees:beech_sapling",
"moretrees:apple_tree_sapling",
"moretrees:oak_sapling",
@ -260,6 +278,7 @@ for _, node in pairs({
"moretrees:rubber_tree_sapling_ongen",
"moretrees:fir_sapling_ongen",
"moretrees:jungletree_sapling_ongen",
-- dryplants nodes
"dryplants:grass",
"dryplants:grass_short",
"dryplants:hay",
@ -273,10 +292,13 @@ for _, node in pairs({
"dryplants:reedmace",
"dryplants:reedmace_bottom",
"dryplants:reedmace_sapling",
-- poisonivy nodes
"poisonivy:seedling",
"poisonivy:sproutling",
"poisonivy:climbing",
}) do
flowerpot.register_node(node)
if minetest.registered_nodes[node] then
flowerpot.register_node(node)
end
end

7
locale/flowerpot.eo.tr Normal file
View File

@ -0,0 +1,7 @@
# textdomain: flowerpot
@1 is not a known node, unable to register flowerpot=@1 ne estas konata nodo, nekapabla registri florpoton
Flowerpot with @1=Florpoto kun @1
Flowerpot=Florpoto

7
locale/flowerpot.es.tr Normal file
View File

@ -0,0 +1,7 @@
# textdomain: flowerpot
@1 is not a known node, unable to register flowerpot=@1 no es un nodo conocido, no se pudo registrar la maceta
Flowerpot with @1=Maceta con @1
Flowerpot=Maceta

View File

@ -1,4 +1,4 @@
name = flowerpot
depends = default, farming, flowers
optional_depends = moretrees, dryplants, poisonivy
description = A stylish flowerpot that can contain most plants.
depends = default
optional_depends = moretrees, dryplants, poisonivy, farming, flowers
description = A stylish flowerpot that can contain most plants.