From 62d7b8cc770f1b818a4ef6145e01b2effccfe836 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 3 Jun 2022 12:43:25 +0200 Subject: [PATCH 1/3] move depends.txt to mod.conf --- depends.txt | 5 ----- mod.conf | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 depends.txt create mode 100644 mod.conf diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 6ac5f45015..0000000000 --- a/depends.txt +++ /dev/null @@ -1,5 +0,0 @@ -mcl_core -mcl_mushrooms -mcl_flowers -mcl_potions -mcl_hunger \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000000..9e28bd300c --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = mcl_sus_stew +author = chmodsayshello +depends = mcl_core, mcl_mushrooms, mcl_flowers, mcl_potions, mcl_hunger From 3cd87dfe3835fa9f8057ff0b935d2239f426b6e0 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 3 Jun 2022 12:43:47 +0200 Subject: [PATCH 2/3] use itemmeta instead of separate itemstrings --- init.lua | 187 ++++++++++++++++++++++++++----------------------------- 1 file changed, 88 insertions(+), 99 deletions(-) diff --git a/init.lua b/init.lua index 1c37741069..e39be29442 100644 --- a/init.lua +++ b/init.lua @@ -4,129 +4,118 @@ local eat = minetest.item_eat(6, "mcl_core:bowl") --6 hunger points, player receives mcl_core:bowl after eating +local flower_effect = { + [ "mcl_flowers:tulip_white" ] = "poison", + [ "mcl_flowers:blue_orchid" ] = "hunger", + [ "mcl_flowers:dandelion" ] = "hunger", + [ "mcl_flowers:peony" ] = "jump", + [ "mcl_flowers:oxeye_daisy" ] = "regeneration", + [ "mcl_flowers:poppy" ] = "night_vision" +} +local effects = { + [ "poison" ] = function(itemstack, placer, pointed_thing) + mcl_potions.poison_func(placer, 1, 12) + return eat(itemstack, placer, pointed_thing) + end, -local function poison(itemstack, placer, pointed_thing) - local hunger = mcl_hunger.get_hunger(placer) - if hunger < 20 then - mcl_potions.poison_func(placer, 1, 12) - return eat(itemstack, placer, pointed_thing) - end + [ "hunger" ] = function(itemstack, placer, pointed_thing, player) + mcl_hunger.item_eat(6, "mcl_core:bowl", 3.5, 0, 100) + return eat(itemstack, placer, pointed_thing) + end, + + ["jump"] = function(itemstack, placer, pointed_thing) + mcl_potions.leaping_func(placer, 1, 6) + return eat(itemstack, placer, pointed_thing) + end, + + ["regeneration"] = function(itemstack, placer, pointed_thing) + mcl_potions.regeneration_func(placer, 1, 8) + return eat(itemstack, placer, pointed_thing) + end, + + ["night_vision"] = function(itemstack, placer, pointed_thing) + mcl_potions.night_vision_func(placer, 1, 5) + return eat(itemstack, placer, pointed_thing) + end, +} + +local function eat_stew(itemstack, placer, pointed_thing) + local e = itemstack:get_meta():get_string("effect") + if effects[e] then + if effects[e](itemstack,placer,pointed_thing) then + return "mcl_core:bowl" + end + end end -local function hunger(itemstack, placer, pointed_thing, player) - local hunger = mcl_hunger.get_hunger(placer) - if hunger < 20 then - return eat(itemstack, placer, pointed_thing) - end -end +minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) + if itemstack:get_name() ~= "mcl_sus_stew:stew" then return end + for f,e in pairs(flower_effect) do + for _,it in pairs(old_craft_grid) do + if it:get_name() == f then + itemstack:get_meta():set_string("effect",e) + return itemstack + end + end + end +end) -local function jump_boost(itemstack, placer, pointed_thing) - local hunger = mcl_hunger.get_hunger(placer) - if hunger < 20 then - mcl_potions.leaping_func(placer, 1, 6) - return eat(itemstack, placer, pointed_thing) - end -end - -local function regeneration(itemstack, placer, pointed_thing) - local hunger = mcl_hunger.get_hunger(placer) - if hunger < 20 then - mcl_potions.regeneration_func(placer, 1, 8) - return eat(itemstack, placer, pointed_thing) - end -end - -local function night_vision(itemstack, placer, pointed_thing) - local hunger = mcl_hunger.get_hunger(placer) - if hunger < 20 then - mcl_potions.night_vision_func(placer, 1, 5) - return eat(itemstack, placer, pointed_thing) - end -end - - --- ________________________ ---_________________________________________/ Item Regestration \_________________ -minetest.register_craftitem("mcl_sus_stew:poison_stew",{ - description = "Suspicious Stew", - inventory_image = "sus_stew.png", - stack_max = 1, - on_place = poison, - groups = { food = 2, eatable = 4, not_in_creative_inventory=1,}, - _mcl_saturation = 7.2, +-- ________________________ +--_________________________________________/ Item Regestration \_________________ +minetest.register_craftitem("mcl_sus_stew:stew",{ + description = "Suspicious Stew", + inventory_image = "sus_stew.png", + stack_max = 1, + on_place = eat_stew, + groups = { food = 2, eatable = 4, can_eat_when_full = 1, not_in_creative_inventory=1,}, + _mcl_saturation = 7.2, }) -minetest.register_craftitem("mcl_sus_stew:hunger_stew",{ - description = "Suspicious Stew", - inventory_image = "sus_stew.png", - stack_max = 1, - on_place = hunger, - groups = { food = 2, eatable = 4, not_in_creative_inventory=1,}, - _mcl_saturation = 7.2, -}) +mcl_hunger.register_food("mcl_sus_stew:stew",6, "mcl_core:bowl") -minetest.register_craftitem("mcl_sus_stew:jump_boost_stew",{ - description = "Suspicious Stew", - inventory_image = "sus_stew.png", - stack_max = 1, - on_place = jump_boost, - groups = { food = 2, eatable = 4, not_in_creative_inventory=1,}, - _mcl_saturation = 7.2, -}) +--compat with old (mcl5) sus_stew +minetest.register_alias("mcl_sus_stew:poison_stew", "mcl_sus_stew:stew") +minetest.register_alias("mcl_sus_stew:hunger_stew", "mcl_sus_stew:stew") +minetest.register_alias("mcl_sus_stew:jump_boost_stew", "mcl_sus_stew:stew") +minetest.register_alias("mcl_sus_stew:regneration_stew", "mcl_sus_stew:stew") +minetest.register_alias("mcl_sus_stew:night_vision_stew", "mcl_sus_stew:stew") -minetest.register_craftitem("mcl_sus_stew:regneration_stew",{ - description = "Suspicious Stew", - inventory_image = "sus_stew.png", - stack_max = 1, - on_place = regeneration, - groups = { food = 2, eatable = 4, not_in_creative_inventory=1,}, - _mcl_saturation = 7.2, -}) - -minetest.register_craftitem("mcl_sus_stew:night_vision_stew",{ - description = "Suspicious Stew", - inventory_image = "sus_stew.png", - stack_max = 1, - on_place = night_vision, - groups = { food = 2, eatable = 4, not_in_creative_inventory=1,}, - _mcl_saturation = 7.2, -}) - --- ____________________________ ---______________________________________/ Using mcl_hunger API \______________________ -mcl_hunger.register_food("mcl_sus_stew:hunger_stew",6, "mcl_core:bowl", 3.5, 0, 100) -- Register it using mcl_hunger so i can use its poison feature - - --- ______________ ---_________________________________________/ Crafts \________________________________ +-- ______________ +--_________________________________________/ Crafts \________________________________ minetest.register_craft({ - output = "mcl_sus_stew:poison_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:tulip_white"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:tulip_white"}, }) minetest.register_craft({ - output = "mcl_sus_stew:hunger_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:blue_orchid"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:blue_orchid"}, }) minetest.register_craft({ - output = "mcl_sus_stew:hunger_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:dandelion"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:dandelion"} , }) minetest.register_craft({ - output = "mcl_sus_stew:jump_boost_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:peony"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:peony"}, }) minetest.register_craft({ - output = "mcl_sus_stew:regeneration_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:oxeye_daisy"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:oxeye_daisy"}, }) minetest.register_craft({ - output = "mcl_sus_stew:night_vision_stew", - recipe = { {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown"}, {"mcl_core:bowl", "mcl_flowers:poppy"} }, + type = "shapeless", + output = "mcl_sus_stew:stew", + recipe = {"mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "mcl_core:bowl", "mcl_flowers:poppy"}, }) From 6f3c013d41598a6083717a3e33ee9ebe1c258ce5 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 4 Jun 2022 02:44:39 +0200 Subject: [PATCH 3/3] random effect on sstew with no meta --- init.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index e39be29442..37fb5265f5 100644 --- a/init.lua +++ b/init.lua @@ -39,13 +39,22 @@ local effects = { return eat(itemstack, placer, pointed_thing) end, } +local function get_random_effect() + local keys = {} + for k in pairs(effects) do + table.insert(keys, k) + end + return effects[keys[math.random(#keys)]] +end local function eat_stew(itemstack, placer, pointed_thing) local e = itemstack:get_meta():get_string("effect") - if effects[e] then - if effects[e](itemstack,placer,pointed_thing) then - return "mcl_core:bowl" - end + local f = effects[e] + if not f then + f = get_random_effect() + end + if f(itemstack,placer,pointed_thing) then + return "mcl_core:bowl" end end