
# -> Reset adv trigger
advancement revoke @s only overly_realistic:items/item_weight/item_update_weight_percent_15

# -> Get how many weighted items the player is carrying (this is better than clear 0)
execute store result score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 \
    if items entity @s container.* *[custom_data~{or_item_weight_value:15b,or_item_weight_type:"percent"}]
execute store result score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_1 \
    if items entity @s weapon.offhand *[custom_data~{or_item_weight_value:15b,or_item_weight_type:"percent"}]

# -> Add values
scoreboard players operation @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 += @s OverlyRealistic.Player.ItemWeight_Percentage_Value_1

# -> Reset weight
attribute @s movement_speed modifier remove overly_realistic:item_weight_percent_15

# -> If player has no weighted items then return
execute unless score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 matches 1.. run \
    return fail

# --> Add weight

# -> 1 item
execute if score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 matches 1 run \
    return run \
        attribute @s movement_speed modifier add overly_realistic:item_weight_percent_15 -0.15 add_multiplied_total

# -> 2 items
execute if score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 matches 2 run \
    return run \
        attribute @s movement_speed modifier add overly_realistic:item_weight_percent_15 -0.3 add_multiplied_total

# -> 3+ items
execute if score @s OverlyRealistic.Player.ItemWeight_Percentage_Value_0 matches 3.. run \
    return run \
        attribute @s movement_speed modifier add overly_realistic:item_weight_percent_15 -0.45 add_multiplied_total
