1
0
Fork 0

Added visible items cooking on the fire

This commit is contained in:
DinoNuggies4665 2023-05-30 16:06:57 -05:00 committed by PrairieWind
parent 1908602a9e
commit 9d147e2783
3 changed files with 128 additions and 19 deletions

View File

@ -1,16 +1,16 @@
local S = minetest.get_translator(minetest.get_current_modname())
mcl_campfires = {}
local drop_items = mcl_util.drop_items_from_meta_container("main")
local function on_blast(pos)
local node = minetest.get_node(pos)
drop_items(pos, node)
minetest.remove_node(pos)
end
local function say(msg) minetest.chat_send_all(msg) end
-- on_rightclick function to take items that are cookable in a campfire, and put them in the campfire inventory
function mcl_campfires.take_item(pos, node, player, itemstack)
local campfire_spots = {
{x = -0.25, y = -0.04, z = -0.25},
{x = 0.25, y = -0.04, z = -0.25},
{x = 0.25, y = -0.04, z = 0.25},
{x = -0.25, y = -0.04, z = 0.25},
}
local is_creative = minetest.is_creative_enabled(player:get_player_name())
local inv = player:get_inventory()
local campfire_meta = minetest.get_meta(pos)
@ -20,12 +20,13 @@ function mcl_campfires.take_item(pos, node, player, itemstack)
if minetest.get_item_group(itemstack:get_name(), "campfire_cookable") ~= 0 then
local cookable = minetest.get_craft_result({method = "cooking", width = 1, items = {itemstack}})
if cookable then
for space = 1, 4 do -- Cycle through spots
for space = 1, 4 do
local spot = campfire_inv:get_stack("main", space)
if not spot or spot == (ItemStack("") or ItemStack("nil")) then -- Check if the spot is empty or not
if not is_creative then itemstack:take_item(1) end -- Take the item if in creative
campfire_inv:set_stack("main", space, stack) -- Set the inventory itemstack at the empty spot
campfire_meta:set_int("cooktime_"..tostring(space), 30) -- Set the cook time meta
if not is_creative then itemstack:take_item(1) end
campfire_inv:set_stack("main", space, stack)
campfire_meta:set_int("cooktime_"..tostring(space), 30)
minetest.add_entity(pos + campfire_spots[space], player:get_wielded_item():get_name().."_entity")
break
end
end
@ -51,9 +52,9 @@ function mcl_campfires.cook_item(pos, elapsed)
elseif time_r <= 0 then
local cooked = minetest.get_craft_result({method = "cooking", width = 1, items = {item}})
if cooked then
minetest.add_item(pos, cooked.item) -- Drop Cooked Item
inv:set_stack("main", i, "") -- Clear Inventory
continue = continue + 1 -- Indicate that the slot is clear.
minetest.add_item(pos, cooked.item)
inv:set_stack("main", i, "")
continue = continue + 1
end
end
end
@ -161,8 +162,6 @@ function mcl_campfires.register_campfire(name, def)
_mcl_blast_resistance = 2,
_mcl_hardness = 2,
damage_per_second = def.damage,
on_blast = on_blast,
after_dig_node = drop_items,
})
end

View File

@ -1,3 +1,3 @@
name = mcl_campfires
depends = mcl_sounds, mcl_util
author = PrairieWind, Gerold55
depends = mcl_sounds
author = PrairieWind, Gerold55

View File

@ -25,6 +25,28 @@ minetest.register_craftitem("mcl_mobitems:mutton", {
stack_max = 64,
})
minetest.register_entity("mcl_mobitems:mutton_entity", {
initial_properties = {
physical = false,
visual = "wielditem",
wield_item = "mcl_mobitems:mutton",
wield_image = "mcl_mobitems_mutton_raw.png",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
pointable = false,
},
on_activate = function(self, staticdata)
self.timer = 0
self.object:set_rotation({x = math.pi / 2, y = 0, z = 0})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 31 then
self.object:remove()
end
end,
})
minetest.register_craftitem("mcl_mobitems:cooked_mutton", {
description = S("Cooked Mutton"),
_doc_items_longdesc = S("Cooked mutton is the cooked flesh from a sheep and is used as food."),
@ -49,6 +71,28 @@ minetest.register_craftitem("mcl_mobitems:beef", {
stack_max = 64,
})
minetest.register_entity("mcl_mobitems:beef_entity", {
initial_properties = {
physical = false,
visual = "wielditem",
wield_item = "mcl_mobitems:beef",
wield_image = "mcl_mobitems_beef_raw.png",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
pointable = false,
},
on_activate = function(self, staticdata)
self.timer = 0
self.object:set_rotation({x = math.pi / 2, y = 0, z = 0})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 31 then
self.object:remove()
end
end,
})
minetest.register_craftitem("mcl_mobitems:cooked_beef", {
description = S("Steak"),
_doc_items_longdesc = S("Steak is cooked beef from cows and can be eaten."),
@ -74,6 +118,28 @@ minetest.register_craftitem("mcl_mobitems:chicken", {
stack_max = 64,
})
minetest.register_entity("mcl_mobitems:chicken_entity", {
initial_properties = {
physical = false,
visual = "wielditem",
wield_item = "mcl_mobitems:chicken",
wield_image = "mcl_mobitems_chicken_raw.png",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
pointable = false,
},
on_activate = function(self, staticdata)
self.timer = 0
self.object:set_rotation({x = math.pi / 2, y = 0, z = 0})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 31 then
self.object:remove()
end
end,
})
minetest.register_craftitem("mcl_mobitems:cooked_chicken", {
description = S("Cooked Chicken"),
_doc_items_longdesc = S("A cooked chicken is a healthy food item which can be eaten."),
@ -98,6 +164,28 @@ minetest.register_craftitem("mcl_mobitems:porkchop", {
stack_max = 64,
})
minetest.register_entity("mcl_mobitems:porkchop_entity", {
initial_properties = {
physical = false,
visual = "wielditem",
wield_item = "mcl_mobitems:porkchop",
wield_image = "mcl_mobitems_porkchop_raw.png",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
pointable = false,
},
on_activate = function(self, staticdata)
self.timer = 0
self.object:set_rotation({x = math.pi / 2, y = 0, z = 0})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 31 then
self.object:remove()
end
end,
})
minetest.register_craftitem("mcl_mobitems:cooked_porkchop", {
description = S("Cooked Porkchop"),
_doc_items_longdesc = S("Cooked porkchop is the cooked flesh of a pig and is used as food."),
@ -122,6 +210,28 @@ minetest.register_craftitem("mcl_mobitems:rabbit", {
stack_max = 64,
})
minetest.register_entity("mcl_mobitems:rabbit_entity", {
initial_properties = {
physical = false,
visual = "wielditem",
wield_item = "mcl_mobitems:rabbit",
wield_image = "mcl_mobitems_rabbit_raw.png",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
pointable = false,
},
on_activate = function(self, staticdata)
self.timer = 0
self.object:set_rotation({x = math.pi / 2, y = 0, z = 0})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 31 then
self.object:remove()
end
end,
})
minetest.register_craftitem("mcl_mobitems:cooked_rabbit", {
description = S("Cooked Rabbit"),
_doc_items_longdesc = S("This is a food item which can be eaten."),
@ -339,7 +449,7 @@ minetest.register_tool("mcl_mobitems:warped_fungus_on_a_stick", {
description = S("Warped fungus on a Stick"),
_tt_help = S("Lets you ride a strider"),
_doc_items_longdesc = S("A warped fungus on a stick can be used on saddled striders to ride them."),
_doc_items_usagehelp = S("Place it on a saddled strider to mount it. You can now ride the strider like a horse. Striders will also walk towards you when you just wield the fungus on a stick."),
_doc_items_usagehelp = S("Place it on a saddled strider to mount it. You can now ride the strider like a horse. Striders will also walk towards you when you just wield the carrot on a stick."),
wield_image = "mcl_mobitems_warped_fungus_on_a_stick.png^[transformFY^[transformR90",
inventory_image = "mcl_mobitems_warped_fungus_on_a_stick.png",
groups = { transport = 1 },