Fix campfire drops to work correctly with creative and silk touch

This commit is contained in:
PrairieWind 2023-06-21 12:37:41 -06:00 committed by ancientmarinerdev
parent 4c59b189dd
commit 4c3e521779
1 changed files with 32 additions and 12 deletions

View File

@ -5,6 +5,22 @@ local food_entity = {nil, nil, nil, nil}
local drop_inventory = mcl_util.drop_items_from_meta_container("main") local drop_inventory = mcl_util.drop_items_from_meta_container("main")
local function campfire_drops(pos, digger, drops, nodename)
local wield_item = digger:get_wielded_item()
local silk_touch = mcl_enchanting.has_enchantment(wield_item, "silk_touch")
local is_creative = minetest.is_creative_enabled(digger:get_player_name())
local inv = digger:get_inventory()
if not is_creative then
if silk_touch then
minetest.add_item(pos, nodename)
else
minetest.add_item(pos, drops)
end
elseif is_creative and inv:room_for_item("main", nodename) and not inv:contains_item("main", nodename) then
inv:add_item("main", nodename)
end
end
local function drop_items(pos, node, oldmeta) local function drop_items(pos, node, oldmeta)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
drop_inventory(pos, node, oldmeta) drop_inventory(pos, node, oldmeta)
@ -66,9 +82,9 @@ function mcl_campfires.take_item(pos, node, player, itemstack)
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_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_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 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_x_"..tostring(space), tostring(food_entity[space]:get_pos().x))
campfire_meta:set_string("food_y_"..tostring(space), tostring(food_entity[space]:getpos().y)) campfire_meta:set_string("food_y_"..tostring(space), tostring(food_entity[space]:get_pos().y))
campfire_meta:set_string("food_z_"..tostring(space), tostring(food_entity[space]:getpos().z)) campfire_meta:set_string("food_z_"..tostring(space), tostring(food_entity[space]:get_pos().z))
break break
end end
end end
@ -95,9 +111,9 @@ function mcl_campfires.cook_item(pos, elapsed)
if entites then if entites then
for _, entity in ipairs(entites) do for _, entity in ipairs(entites) do
if entity then if entity then
luaentity = entity:get_luaentity() local luaentity = entity:get_luaentity()
if luaentity then if luaentity then
name = luaentity.name local name = luaentity.name
if name == "mcl_campfires:food_entity" then if name == "mcl_campfires:food_entity" then
food_entity = entity food_entity = entity
food_entity:set_properties({wield_item = inv:get_stack("main", i):get_name()}) food_entity:set_properties({wield_item = inv:get_stack("main", i):get_name()})
@ -151,13 +167,12 @@ function mcl_campfires.register_campfire(name, def)
use_texture_alpha = "clip", use_texture_alpha = "clip",
groups = { handy=1, axey=1, material_wood=1, not_in_creative_inventory=1, campfire=1, }, groups = { handy=1, axey=1, material_wood=1, not_in_creative_inventory=1, campfire=1, },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "4dir",
_on_ignite = function(player, node) _on_ignite = function(player, node)
mcl_campfires.light_campfire(node.under) mcl_campfires.light_campfire(node.under)
return true return true
end, end,
drop = def.drops, drop = "",
_mcl_silk_touch_drop = {name},
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = mcl_sounds.node_sound_wood_defaults(),
selection_box = { selection_box = {
type = 'fixed', type = 'fixed',
@ -169,6 +184,9 @@ function mcl_campfires.register_campfire(name, def)
}, },
_mcl_blast_resistance = 2, _mcl_blast_resistance = 2,
_mcl_hardness = 2, _mcl_hardness = 2,
after_dig_node = function(pos, node, oldmeta, digger)
campfire_drops(pos, digger, def.drops, name.."_lit")
end,
}) })
--Define Lit Campfire --Define Lit Campfire
@ -199,7 +217,7 @@ function mcl_campfires.register_campfire(name, def)
use_texture_alpha = "clip", use_texture_alpha = "clip",
groups = { handy=1, axey=1, material_wood=1, lit_campfire=1 }, groups = { handy=1, axey=1, material_wood=1, lit_campfire=1 },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "4dir",
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -228,8 +246,7 @@ function mcl_campfires.register_campfire(name, def)
end end
end, end,
on_timer = mcl_campfires.cook_item, on_timer = mcl_campfires.cook_item,
drop = def.drops, drop = "",
_mcl_silk_touch_drop = {name.."_lit"},
light_source = def.lightlevel, light_source = def.lightlevel,
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = mcl_sounds.node_sound_wood_defaults(),
selection_box = { selection_box = {
@ -244,7 +261,10 @@ function mcl_campfires.register_campfire(name, def)
_mcl_hardness = 2, _mcl_hardness = 2,
damage_per_second = def.damage, damage_per_second = def.damage,
on_blast = on_blast, on_blast = on_blast,
after_dig_node = drop_items, after_dig_node = function(pos, node, oldmeta, digger)
drop_items(pos, node, oldmeta)
campfire_drops(pos, digger, def.drops, name.."_lit")
end,
_mcl_campfires_smothered_form = name, _mcl_campfires_smothered_form = name,
}) })
end end