Compare commits

...

5 Commits

Author SHA1 Message Date
Cy 59ff757c80 Make sure punched node has actually been got 2013-10-12 14:47:07 -07:00
Cy 5878a255c3 punched nothing with a position?
IDK it's supposed to pass the punched node as punched, so you can check
what kind of chest it is.
2013-10-12 14:08:32 -07:00
Cy 0dfb76dbbe Only check shared chests for shared locks!
Jeez
2013-10-08 13:15:29 -07:00
Cy bef8a1af5f Oops 2013-10-07 22:22:05 -07:00
Cy 7f7f259e7b Fixing another ordering bug. 2013-10-07 02:22:10 -07:00
1 changed files with 38 additions and 19 deletions

View File

@ -10,6 +10,12 @@ function min(a,b)
end
end
if not string.starts then
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
end
--------------------------------------------------------
function sortInventory(inv,sorter)
@ -28,6 +34,8 @@ end
sorters = {
wise = function(a,b)
-- XXX: this needs to have stricter ordering!
-- (why is air scoring higher than the end?)
if(a == nil) then
if b == nil then
return true
@ -66,14 +74,17 @@ sorters = {
local acount = a:get_count()
local bcount = b:get_count()
if(acount == bothmax) then
return bcount == bothmax
--print('same?',acount,bcount,bothmax)
return bcount ~= bothmax
elseif (bcount == bothmax) then
--print('bcount bothmax derp')
return false
end
local num = min(bcount,bothmax-acount)
a:add_item(b:take_item(num))
-- nothing can have both count AND wear, right?
-- now a:count > b:count so a should go first
--print('numnum',num)
return true
end,
amount = function(a,b)
@ -125,8 +136,14 @@ function registerWand(method,sorter)
return
end
-- Sokomine's shared chest locks
if locks ~= nil and not locks:lock_allow_use(pos,user) then
minetest.chat_send_player(user:get_player_name(),"That's not yours!","Sorter -!-")
if locks ~= nil then
if punched == nil or punched.name == nil then
punched = minetest.get_node(pos)
end
if punched and punched.name:starts('locks:') and not locks:lock_allow_use(pos,user) then
-- the error has already been reported (yay side effects)
return
end
end
if(sortInventory(inv,sorter)) then
@ -136,8 +153,25 @@ function registerWand(method,sorter)
})
end
function debugSorter(a,b)
result = sorters.wise(a,b)
function derp(a)
return a:get_name()..":"..a:get_count()..":"..a:get_wear()
end
if a then
a = derp(a)
end
if b then
b = derp(b)
end
if result then
print('a goes first',a,b)
else
print('b goes first',a,b)
end
return result
end
function test()
table.sort({nil,nil,nil},sorters.wise)
function thingy(name,stack_max)
return {
get_name=function(self) return name end,
@ -152,21 +186,6 @@ function test()
}
end
tabl = {thingy('thing1',1),thingy('hting2',1),nil,thingy('thing1',2),thingy('thing1',4),thingy('thing1',10)}
function sorter(a,b)
result = sorters.wise(a,b)
if a then
a = a:derp()
end
if b then
b = b:derp()
end
if result then
print('a goes first',a,b)
else
print('b goes first',a,b)
end
return result
end
table.sort(tabl,sorter)
for n,v in pairs(tabl) do
print(n,v:get_name(),v:get_count())