Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bitchange
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
bitchange
Commits
3814d994
Commit
3814d994
authored
8 years ago
by
Foz
Committed by
SmallJoker
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix handling of empty stacks and item accumulation
Fixes SmallJoker/bitchange#9
parent
6f9cc008
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shop.lua
+38
-11
38 additions, 11 deletions
shop.lua
with
38 additions
and
11 deletions
shop.lua
+
38
−
11
View file @
3814d994
...
...
@@ -7,25 +7,52 @@ local exchange_shop = {}
-- Tool wear aware replacement for contains_item.
local
function
list_contains_item
(
inv
,
listname
,
stack
)
local
count
=
stack
:
get_count
()
if
count
==
0
then
return
true
end
local
list
=
inv
:
get_list
(
listname
)
for
i
,
list_stack
in
pairs
(
list
)
do
if
list_stack
:
get_name
()
==
stack
:
get_name
()
and
list_stack
:
get_count
()
>=
stack
:
get_count
()
and
list_stack
:
get_wear
()
<=
stack
:
get_wear
()
then
return
i
local
name
=
stack
:
get_name
()
local
wear
=
stack
:
get_wear
()
for
_
,
list_stack
in
pairs
(
list
)
do
if
list_stack
:
get_name
()
==
name
and
list_stack
:
get_wear
()
<=
wear
then
if
list_stack
:
get_count
()
>=
count
then
return
true
else
count
=
count
-
list_stack
:
get_count
()
end
end
end
end
-- Tool wear aware replacement for remove_item.
local
function
list_remove_item
(
inv
,
listname
,
stack
)
local
index
=
list_contains_item
(
inv
,
listname
,
stack
)
if
index
then
local
list_stack
=
inv
:
get_stack
(
listname
,
index
)
local
removed_stack
=
list_stack
:
take_item
(
stack
:
get_count
())
inv
:
set_stack
(
listname
,
index
,
list_stack
)
return
removed_stack
local
count
=
stack
:
get_count
()
if
count
==
0
then
return
stack
end
local
removed_stack
=
ItemStack
(
nil
)
local
list
=
inv
:
get_list
(
listname
)
local
name
=
stack
:
get_name
()
local
wear
=
stack
:
get_wear
()
for
index
,
list_stack
in
pairs
(
list
)
do
if
list_stack
:
get_name
()
==
name
and
list_stack
:
get_wear
()
<=
wear
then
if
list_stack
:
get_count
()
>=
count
then
removed_stack
:
add_item
(
list_stack
:
take_item
(
count
))
inv
:
set_stack
(
listname
,
index
,
list_stack
)
break
else
removed_stack
:
add_item
(
list_stack
)
inv
:
set_stack
(
listname
,
index
,
ItemStack
(
nil
))
count
=
count
-
list_stack
:
get_count
()
end
end
end
return
removed_stack
end
local
function
get_exchange_shop_formspec
(
number
,
pos
,
title
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment