Compare commits

...

14 Commits

Author SHA1 Message Date
PrairieWind c41baccdf7 Update campfire rightclick and smothering 2023-06-07 17:13:19 -06:00
DinoNuggies4665 51988c317d Food entities don't turn back to mutton when leaving a re-joining now 2023-06-05 17:17:49 -06:00
DinoNuggies4665 6ee4f419c0 The food is now oriented the right direction when on the cooking on the campfire, and food entities are removed when the campfire is destroyed, still doesn't drop items though 2023-06-05 17:17:49 -06:00
DinoNuggies4665 39c501bc6b Fixed crash when standing on campfire whilst food is cooking 2023-06-05 17:17:49 -06:00
DinoNuggies4665 408c14bc26 Made food entities local to evcery campfire, and made one food entity that works for all foods 2023-06-05 17:17:49 -06:00
PrairieWind 11592ff3c9 Update ignition, smothering, and campfire inventory drops
Bonus fix for grass path creation sound traveling across the entire server
2023-06-05 17:17:49 -06:00
DinoNuggies4665 fd5bc13ae5 modified: mods/ITEMS/mcl_campfires/api.lua
modified:   mods/ITEMS/mcl_fishing/init.lua
	modified:   mods/ITEMS/mcl_mobitems/init.lua
2023-06-05 17:17:49 -06:00
DinoNuggies4665 19c071c8f1 A couple of fixes 2023-06-05 17:17:49 -06:00
DinoNuggies4665 c6391af5d7 Added visible items cooking on the fire 2023-06-05 17:17:49 -06:00
DinoNuggies4665 d88de72f77 modified: mods/ITEMS/mcl_campfires/mod.conf 2023-06-05 17:17:49 -06:00
DinoNuggies4665 b67f96e485 modified: mods/ITEMS/mcl_campfires/api.lua
modified:   mods/ITEMS/mcl_mobitems/init.lua
2023-06-05 17:17:49 -06:00
DinoNuggies4665 32b7c88e07 Added visible items cooking on the fire 2023-06-05 17:17:49 -06:00
PrairieWind d8cb28b800 Campfires make big smoke
Smells like carcenogens, yum
2023-06-05 17:17:49 -06:00
PrairieWind af414d84f2 Make campfires cook items 2023-06-05 17:17:49 -06:00
11 changed files with 264 additions and 30 deletions

View File

@ -1,6 +1,7 @@
local S = minetest.get_translator(minetest.get_current_modname())
local mod_target = minetest.get_modpath("mcl_target")
local mod_campfire = minetest.get_modpath("mcl_campfires")
local enable_pvp = minetest.settings:get_bool("enable_pvp")
local math = math
@ -395,6 +396,11 @@ function ARROW_ENTITY.on_step(self, dtime)
tnt.ignite(self._stuckin)
end
-- Ignite Campfires
if mod_campfire and mcl_burning.is_burning(self.object) and minetest.get_item_group(snode.name, "campfire") ~= 0 then
mcl_campfires.light_campfire(self._stuckin)
end
-- Activate target
if mod_target and snode.name == "mcl_target:target_off" then
mcl_target.hit(self._stuckin, 1) --10 redstone ticks

View File

@ -1,7 +1,5 @@
MineClone 2 Campfire API
========================
`mcl_campfires.register_campfire`
---------------------------------
# MineClone 2 Campfire API
## `mcl_campfires.register_campfire`
Used to register campfires.
**Example Usage**
@ -23,4 +21,7 @@ mcl_campfires.register_campfire("mcl_campfires:campfire", {
* lit_logs_texture - texture for the logs of the lit campfire. if not changed, specify mcl_campfires_log.png.
* drops - what items drop when the campfire is mined.
* lightlevel - the level of light the campfire emits.
* damage - amount of damage the campfire deals when the player stands on it.
* damage - amount of damage the campfire deals when the player stands on it.
## Cooking Items
To allow an item to be cooked on the campfire, it must first have a registered cooked variant. To allow placing the item on the campfire to be cooked, add `campfire_cookable = 1` into the item groups list.

View File

@ -1,6 +1,144 @@
local S = minetest.get_translator(minetest.get_current_modname())
mcl_campfires = {}
local food_entity = {nil, nil, nil, nil}
local drop_inventory = mcl_util.drop_items_from_meta_container("main")
local function drop_items(pos, node, oldmeta)
local meta = minetest.get_meta(pos)
drop_inventory(pos, node, oldmeta)
local entites = minetest.get_objects_inside_radius(pos, 0.5)
if entites then
for _, food_entity in ipairs(entites) do
if food_entity then
if food_entity:get_luaentity().name == "mcl_campfires:food_entity" then
food_entity:remove()
for i = 1, 4 do
meta:set_string("food_x_"..tostring(i), nil)
meta:set_string("food_y_"..tostring(i), nil)
meta:set_string("food_z_"..tostring(i), nil)
end
end
end
end
end
end
local function on_blast(pos)
local node = minetest.get_node(pos)
drop_items(pos, node)
minetest.remove_node(pos)
end
function mcl_campfires.light_campfire(pos)
local campfire = minetest.get_node(pos)
local name = campfire.name .. "_lit"
minetest.set_node(pos, {name = name, param2 = campfire.param2})
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 = {
vector.new(-0.25, -0.04, -0.25),
vector.new( 0.25, -0.04, -0.25),
vector.new( 0.25, -0.04, 0.25),
vector.new(-0.25, -0.04, 0.25),
}
local food_entity = {nil,nil,nil,nil}
local is_creative = minetest.is_creative_enabled(player:get_player_name())
local inv = player:get_inventory()
local campfire_meta = minetest.get_meta(pos)
local campfire_inv = campfire_meta:get_inventory()
local timer = minetest.get_node_timer(pos)
local stack = itemstack:peek_item(1)
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
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
food_entity[space] = minetest.add_entity(pos + campfire_spots[space], "mcl_campfires:food_entity") -- Spawn food item on the campfire
local food_luaentity = food_entity[space]:get_luaentity()
food_luaentity.wield_item = campfire_inv:get_stack("main", space):get_name() -- Set the wielditem of the food item to the food on the campfire
food_luaentity.wield_image = "mcl_mobitems_"..string.sub(campfire_inv:get_stack("main", space):get_name(), 14).."_raw.png" -- Set the wield_image to the food item on the campfire
food_entity[space]:set_properties(food_luaentity) -- Apply changes to the food entity
campfire_meta:set_string("food_x_"..tostring(space), tostring(food_entity[space]:getpos().x))
campfire_meta:set_string("food_y_"..tostring(space), tostring(food_entity[space]:getpos().y))
campfire_meta:set_string("food_z_"..tostring(space), tostring(food_entity[space]:getpos().z))
break
end
end
end
timer:start(1) -- Start cook timer
end
end
-- on_timer function to run the cook timer and cook items.
function mcl_campfires.cook_item(pos, elapsed)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local continue = 0
-- Cycle through slots to cook them.
for i = 1, 4 do
local time_r = meta:get_int("cooktime_"..tostring(i))
local item = inv:get_stack("main", i)
local food_entity = nil
local food_x = tonumber(meta:get_string("food_x_"..tostring(i)))
local food_y = tonumber(meta:get_string("food_y_"..tostring(i)))
local food_z = tonumber(meta:get_string("food_z_"..tostring(i)))
if food_x and food_y and food_z then
local entites = minetest.get_objects_inside_radius({x = food_x, y = food_y, z = food_z}, 0)
if entites then
for _, entity in ipairs(entites) do
if entity then
luaentity = entity:get_luaentity()
if luaentity then
name = luaentity.name
if name == "mcl_campfires:food_entity" then
food_entity = entity
luaentity.wield_item = inv:get_stack("main", i):get_name()
luaentity.wield_image = "mcl_mobitems_"..string.sub(inv:get_stack("main", i):get_name(), 14).."_raw.png"
food_entity:set_properties(luaentity)
end
end
end
end
end
end
if item ~= (ItemStack("") or ItemStack("nil")) then
-- Item hasn't been cooked completely, continue cook timer countdown.
if time_r and time_r ~= 0 and time_r > 0 then
meta:set_int("cooktime_"..tostring(i), time_r - 1)
-- Item cook timer is up, finish cooking process and drop cooked item.
elseif time_r <= 0 then
local cooked = minetest.get_craft_result({method = "cooking", width = 1, items = {item}})
if cooked then
if food_entity then
food_entity:remove() -- Remove visual food entity
meta:set_string("food_x_"..tostring(i), nil)
meta:set_string("food_y_"..tostring(i), nil)
meta:set_string("food_z_"..tostring(i), nil)
end
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
end
-- Not all slots are empty, continue timer.
if continue ~= 4 then
return true
-- Slots are empty, stop node timer.
else
return false
end
end
function mcl_campfires.register_campfire(name, def)
-- Define Campfire
minetest.register_node(name, {
@ -16,15 +154,13 @@ function mcl_campfires.register_campfire(name, def)
groups = { handy=1, axey=1, material_wood=1, not_in_creative_inventory=1, campfire=1, },
paramtype = "light",
paramtype2 = "facedir",
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
if player:get_wielded_item():get_name() == "mcl_fire:flint_and_steel" then
node.name = name.."_lit"
minetest.set_node(pos, node)
end
_on_ignite = function(player, node)
mcl_campfires.light_campfire(node.under)
return true
end,
drop = def.drops,
_mcl_silk_touch_drop = {name},
mcl_sounds.node_sound_wood_defaults(),
sounds = mcl_sounds.node_sound_wood_defaults(),
selection_box = {
type = 'fixed',
fixed = {-.5, -.5, -.5, .5, -.05, .5}, --left, bottom, front, right, top
@ -63,20 +199,41 @@ function mcl_campfires.register_campfire(name, def)
}}
},
use_texture_alpha = "clip",
groups = { handy=1, axey=1, material_wood=1, campfire=1, lit_campfire=1 },
groups = { handy=1, axey=1, material_wood=1, lit_campfire=1 },
paramtype = "light",
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 4)
end,
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
if player:get_wielded_item():get_name():find("shovel") then
node.name = name
minetest.set_node(pos, node)
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true)
if minetest.get_item_group(itemstack:get_name(), "shovel") ~= 0 then
local protected = mcl_util.check_position_protection(pos, player)
if not protected then
if not minetest.is_creative_enabled(player:get_player_name()) then
-- Add wear (as if digging a shovely node)
local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "shovely")
if wear then
itemstack:add_wear(wear)
end
end
node.name = name
minetest.set_node(pos, node)
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true)
end
elseif minetest.get_item_group(itemstack:get_name(), "campfire_cookable") ~= 0 then
mcl_campfires.take_item(pos, node, player, itemstack)
else
minetest.item_place_node(itemstack, player, pointed_thing)
end
end,
on_timer = mcl_campfires.cook_item,
drop = def.drops,
_mcl_silk_touch_drop = {name.."_lit"},
light_source = def.lightlevel,
mcl_sounds.node_sound_wood_defaults(),
sounds = mcl_sounds.node_sound_wood_defaults(),
selection_box = {
type = "fixed",
fixed = {-.5, -.5, -.5, .5, -.05, .5}, --left, bottom, front, right, top
@ -88,6 +245,9 @@ 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,
_mcl_campfires_smothered_form = name,
})
end
@ -115,3 +275,38 @@ minetest.register_globalstep(function(dtime)
end
end
end)
function mcl_campfires.generate_smoke(pos, haybale)
local smoke_timer
if haybale then
smoke_timer = 8
else
smoke_timer = 4.75
end
minetest.add_particle({
pos = pos,
velocity = vector.new(0, 1, 0),
texture = "mcl_particles_smoke.png",
size = 10,
acceleration = vector.new(0, 0.5, 0),
collisiondetection = true,
expirationtime = smoke_timer,
})
end
minetest.register_abm({
label = "Campfire Smoke",
nodenames = {"group:lit_campfire"},
interval = 2,
chance = 2,
action = function(pos, node)
local node_below = vector.offset(pos, 0, -1, 0)
local haybale = false
if minetest.get_node(node_below).name == "mcl_farming:hay_block" then
haybale = true
end
mcl_campfires.generate_smoke(pos, haybale)
end,
})

View File

@ -1,7 +1,6 @@
-- TO-DO:
-- * Add Smoke Particles
-- * Add Spark Particles
-- * Add Cooking Meat
-- * Add Working Sounds
local modname = minetest.get_modpath(minetest.get_current_modname())

View File

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

View File

@ -40,3 +40,19 @@ minetest.register_craft({
{ "group:tree", "group:tree", "group:tree" },
}
})
-- Register Visual Food Entity
minetest.register_entity("mcl_campfires:food_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.object:set_rotation({x = math.pi / -2, y = 0, z = 0})
end,
})

View File

@ -66,6 +66,12 @@ minetest.register_tool("mcl_fire:flint_and_steel", {
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
-- Ignite Campfire
elseif minetest.get_item_group(dropnode.name, "campfire") ~= 0 then
add_node(droppos, {name=dropnode.name.."_lit"})
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
end
return stack
end,

View File

@ -432,7 +432,7 @@ minetest.register_craftitem("mcl_fishing:fish_raw", {
on_place = minetest.item_eat(2),
on_secondary_use = minetest.item_eat(2),
stack_max = 64,
groups = { food=2, eatable = 2, smoker_cookable = 1 },
groups = { food=2, eatable = 2, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 0.4,
})
@ -462,7 +462,7 @@ minetest.register_craftitem("mcl_fishing:salmon_raw", {
on_place = minetest.item_eat(2),
on_secondary_use = minetest.item_eat(2),
stack_max = 64,
groups = { food=2, eatable = 2, smoker_cookable = 1 },
groups = { food=2, eatable = 2, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 0.4,
})

View File

@ -20,7 +20,7 @@ minetest.register_craftitem("mcl_mobitems:mutton", {
wield_image = "mcl_mobitems_mutton_raw.png",
on_place = minetest.item_eat(2),
on_secondary_use = minetest.item_eat(2),
groups = { food = 2, eatable = 2, smoker_cookable = 1 },
groups = { food = 2, eatable = 2, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 1.2,
stack_max = 64,
})
@ -44,7 +44,7 @@ minetest.register_craftitem("mcl_mobitems:beef", {
wield_image = "mcl_mobitems_beef_raw.png",
on_place = minetest.item_eat(3),
on_secondary_use = minetest.item_eat(3),
groups = { food = 2, eatable = 3, smoker_cookable = 1 },
groups = { food = 2, eatable = 3, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 1.8,
stack_max = 64,
})
@ -69,7 +69,7 @@ minetest.register_craftitem("mcl_mobitems:chicken", {
wield_image = "mcl_mobitems_chicken_raw.png",
on_place = minetest.item_eat(2),
on_secondary_use = minetest.item_eat(2),
groups = { food = 2, eatable = 2, smoker_cookable = 1 },
groups = { food = 2, eatable = 2, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 1.2,
stack_max = 64,
})
@ -93,7 +93,7 @@ minetest.register_craftitem("mcl_mobitems:porkchop", {
wield_image = "mcl_mobitems_porkchop_raw.png",
on_place = minetest.item_eat(3),
on_secondary_use = minetest.item_eat(3),
groups = { food = 2, eatable = 3, smoker_cookable = 1 },
groups = { food = 2, eatable = 3, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 1.8,
stack_max = 64,
})
@ -117,7 +117,7 @@ minetest.register_craftitem("mcl_mobitems:rabbit", {
wield_image = "mcl_mobitems_rabbit_raw.png",
on_place = minetest.item_eat(3),
on_secondary_use = minetest.item_eat(3),
groups = { food = 2, eatable = 3, smoker_cookable = 1 },
groups = { food = 2, eatable = 3, smoker_cookable = 1, campfire_cookable = 1 },
_mcl_saturation = 1.8,
stack_max = 64,
})

View File

@ -969,7 +969,7 @@ end
function mcl_potions._extinguish_nearby_fire(pos, radius)
local epos = {x=pos.x, y=pos.y+0.5, z=pos.z}
local dnode = minetest.get_node({x=pos.x,y=pos.y-0.5,z=pos.z})
if minetest.get_item_group(dnode.name, "fire") ~= 0 then
if minetest.get_item_group(dnode.name, "fire") ~= 0 or minetest.get_item_group(dnode.name, "lit_campfire") ~= 0 then
epos.y = pos.y - 0.5
end
local exting = false
@ -989,6 +989,11 @@ function mcl_potions._extinguish_nearby_fire(pos, radius)
minetest.sound_play("fire_extinguish_flame", {pos = tpos, gain = 0.25, max_hear_distance = 16}, true)
minetest.remove_node(tpos)
exting = true
elseif minetest.get_item_group(node.name, "lit_campfire") ~= 0 then
minetest.sound_play("fire_extinguish_flame", {pos = tpos, gain = 0.25, max_hear_distance = 16}, true)
local def = minetest.registered_nodes[node.name]
minetest.set_node(tpos, {name = def._mcl_campfires_smothered_form, param2 = node.param2})
exting = true
end
end
-- Has radius: lingering, extinguish all nodes in area
@ -996,10 +1001,16 @@ function mcl_potions._extinguish_nearby_fire(pos, radius)
local nodes = minetest.find_nodes_in_area(
{x=epos.x-radius,y=epos.y,z=epos.z-radius},
{x=epos.x+radius,y=epos.y,z=epos.z+radius},
{"group:fire"})
{"group:fire", "group:lit_campfire"})
for n=1, #nodes do
local node = minetest.get_node(nodes[n])
minetest.sound_play("fire_extinguish_flame", {pos = nodes[n], gain = 0.25, max_hear_distance = 16}, true)
minetest.remove_node(nodes[n])
if minetest.get_item_group(node.name, "fire") ~= 0 then
minetest.remove_node(nodes[n])
elseif minetest.get_item_group(node.name, "lit_campfire") ~= 0 then
local def = minetest.registered_nodes[node.name]
minetest.set_node(nodes[n], {name = def._mcl_campfires_smothered_form, param2 = node.param2})
end
exting = true
end
end

View File

@ -187,7 +187,7 @@ local make_grass_path = function(itemstack, placer, pointed_thing)
itemstack:add_wear(wear)
end
end
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above}, true)
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above, max_hear_distance = 16}, true)
minetest.swap_node(pointed_thing.under, {name="mcl_core:grass_path"})
end
end