7 cake slices instead of 6

Also refactor cake code
This commit is contained in:
Wuzzy 2017-02-28 00:01:51 +01:00
parent a18a9c5f70
commit bf2dca21ce
1 changed files with 55 additions and 133 deletions

View File

@ -5,11 +5,13 @@
local cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"} local cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"}
local slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16} local slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16}
local slice_2 = { -7/16, -8/16, -7/16, -2/16, 0/16, 7/16} local slice_2 = { -7/16, -8/16, -7/16, -3/16, 0/16, 7/16}
local slice_3 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16} local slice_3 = { -7/16, -8/16, -7/16, -1/16, 0/16, 7/16}
local slice_4 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16} local slice_4 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16}
local slice_5 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16} local slice_5 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16}
local slice_6 = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16} local slice_6 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16}
local full_cake = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16}
minetest.register_craft({ minetest.register_craft({
output = "mcl_cake:cake", output = "mcl_cake:cake",
@ -35,18 +37,18 @@ minetest.register_node("mcl_cake:cake", {
drawtype = "nodebox", drawtype = "nodebox",
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = slice_6 fixed = full_cake
}, },
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = slice_6 fixed = full_cake
}, },
stack_max = 1, stack_max = 1,
groups = {handy=1, food=2,attached_node=1}, groups = {handy=1, food=2,attached_node=1},
drop = '', drop = '',
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_5"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"}) minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_5",param2=0}) minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0})
end, end,
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
@ -54,131 +56,51 @@ minetest.register_node("mcl_cake:cake", {
_mcl_blast_resistance = 2.5, _mcl_blast_resistance = 2.5,
_mcl_hardness = 5, _mcl_hardness = 5,
}) })
minetest.register_node("mcl_cake:cake_5", {
description = "Cake (5 Slices Left)",
tiles = cake_texture,
paramtype = "light",
is_ground_content = false,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = slice_5
},
node_box = {
type = "fixed",
fixed = slice_5
},
groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1},
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_4"), ItemStack("mcl_cake:cake_5"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_4",param2=0})
end,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_food_particles = false, local register_slice = function(level, nodebox, desc)
}) local this = "mcl_cake:cake_"..level
minetest.register_node("mcl_cake:cake_4", { local after_eat = "mcl_cake:cake_"..(level-1)
description = "Cake (4 Slices Left)", local on_rightclick
tiles = cake_texture, if level > 1 then
paramtype = "light", on_rightclick = function(pos, node, clicker, itemstack)
is_ground_content = false, minetest.do_item_eat(2, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"})
drawtype = "nodebox", minetest.add_node(pos,{type="node",name=after_eat,param2=0})
selection_box = { end
type = "fixed", else
fixed = slice_4 on_rightclick = function(pos, node, clicker, itemstack)
}, minetest.do_item_eat(2, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"})
node_box = { minetest.remove_node(pos)
type = "fixed", end
fixed = slice_4 end
},
groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1},
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_3"), ItemStack("mcl_cake:cake_4"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_3",param2=0})
end,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_food_particles = false, minetest.register_node(this, {
_mcl_blast_resistance = 2.5, description = desc,
_mcl_hardness = 5, tiles = cake_texture,
}) paramtype = "light",
minetest.register_node("mcl_cake:cake_3", { is_ground_content = false,
description = "Cake (3 Slices Left)", drawtype = "nodebox",
tiles = cake_texture, selection_box = {
paramtype = "light", type = "fixed",
is_ground_content = false, fixed = nodebox,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = slice_3
},
node_box = {
type = "fixed",
fixed = slice_3
}, },
groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1}, node_box = {
drop = '', type = "fixed",
on_rightclick = function(pos, node, clicker, itemstack) fixed = nodebox,
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_2"), ItemStack("mcl_cake:cake_3"), clicker, {type="nothing"}) },
minetest.add_node(pos,{type="node",name="mcl_cake:cake_2",param2=0}) groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1},
end, drop = '',
sounds = mcl_sounds.node_sound_leaves_defaults(), on_rightclick = on_rightclick,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_food_particles = false, _food_particles = false,
_mcl_blast_resistance = 2.5, _mcl_blast_resistance = 2.5,
_mcl_hardness = 5, _mcl_hardness = 5,
}) })
minetest.register_node("mcl_cake:cake_2", { end
description = "Cake (2 Slices Left)",
tiles = cake_texture,
paramtype = "light",
is_ground_content = false,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = slice_2
},
node_box = {
type = "fixed",
fixed = slice_2
},
groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1},
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_1"), ItemStack("mcl_cake:cake_2"), clicker, {type="nothing"})
minetest.add_node(pos,{type="node",name="mcl_cake:cake_1",param2=0})
end,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_food_particles = false, register_slice(6, slice_6, "Cake (6 Slices Left")
_mcl_blast_resistance = 2.5, register_slice(5, slice_5, "Cake (5 Slices Left")
_mcl_hardness = 5, register_slice(4, slice_4, "Cake (4 Slices Left")
}) register_slice(3, slice_3, "Cake (3 Slices Left")
minetest.register_node("mcl_cake:cake_1", { register_slice(2, slice_2, "Cake (2 Slices Left")
description = "Cake (1 Slice Left)", register_slice(1, slice_1, "Cake (1 Slice Left")
tiles = cake_texture,
paramtype = "light",
is_ground_content = false,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = slice_1
},
node_box = {
type = "fixed",
fixed = slice_1
},
groups = {handy=1, food=2,attached_node=1,not_in_creative_inventory=1},
drop = '',
on_rightclick = function(pos, node, clicker, itemstack)
minetest.do_item_eat(2, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"})
minetest.remove_node(pos)
end,
sounds = mcl_sounds.node_sound_leaves_defaults(),
_food_particles = false,
_mcl_blast_resistance = 2.5,
_mcl_hardness = 5,
})