mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-28 10:12:59 +00:00
Fix villager crash when trading w/o inited inv
This commit is contained in:
parent
94c4256451
commit
fb55d33bfe
1 changed files with 12 additions and 0 deletions
|
@ -488,6 +488,9 @@ local function show_trade_formspec(playername, trader, tradenum)
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..playername})
|
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..playername})
|
||||||
|
if not inv then
|
||||||
|
return
|
||||||
|
end
|
||||||
local wanted1 = inv:get_stack("wanted", 1)
|
local wanted1 = inv:get_stack("wanted", 1)
|
||||||
local wanted2 = inv:get_stack("wanted", 2)
|
local wanted2 = inv:get_stack("wanted", 2)
|
||||||
local offered = inv:get_stack("offered", 1)
|
local offered = inv:get_stack("offered", 1)
|
||||||
|
@ -624,6 +627,9 @@ local return_fields = function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local inv_t = minetest.get_inventory({type="detached", name = "mobs_mc:trade_"..name})
|
local inv_t = minetest.get_inventory({type="detached", name = "mobs_mc:trade_"..name})
|
||||||
local inv_p = player:get_inventory()
|
local inv_p = player:get_inventory()
|
||||||
|
if not inv_t or not inv_p then
|
||||||
|
return
|
||||||
|
end
|
||||||
for i=1, inv_t:get_size("input") do
|
for i=1, inv_t:get_size("input") do
|
||||||
local stack = inv_t:get_stack("input", i)
|
local stack = inv_t:get_stack("input", i)
|
||||||
return_item(stack, player, player:get_pos(), inv_p)
|
return_item(stack, player, player:get_pos(), inv_p)
|
||||||
|
@ -660,6 +666,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
end
|
end
|
||||||
local tradenum = player_tradenum[name] + dir
|
local tradenum = player_tradenum[name] + dir
|
||||||
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..name})
|
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..name})
|
||||||
|
if not inv then
|
||||||
|
return
|
||||||
|
end
|
||||||
set_trade(trader, player, inv, tradenum)
|
set_trade(trader, player, inv, tradenum)
|
||||||
update_offer(inv, player, false)
|
update_offer(inv, player, false)
|
||||||
show_trade_formspec(name, trader, player_tradenum[name])
|
show_trade_formspec(name, trader, player_tradenum[name])
|
||||||
|
@ -983,6 +992,9 @@ mobs:register_mob("mobs_mc:villager", {
|
||||||
player_trading_with[name] = self
|
player_trading_with[name] = self
|
||||||
|
|
||||||
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..name})
|
local inv = minetest.get_inventory({type="detached", name="mobs_mc:trade_"..name})
|
||||||
|
if not inv then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
set_trade(self, clicker, inv, 1)
|
set_trade(self, clicker, inv, 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue