fix:free silk creation when replacing a spinning wheel

master
root 2022-06-25 01:10:50 +02:00
parent 9115576ec7
commit 6632e9d841
3 changed files with 36 additions and 20 deletions

View File

@ -86,6 +86,7 @@ minetest.register_node("petz:silkworm_eggs", {
}) })
--Spinning Wheel --Spinning Wheel
minetest.register_node("petz:spinning_wheel", { minetest.register_node("petz:spinning_wheel", {
description = S("Spinning Wheel"), description = S("Spinning Wheel"),
groups = {snappy=1, bendy=2, cracky=1}, groups = {snappy=1, bendy=2, cracky=1},
@ -102,20 +103,22 @@ minetest.register_node("petz:spinning_wheel", {
type = "fixed", type = "fixed",
fixed = {-0.5, -0.5, -0.25, 0.5, 0.3125, 0.1875}, fixed = {-0.5, -0.5, -0.25, 0.5, 0.3125, 0.1875},
}, },
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("silk_count", 1) meta:set_int("silk_count", 1)
meta:set_string("infotext", S("Silk Count").." = "..meta:get_int("silk_count")) meta:set_string("infotext", S("Silk Count").." = "..meta:get_int("silk_count"))
end, end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local player_name = player:get_player_name() local player_name = player:get_player_name()
--minetest.chat_send_player(player_name, "name="..itemstack:get_name()) --minetest.chat_send_player(player_name, "name="..itemstack:get_name())
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local silk_count = meta:get_int("silk_count") local silk_count = meta:get_int("silk_count")
if itemstack:get_name() == "petz:cocoon" then if itemstack:get_name() == "petz:cocoon" then
if silk_count == 3 then if silk_count == petz.settings.silk_to_bobbin then
minetest.chat_send_player(player_name, S("First, extract the silk bobbin from the spinning wheel.")) minetest.chat_send_player(player_name, S("First, extract the silk bobbin from the spinning wheel."))
elseif silk_count == 2 then elseif silk_count == (petz.settings.silk_to_bobbin - 1) then
silk_count = silk_count + 1 silk_count = silk_count + 1
meta:set_int("silk_count", silk_count) meta:set_int("silk_count", silk_count)
meta:set_string("infotext", S("Silk Count").." = "..tostring(silk_count)) meta:set_string("infotext", S("Silk Count").." = "..tostring(silk_count))
@ -127,21 +130,23 @@ minetest.register_node("petz:spinning_wheel", {
meta:set_int("silk_count", silk_count) meta:set_int("silk_count", silk_count)
meta:set_string("infotext", S("Silk Count").." = "..tostring(silk_count)) meta:set_string("infotext", S("Silk Count").." = "..tostring(silk_count))
itemstack:take_item() itemstack:take_item()
minetest.chat_send_player(player_name, S("There are still").." ".. tostring(3-silk_count).." "..S("more to create the bobbin.")) minetest.chat_send_player(player_name, S("There are still").." "
..tostring(petz.settings.silk_to_bobbin - silk_count).." "..S("more to create the bobbin."))
return itemstack return itemstack
end end
elseif silk_count == 3 then --get the bobbin elseif silk_count == petz.settings.silk_to_bobbin then --get the bobbin
local inv = player:get_inventory() local inv = player:get_inventory()
if inv:room_for_item("main", "petz:silk_bobbin") then --firstly check for room in the inventory if inv:room_for_item("main", "petz:silk_bobbin") then --firstly check for room in the inventory
local itemstack_name = itemstack:get_name() local itemstack_name = itemstack:get_name()
local stack = ItemStack("petz:silk_bobbin 1") local stack = ItemStack("petz:silk_bobbin 1")
if (itemstack_name == "petz:silk_bobbin" or itemstack_name == "") and (itemstack:get_count() < itemstack:get_stack_max()) then if (itemstack_name == "petz:silk_bobbin" or itemstack_name == "")
itemstack:add_item(stack) and (itemstack:get_count() < itemstack:get_stack_max()) then
itemstack:add_item(stack)
else else
inv:add_item("main", stack) inv:add_item("main", stack)
end end
meta:set_int("silk_count", 0) --reset the silk count meta:set_int("silk_count", 1) --reset the silk count
meta:set_string("infotext", S("Silk Count").." = 0") meta:set_string("infotext", S("Silk Count").." = 1")
minetest.chat_send_player(player_name, S("You got the bobbin!")) minetest.chat_send_player(player_name, S("You got the bobbin!"))
return itemstack return itemstack
else else
@ -162,18 +167,19 @@ minetest.register_craft({
}) })
petz.init_convert_to_chrysalis = function(self) petz.init_convert_to_chrysalis = function(self)
minetest.after(math.random(petz.settings.silkworm_chrysalis_min_time, petz.settings.silkworm_chrysalis_max_time), function() minetest.after(math.random(petz.settings.silkworm_chrysalis_min_time,
if not(kitz.is_alive(self)) then petz.settings.silkworm_chrysalis_max_time), function()
return if not(kitz.is_alive(self)) then
end return
local pos = self.object:get_pos() end
local air_pos = minetest.find_node_near(pos, 1, {"air"}, true) local pos = self.object:get_pos()
if air_pos then local air_pos = minetest.find_node_near(pos, 1, {"air"}, true)
minetest.set_node(air_pos, {name= "petz:cocoon"}) if air_pos then
kitz.remove_mob(self) minetest.set_node(air_pos, {name= "petz:cocoon"})
else kitz.remove_mob(self)
petz.init_convert_to_chrysalis(self) else
end petz.init_convert_to_chrysalis(self)
end
end, self) end, self)
end end

View File

@ -78,6 +78,10 @@ horseshoe_speedup = 0.2
##lashing ##lashing
lashing_tame_count = 3 lashing_tame_count = 3
#Spinning Wheel
##amount of silk to craft a bobbin in a spinning_wheel
silk_to_bobbin = 3
##look_at ##look_at
look_at = true look_at = true
#random probability of look_at #random probability of look_at

View File

@ -388,6 +388,12 @@ local settings_def = {
type = "number", type = "number",
default = 3, default = 3,
}, },
--Spinning Wheel
{
name = "silk_to_bobbin",
type = "number",
default = 3,
},
--Bee Stuff --Bee Stuff
{ {
name = "initial_honey_beehive", name = "initial_honey_beehive",