Skip to content

Commit

Permalink
bugfix: shift-click into inventory, only refill if going from Count:1…
Browse files Browse the repository at this point in the history
… to none
  • Loading branch information
dthigpen committed Aug 17, 2021
1 parent 8730d62 commit 911bcd4
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 88 deletions.
25 changes: 0 additions & 25 deletions refill/data/dt.refill/functions/check_deps.mcfunction

This file was deleted.

18 changes: 13 additions & 5 deletions refill/data/dt.refill/functions/do_refill.mcfunction
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# say do_refill
function call_stack:push

data modify storage call_stack: this.this_user set from storage call_stack: this.arg0
data modify storage call_stack: this.user set from storage call_stack: this.arg0
data modify storage call_stack: this.item set from storage call_stack: this.arg1

data modify storage call_stack: this.original_slot set from storage call_stack: this.item.Slot
data modify storage call_stack: this.item.Slot set from storage call_stack: this.this_user.data.selected.slot
data modify storage call_stack: this.slot_from_inventory set from storage call_stack: this.item.Slot
data modify storage call_stack: this.item.Slot set from storage call_stack: this.user.data.selected.Slot

# Replace the inventory item
execute unless data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from storage call_stack: this.slot_from_inventory
execute unless data entity @s SelectedItem run function dt.inventory:api/player/slot/remove
# execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from entity @s SelectedItem
# execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0.Slot set from storage call_stack: this.slot_from_inventory
# execute if data entity @s SelectedItem run function dt.inventory:api/player/slot/replace

# Replace the hotbar item
data modify storage call_stack: call.arg0 set from storage call_stack: this.item
function dt.inventory:api/player/slot/replace

data modify storage call_stack: call.arg0 set from storage call_stack: this.original_slot
function dt.inventory:api/player/slot/remove
data modify storage call_stack: call.arg0 set from storage call_stack: this.slot_from_inventory
function dt.refill:internal/output/print_did_refill

function call_stack:pop
20 changes: 0 additions & 20 deletions refill/data/dt.refill/functions/from_inventory.mcfunction

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ function call_stack:push

# tellraw @p ["users before: ",{"nbt":"users","storage":"dt.refill:"}]

#region get or create this_user
data modify storage call_stack: call.arg0 set from storage dt.refill: users
function dt.user_util:get_or_create
data modify storage call_stack: this.this_user set from storage call_stack: call.result
#endregion
function dt.refill:internal/database/fetch_or_init
data modify storage call_stack: this.user set from storage call_stack: call.result

# If there is nothing selected, check the last selected for that same slot number
execute unless data entity @s SelectedItem if data storage call_stack: this.user.data.selected run data modify storage call_stack: call.arg0 set from storage call_stack: this.user
execute unless data entity @s SelectedItem if data storage call_stack: this.user.data.selected run function dt.refill:internal/try_refill
execute unless data entity @s SelectedItem if data storage call_stack: this.user.data.selected run data modify storage call_stack: this.user set from storage call_stack: call.result

execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from storage call_stack: this.this_user
execute if data entity @s SelectedItem run function dt.refill:store_selected_item
execute if data entity @s SelectedItem run data modify storage call_stack: this.this_user set from storage call_stack: call.result
execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from storage call_stack: this.user
execute if data entity @s SelectedItem run function dt.refill:internal/set_user_item_data
execute if data entity @s SelectedItem run data modify storage call_stack: this.user set from storage call_stack: call.result

execute unless data entity @s SelectedItem if data storage call_stack: this.this_user.data.selected run data modify storage call_stack: call.arg0 set from storage call_stack: this.this_user
execute unless data entity @s SelectedItem if data storage call_stack: this.this_user.data.selected run function dt.refill:refill_if_same_slot
execute unless data entity @s SelectedItem if data storage call_stack: this.this_user.data.selected run data modify storage call_stack: this.this_user set from storage call_stack: call.result
#region update user
data modify storage call_stack: call.arg0 set from storage dt.refill: users
data modify storage call_stack: call.arg1 set from storage call_stack: this.this_user
data modify storage call_stack: call.arg1 set from storage call_stack: this.user
function dt.user_util:update
data modify storage dt.refill: users set from storage call_stack: call.result

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function call_stack:push

# get or create empty
data modify storage call_stack: call.arg0 set from storage dt.refill: users
function dt.user_util:get_or_create
data modify storage call_stack: this.user set from storage call_stack: call.result

# Default object
function dt.refill:internal/database/get_init_data
data modify storage call_stack: this.default_data set from storage call_stack: call.result

# Merge with actual data
data modify storage call_stack: this.default_data merge from storage call_stack: this.user.data
data modify storage call_stack: this.user.data set from storage call_stack: this.default_data
data modify storage call_stack: this.result set from storage call_stack: this.user
function call_stack:pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function call_stack:push
data modify storage call_stack: this.result set value {inventory:[], settings:{min_durability:1}}
function call_stack:pop
24 changes: 24 additions & 0 deletions refill/data/dt.refill/functions/internal/do_refill.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# say do_refill
function call_stack:push

data modify storage call_stack: this.user set from storage call_stack: this.arg0
data modify storage call_stack: this.item set from storage call_stack: this.arg1

data modify storage call_stack: this.slot_from_inventory set from storage call_stack: this.item.Slot
data modify storage call_stack: this.item.Slot set from storage call_stack: this.user.data.selected.Slot

# Replace the inventory item
execute unless data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from storage call_stack: this.slot_from_inventory
execute unless data entity @s SelectedItem run function dt.inventory:api/player/slot/remove
# execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0 set from entity @s SelectedItem
# execute if data entity @s SelectedItem run data modify storage call_stack: call.arg0.Slot set from storage call_stack: this.slot_from_inventory
# execute if data entity @s SelectedItem run function dt.inventory:api/player/slot/replace

# Replace the hotbar item
data modify storage call_stack: call.arg0 set from storage call_stack: this.item
function dt.inventory:api/player/slot/replace

data modify storage call_stack: call.arg0 set from storage call_stack: this.slot_from_inventory
function dt.refill:internal/output/print_did_refill

function call_stack:pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function call_stack:push
execute store result score $slot dt.tmp run data get storage call_stack: this.arg0
title @a actionbar ["",{"text":"Refilled from slot ","color":"white"},{"score":{"name":"$slot","objective":"dt.tmp"}}]
function call_stack:pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# say from_inventory
function call_stack:push

data modify storage call_stack: this.user set from storage call_stack: this.arg0

# find in stored inventory first
data modify storage call_stack: call.arg0 set from storage call_stack: this.user.data.inventory
data modify storage call_stack: call.arg1 set value {id:""}
data modify storage call_stack: call.arg1.id set from storage call_stack: this.user.data.selected.id
data modify storage call_stack: call.arg2 set value 1
function dt.array:api/split_by_key_limit_n
data modify storage call_stack: this.data_item_found set from storage call_stack: call.result[0][0]

# if found in inventory data, match with actual inventory
execute if data storage call_stack: this.data_item_found.id run function dt.inventory:api/player/get/inventory
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: this.items set from storage call_stack: call.result

execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: call.arg0 set from storage call_stack: this.items
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: call.arg1 set value {id:"",Slot:""}
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: call.arg1.id set from storage call_stack: this.data_item_found.id
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: call.arg1.Slot set from storage call_stack: this.data_item_found.Slot
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: call.arg2 set value 1
execute if data storage call_stack: this.data_item_found.id run function dt.array:api/split_by_key_limit_n
execute if data storage call_stack: this.data_item_found.id run data modify storage call_stack: this.actual_item_found set from storage call_stack: call.result[0][0]


# execute if data storage call_stack: this.actual_item_found.id store result
# TODO check that new items durability is greater than current
execute if data storage call_stack: this.actual_item_found.id run data modify storage call_stack: call.arg0 set from storage call_stack: this.user
execute if data storage call_stack: this.actual_item_found.id run data modify storage call_stack: call.arg1 set from storage call_stack: this.actual_item_found
execute if data storage call_stack: this.actual_item_found.id run function dt.refill:do_refill
# execute unless data storage call_stack: this.actual_item_found.id run data remove storage call_stack: this.user.data.selected

function call_stack:pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# say store selected
function call_stack:push

data modify storage call_stack: this.this_user set from storage call_stack: this.arg0

data remove storage call_stack: this.this_user.data
data modify storage call_stack: this.this_user.data.selected set from entity @s SelectedItem
data modify storage call_stack: this.this_user.data.selected.Slot set from entity @s SelectedItemSlot

data modify storage call_stack: this.this_user.data.inventory set from entity @s Inventory

# remove hotbar slots
data remove storage call_stack: this.this_user.data.inventory[{Slot:0b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:1b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:2b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:3b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:4b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:5b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:6b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:7b}]
data remove storage call_stack: this.this_user.data.inventory[{Slot:8b}]

data modify storage call_stack: this.result set from storage call_stack: this.this_user
function call_stack:pop
20 changes: 20 additions & 0 deletions refill/data/dt.refill/functions/internal/try_refill.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# say try_refill
function call_stack:push

data modify storage call_stack: this.user set from storage call_stack: this.arg0
# Check that the slots are the same, if so continue
execute store result score $slot_from_data dt.tmp run data get storage call_stack: this.user.data.selected.Slot
execute store result score $slot_from_player dt.tmp run data get entity @s SelectedItemSlot
execute store result score $item_count dt.tmp run data get storage call_stack: this.user.data.selected.Count
# scoreboard players set $item_uses_left dt.tmp -1
# execute store result score $min_durability dt.tmp run data get storage call_stack: this.user.data.settings.min_durability
# data modify storage call_stack: this.user.data.settings.min_durability set value 0
# execute if data entity @s SelectedItem.tag.Damage run function dt.refill:internal/calculate_remaining_durability
# execute if data entity @s SelectedItem.tag.Damage run scoreboard players operation $item_uses_left dt.tmp = @s dt.tmp

# if score $item_uses_left dt.tmp <= $min_durability dt.tmp
execute if score $slot_from_data dt.tmp = $slot_from_data dt.tmp if score $item_count dt.tmp matches 1 run data modify storage call_stack: call.arg0 set from storage call_stack: this.user
execute if score $slot_from_data dt.tmp = $slot_from_data dt.tmp if score $item_count dt.tmp matches 1 run function dt.refill:internal/refill_from_inventory


function call_stack:pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function call_stack:push
data modify storage call_stack: this.user set from storage call_stack: this.arg0



function call_stack:pop
15 changes: 0 additions & 15 deletions refill/data/dt.refill/functions/refill_if_same_slot.mcfunction

This file was deleted.

10 changes: 0 additions & 10 deletions refill/data/dt.refill/functions/store_selected_item.mcfunction

This file was deleted.

2 changes: 1 addition & 1 deletion refill/data/dt.refill/functions/tick.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ execute as @a[tag=dt.tmp.add] run tag @s remove dt.tmp.add
scoreboard players reset @a dt.refill.toggle
scoreboard players enable @a dt.refill.toggle

execute as @a[tag=dt.refill] run function dt.refill:check_refills
execute as @a[tag=dt.refill] run function dt.refill:internal/check_refills
schedule function dt.refill:tick 1t replace

0 comments on commit 911bcd4

Please sign in to comment.