modified: mods/ITEMS/mcl_campfires/api.lua

modified:   mods/ITEMS/mcl_mobitems/init.lua
This commit is contained in:
DinoNuggies4665 2023-05-30 16:19:48 -05:00 committed by ancientmarinerdev
parent a7fcd62999
commit aca82fcafc
2 changed files with 17 additions and 126 deletions

@ -1,16 +1,16 @@
local S = minetest.get_translator(minetest.get_current_modname())
mcl_campfires = {}
local function say(msg) minetest.chat_send_all(msg) end
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
-- 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,13 +20,12 @@ 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
for space = 1, 4 do -- Cycle through spots
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
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")
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
break
end
end
@ -52,9 +51,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)
inv:set_stack("main", i, "")
continue = continue + 1
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.
end
end
end
@ -162,6 +161,8 @@ 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

@ -25,28 +25,6 @@ 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."),
@ -71,28 +49,6 @@ 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."),
@ -118,28 +74,6 @@ 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."),
@ -164,28 +98,6 @@ 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."),
@ -210,28 +122,6 @@ 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."),
@ -449,7 +339,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 carrot 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 fungus 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 },