Compare commits
10 Commits
d346732a86
...
af4f256c55
Author | SHA1 | Date | |
---|---|---|---|
|
af4f256c55 | ||
|
1bf935c33d | ||
|
2535483e85 | ||
|
7d2fecdb4a | ||
|
1431a640b2 | ||
|
4dff9943d9 | ||
|
3a933aa081 | ||
|
8802188e53 | ||
|
e017fcbbe8 | ||
|
f3d5285337 |
27
.luacheckrc
Normal file
27
.luacheckrc
Normal 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
136
init.lua
@ -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
7
locale/flowerpot.eo.tr
Normal 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
7
locale/flowerpot.es.tr
Normal 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
|
6
mod.conf
6
mod.conf
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user