Render mcl_farming plant grids 1/16 node lower

This patch replaces the plantlike drawtype of mcl_farming plant nodes
that are rendered like a grid (#) with a nodebox drawtype. The nodebox
looks like a plantlike grid shifted 1/16 nodes downwards. The goal is to
remove gaps between plants and farming soil with a node height of 15/16.

This patch affects beetroot, carrots, potatoes, and wheat nodes.
master
Nils Dagsson Moskopp 2022-04-18 07:32:47 +02:00
parent de8ea11b39
commit 14cbc63b5f
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
5 changed files with 91 additions and 42 deletions

View File

@ -18,19 +18,21 @@ minetest.register_node("mcl_farming:beetroot_0", {
_doc_items_longdesc = S("Beetroot plants are plants which grow on farmland under sunlight in 4 stages. On hydrated farmland, they grow a bit faster. They can be harvested at any time but will only yield a profit when mature."),
_doc_items_entry_name = S("Premature Beetroot Plant"),
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:beetroot_seeds",
tiles = {"mcl_farming_beetroot_0.png"},
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_beetroot_0.png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_beetroot_0.png",
wield_image = "mcl_farming_beetroot_0.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
{-0.5, -9/16, -0.5, 0.5, -6/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},
@ -42,19 +44,21 @@ minetest.register_node("mcl_farming:beetroot_1", {
description = S("Premature Beetroot Plant (Stage 2)"),
_doc_items_create_entry = false,
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:beetroot_seeds",
tiles = {"mcl_farming_beetroot_1.png"},
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_beetroot_1.png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_beetroot_1.png",
wield_image = "mcl_farming_beetroot_1.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -3/16, 0.5}
{-0.5, -9/16, -0.5, 0.5, -4/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},
@ -66,19 +70,21 @@ minetest.register_node("mcl_farming:beetroot_2", {
description = S("Premature Beetroot Plant (Stage 3)"),
_doc_items_create_entry = false,
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:beetroot_seeds",
tiles = {"mcl_farming_beetroot_2.png"},
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_beetroot_2.png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_beetroot_2.png",
wield_image = "mcl_farming_beetroot_2.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 2/16, 0.5}
{-0.5, -9/16, -0.5, 0.5, 1/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},
@ -91,11 +97,12 @@ minetest.register_node("mcl_farming:beetroot", {
_doc_items_longdesc = S("A mature beetroot plant is a farming plant which is ready to be harvested for a beetroot and some beetroot seeds. It won't grow any further."),
_doc_items_create_entry = true,
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = {
--[[ drops 1 beetroot guaranteed.
drops 1-4 beetroot seeds:
@ -112,13 +119,14 @@ minetest.register_node("mcl_farming:beetroot", {
{ items = {"mcl_farming:beetroot_seeds 1"}, rarity = 4 },
},
},
tiles = {"mcl_farming_beetroot_3.png"},
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_beetroot_3.png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_beetroot_3.png",
wield_image = "mcl_farming_beetroot_3.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 3/16, 0.5}
{-0.5, -9/16, -0.5, 0.5, 2/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1,beetroot=4},

View File

@ -28,18 +28,20 @@ for i=1, 7 do
_doc_items_longdesc = longdesc,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "meshoptions",
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:carrot_item",
tiles = {texture},
tiles = { mcl_farming:align_plantlike_nodebox_texture(texture) },
use_texture_alpha = "clip",
inventory_image = texture,
wield_image = texture,
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, sel_height, 0.5}
{-0.5, -9/16, -0.5, 0.5, sel_height - 1/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},
@ -53,11 +55,13 @@ minetest.register_node("mcl_farming:carrot", {
_doc_items_longdesc = S("Mature carrot plants are ready to be harvested for carrots. They won't grow any further."),
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "meshoptions",
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
tiles = {"farming_carrot_4.png"},
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
tiles = { mcl_farming:align_plantlike_nodebox_texture("farming_carrot_4.png") },
use_texture_alpha = "clip",
inventory_image = "farming_carrot_4.png",
wield_image = "farming_carrot_4.png",
drop = {
@ -72,7 +76,7 @@ minetest.register_node("mcl_farming:carrot", {
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 4/16, 0.5}
{-0.5, -9/16, -0.5, 0.5, 3/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},

View File

@ -6,13 +6,13 @@ for i=1, 7 do
local texture, selbox
if i < 3 then
texture = "mcl_farming_potatoes_stage_0.png"
selbox = { -0.5, -0.5, -0.5, 0.5, -5/16, 0.5 }
selbox = { -0.5, -9/16, -0.5, 0.5, -6/16, 0.5 }
elseif i < 5 then
texture = "mcl_farming_potatoes_stage_1.png"
selbox = { -0.5, -0.5, -0.5, 0.5, -2/16, 0.5 }
selbox = { -0.5, -9/16, -0.5, 0.5, -3/16, 0.5 }
else
texture = "mcl_farming_potatoes_stage_2.png"
selbox = { -0.5, -0.5, -0.5, 0.5, 2/16, 0.5 }
selbox = { -0.5, -9/16, -0.5, 0.5, 1/16, 0.5 }
end
local create, name, longdesc
@ -33,13 +33,15 @@ for i=1, 7 do
_doc_items_entry_name = name,
_doc_items_longdesc = longdesc,
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:potato_item",
tiles = { texture },
tiles = { mcl_farming:align_plantlike_nodebox_texture(texture) },
use_texture_alpha = "clip",
inventory_image = texture,
wield_image = texture,
selection_box = {
@ -57,12 +59,14 @@ minetest.register_node("mcl_farming:potato", {
description = S("Mature Potato Plant"),
_doc_items_longdesc = S("Mature potato plants are ready to be harvested for potatoes. They won't grow any further."),
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
tiles = {"mcl_farming_potatoes_stage_3.png"},
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_potatoes_stage_3.png") },
use_texture_alpha = "clip",
wield_image = "mcl_farming_potatoes_stage_3.png",
inventory_image = "mcl_farming_potatoes_stage_3.png",
drop = {
@ -77,7 +81,7 @@ minetest.register_node("mcl_farming:potato", {
selection_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, -0.5, 0.5, 1/16, 0.5 }
{ -0.5, -9/16, -0.5, 0.5, 0, 0.5 }
}
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},

View File

@ -300,7 +300,6 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s
minetest.register_node(stem_itemstring, stem_def)
-- Register connected stems
local connected_stem_tiles = {
{ "blank.png", --top
"blank.png", -- bottom
@ -469,3 +468,27 @@ minetest.register_lbm({
mcl_farming:grow_plant(identifier, pos, node, false, false, low_speed)
end,
})
-- This function returns a nodebox that imitates a plantlike grid (#)
-- drawtype, but is shifted 1/16 lower, into the empty space above
-- farming soil. The regular plantlike drawtype can not do this.
function mcl_farming:get_plantlike_grid_nodebox()
return {
type = "fixed",
fixed = {
{ 4/16, -9/16, -8/16, 4/16, 7/16, 8/16},
{-4/16, -9/16, -8/16, -4/16, 7/16, 8/16},
{-8/16, -9/16, -4/16, 8/16, 7/16, -4/16},
{-8/16, -9/16, 4/16, 8/16, 7/16, 4/16},
}
}
end
-- This function takes a texture and returns a modified texture where
-- the bottom row is at the top, assuming 16px × 16px textures. This
-- is used to align textures to a “plantlike” nodebox shifted 1/16
-- below its own node into the empty space above farming soil.
function mcl_farming:align_plantlike_nodebox_texture(texture)
local texture = texture:gsub("%^", "\\%^"):gsub(":", "\\:")
return "[combine:16x16:0,-15=" .. texture .. ":0,1=" .. texture
end

View File

@ -39,19 +39,21 @@ for i=1,7 do
_doc_items_entry_name = name,
_doc_items_longdesc = longdesc,
paramtype = "light",
paramtype2 = "meshoptions",
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
sunlight_propagates = true,
walkable = false,
drawtype = "plantlike",
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
drop = "mcl_farming:wheat_seeds",
tiles = {"mcl_farming_wheat_stage_"..(i-1)..".png"},
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_wheat_stage_"..(i-1)..".png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_wheat_stage_"..(i-1)..".png",
wield_image = "mcl_farming_wheat_stage_"..(i-1)..".png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, sel_heights[i], 0.5}
{-0.5, -9/16, -0.5, 0.5, sel_heights[i] - 1/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1},
@ -65,13 +67,21 @@ minetest.register_node("mcl_farming:wheat", {
_doc_items_longdesc = S("Mature wheat plants are ready to be harvested for wheat and wheat seeds. They won't grow any further."),
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "meshoptions",
-- keep place_param2 for plantlike drawtype compatiblity
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
tiles = {"mcl_farming_wheat_stage_7.png"},
drawtype = "nodebox",
node_box = mcl_farming:get_plantlike_grid_nodebox(),
tiles = { mcl_farming:align_plantlike_nodebox_texture("mcl_farming_wheat_stage_7.png") },
use_texture_alpha = "clip",
inventory_image = "mcl_farming_wheat_stage_7.png",
wield_image = "mcl_farming_wheat_stage_7.png",
selection_box = {
type = "fixed",
fixed = {
{ -0.5, -9/16, -0.5, 0.5, 7/16, 0.5 }
}
},
drop = {
max_items = 4,
items = {